MediaQuery { public boolean matches(MediaDeviceDescription deviceDescription) { boolean typeMatches = type == null || MediaType.ALL.equals(type) || Objects.equals(type, deviceDescription.getType()); boolean matchesExpressions = true; for (MediaExpression expression : expressions) { if (!expression.matches(deviceDescription)) { matchesExpressions = false; break; } } boolean expressionResult = typeMatches && matchesExpressions; if (not) { expressionResult = !expressionResult; } return expressionResult; } MediaQuery(String type, List<MediaExpression> expressions, boolean only, boolean not); boolean matches(MediaDeviceDescription deviceDescription);  }
@Test public void matchTest() { MediaDeviceDescription deviceDescription = new MediaDeviceDescription("all"); MediaQuery query = MediaQueryParser.parseMediaQuery("not all and (min-width: 600px)"); List<MediaQuery> queries = MediaQueryParser.parseMediaQueries("not all and (min-width: 600px), not all and (min-width: 500px)"); Assert.assertTrue(query.matches(deviceDescription)); Assert.assertTrue(queries.get(0).matches(deviceDescription)); Assert.assertTrue(queries.get(1).matches(deviceDescription)); }