@Test public void mediaExpressionTestTest02() { MediaExpression maxWidth = new MediaExpression("max-width", "600px"); MediaExpression maxHeight = new MediaExpression("max-height", "600px"); MediaDeviceDescription deviceDescription = new MediaDeviceDescription("all"); deviceDescription.setWidth(450); deviceDescription.setHeight(450); Assert.assertTrue(maxHeight.matches(deviceDescription)); Assert.assertTrue(maxWidth.matches(deviceDescription)); }
public boolean matches(MediaDeviceDescription deviceDescription) { switch (feature) { case MediaFeature.COLOR: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getBitsPerComponent() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getBitsPerComponent() <= val; } else { return val == null ? deviceDescription.getBitsPerComponent() != 0 : val == deviceDescription.getBitsPerComponent(); } } case MediaFeature.COLOR_INDEX: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getColorIndex() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getColorIndex() <= val; } else { return val == null ? deviceDescription.getColorIndex() != 0 : val == deviceDescription.getColorIndex(); } } case MediaFeature.ASPECT_RATIO: { int[] aspectRatio = CssUtils.parseAspectRatio(value); if (minPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() >= aspectRatio[1] * deviceDescription.getWidth(); } else if (maxPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() <= aspectRatio[1] * deviceDescription.getWidth(); } else { return aspectRatio != null && CssUtils.compareFloats(aspectRatio[0] * deviceDescription.getHeight(), aspectRatio[1] * deviceDescription.getWidth()); } } case MediaFeature.GRID: { Integer val = CssUtils.parseInteger(value); return val != null && val == 0 && !deviceDescription.isGrid() || deviceDescription.isGrid(); } case MediaFeature.SCAN: { return Objects.equals(value, deviceDescription.getScan()); } case MediaFeature.ORIENTATION: { return Objects.equals(value, deviceDescription.getOrientation()); } case MediaFeature.MONOCHROME: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getMonochrome() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getMonochrome() <= val; } else { return val == null ? deviceDescription.getMonochrome() > 0 : val == deviceDescription.getMonochrome(); } } case MediaFeature.HEIGHT: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getHeight() >= val; } else if (maxPrefix) { return deviceDescription.getHeight() <= val; } else { return deviceDescription.getHeight() > 0; } } case MediaFeature.WIDTH: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getWidth() >= val; } else if (maxPrefix) { return deviceDescription.getWidth() <= val; } else { return deviceDescription.getWidth() > 0; } } case MediaFeature.RESOLUTION: { float val = CssUtils.parseResolution(value); if (minPrefix) { return deviceDescription.getResolution() >= val; } else if (maxPrefix) { return deviceDescription.getResolution() <= val; } else { return deviceDescription.getResolution() > 0; } } default: return false; } }
MediaExpression { public boolean matches(MediaDeviceDescription deviceDescription) { switch (feature) { case MediaFeature.COLOR: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getBitsPerComponent() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getBitsPerComponent() <= val; } else { return val == null ? deviceDescription.getBitsPerComponent() != 0 : val == deviceDescription.getBitsPerComponent(); } } case MediaFeature.COLOR_INDEX: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getColorIndex() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getColorIndex() <= val; } else { return val == null ? deviceDescription.getColorIndex() != 0 : val == deviceDescription.getColorIndex(); } } case MediaFeature.ASPECT_RATIO: { int[] aspectRatio = CssUtils.parseAspectRatio(value); if (minPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() >= aspectRatio[1] * deviceDescription.getWidth(); } else if (maxPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() <= aspectRatio[1] * deviceDescription.getWidth(); } else { return aspectRatio != null && CssUtils.compareFloats(aspectRatio[0] * deviceDescription.getHeight(), aspectRatio[1] * deviceDescription.getWidth()); } } case MediaFeature.GRID: { Integer val = CssUtils.parseInteger(value); return val != null && val == 0 && !deviceDescription.isGrid() || deviceDescription.isGrid(); } case MediaFeature.SCAN: { return Objects.equals(value, deviceDescription.getScan()); } case MediaFeature.ORIENTATION: { return Objects.equals(value, deviceDescription.getOrientation()); } case MediaFeature.MONOCHROME: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getMonochrome() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getMonochrome() <= val; } else { return val == null ? deviceDescription.getMonochrome() > 0 : val == deviceDescription.getMonochrome(); } } case MediaFeature.HEIGHT: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getHeight() >= val; } else if (maxPrefix) { return deviceDescription.getHeight() <= val; } else { return deviceDescription.getHeight() > 0; } } case MediaFeature.WIDTH: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getWidth() >= val; } else if (maxPrefix) { return deviceDescription.getWidth() <= val; } else { return deviceDescription.getWidth() > 0; } } case MediaFeature.RESOLUTION: { float val = CssUtils.parseResolution(value); if (minPrefix) { return deviceDescription.getResolution() >= val; } else if (maxPrefix) { return deviceDescription.getResolution() <= val; } else { return deviceDescription.getResolution() > 0; } } default: return false; } } }
MediaExpression { public boolean matches(MediaDeviceDescription deviceDescription) { switch (feature) { case MediaFeature.COLOR: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getBitsPerComponent() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getBitsPerComponent() <= val; } else { return val == null ? deviceDescription.getBitsPerComponent() != 0 : val == deviceDescription.getBitsPerComponent(); } } case MediaFeature.COLOR_INDEX: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getColorIndex() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getColorIndex() <= val; } else { return val == null ? deviceDescription.getColorIndex() != 0 : val == deviceDescription.getColorIndex(); } } case MediaFeature.ASPECT_RATIO: { int[] aspectRatio = CssUtils.parseAspectRatio(value); if (minPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() >= aspectRatio[1] * deviceDescription.getWidth(); } else if (maxPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() <= aspectRatio[1] * deviceDescription.getWidth(); } else { return aspectRatio != null && CssUtils.compareFloats(aspectRatio[0] * deviceDescription.getHeight(), aspectRatio[1] * deviceDescription.getWidth()); } } case MediaFeature.GRID: { Integer val = CssUtils.parseInteger(value); return val != null && val == 0 && !deviceDescription.isGrid() || deviceDescription.isGrid(); } case MediaFeature.SCAN: { return Objects.equals(value, deviceDescription.getScan()); } case MediaFeature.ORIENTATION: { return Objects.equals(value, deviceDescription.getOrientation()); } case MediaFeature.MONOCHROME: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getMonochrome() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getMonochrome() <= val; } else { return val == null ? deviceDescription.getMonochrome() > 0 : val == deviceDescription.getMonochrome(); } } case MediaFeature.HEIGHT: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getHeight() >= val; } else if (maxPrefix) { return deviceDescription.getHeight() <= val; } else { return deviceDescription.getHeight() > 0; } } case MediaFeature.WIDTH: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getWidth() >= val; } else if (maxPrefix) { return deviceDescription.getWidth() <= val; } else { return deviceDescription.getWidth() > 0; } } case MediaFeature.RESOLUTION: { float val = CssUtils.parseResolution(value); if (minPrefix) { return deviceDescription.getResolution() >= val; } else if (maxPrefix) { return deviceDescription.getResolution() <= val; } else { return deviceDescription.getResolution() > 0; } } default: return false; } } MediaExpression(String feature, String value); }
MediaExpression { public boolean matches(MediaDeviceDescription deviceDescription) { switch (feature) { case MediaFeature.COLOR: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getBitsPerComponent() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getBitsPerComponent() <= val; } else { return val == null ? deviceDescription.getBitsPerComponent() != 0 : val == deviceDescription.getBitsPerComponent(); } } case MediaFeature.COLOR_INDEX: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getColorIndex() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getColorIndex() <= val; } else { return val == null ? deviceDescription.getColorIndex() != 0 : val == deviceDescription.getColorIndex(); } } case MediaFeature.ASPECT_RATIO: { int[] aspectRatio = CssUtils.parseAspectRatio(value); if (minPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() >= aspectRatio[1] * deviceDescription.getWidth(); } else if (maxPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() <= aspectRatio[1] * deviceDescription.getWidth(); } else { return aspectRatio != null && CssUtils.compareFloats(aspectRatio[0] * deviceDescription.getHeight(), aspectRatio[1] * deviceDescription.getWidth()); } } case MediaFeature.GRID: { Integer val = CssUtils.parseInteger(value); return val != null && val == 0 && !deviceDescription.isGrid() || deviceDescription.isGrid(); } case MediaFeature.SCAN: { return Objects.equals(value, deviceDescription.getScan()); } case MediaFeature.ORIENTATION: { return Objects.equals(value, deviceDescription.getOrientation()); } case MediaFeature.MONOCHROME: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getMonochrome() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getMonochrome() <= val; } else { return val == null ? deviceDescription.getMonochrome() > 0 : val == deviceDescription.getMonochrome(); } } case MediaFeature.HEIGHT: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getHeight() >= val; } else if (maxPrefix) { return deviceDescription.getHeight() <= val; } else { return deviceDescription.getHeight() > 0; } } case MediaFeature.WIDTH: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getWidth() >= val; } else if (maxPrefix) { return deviceDescription.getWidth() <= val; } else { return deviceDescription.getWidth() > 0; } } case MediaFeature.RESOLUTION: { float val = CssUtils.parseResolution(value); if (minPrefix) { return deviceDescription.getResolution() >= val; } else if (maxPrefix) { return deviceDescription.getResolution() <= val; } else { return deviceDescription.getResolution() > 0; } } default: return false; } } MediaExpression(String feature, String value); boolean matches(MediaDeviceDescription deviceDescription); }
MediaExpression { public boolean matches(MediaDeviceDescription deviceDescription) { switch (feature) { case MediaFeature.COLOR: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getBitsPerComponent() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getBitsPerComponent() <= val; } else { return val == null ? deviceDescription.getBitsPerComponent() != 0 : val == deviceDescription.getBitsPerComponent(); } } case MediaFeature.COLOR_INDEX: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getColorIndex() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getColorIndex() <= val; } else { return val == null ? deviceDescription.getColorIndex() != 0 : val == deviceDescription.getColorIndex(); } } case MediaFeature.ASPECT_RATIO: { int[] aspectRatio = CssUtils.parseAspectRatio(value); if (minPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() >= aspectRatio[1] * deviceDescription.getWidth(); } else if (maxPrefix) { return aspectRatio != null && aspectRatio[0] * deviceDescription.getHeight() <= aspectRatio[1] * deviceDescription.getWidth(); } else { return aspectRatio != null && CssUtils.compareFloats(aspectRatio[0] * deviceDescription.getHeight(), aspectRatio[1] * deviceDescription.getWidth()); } } case MediaFeature.GRID: { Integer val = CssUtils.parseInteger(value); return val != null && val == 0 && !deviceDescription.isGrid() || deviceDescription.isGrid(); } case MediaFeature.SCAN: { return Objects.equals(value, deviceDescription.getScan()); } case MediaFeature.ORIENTATION: { return Objects.equals(value, deviceDescription.getOrientation()); } case MediaFeature.MONOCHROME: { Integer val = CssUtils.parseInteger(value); if (minPrefix) { return val != null && deviceDescription.getMonochrome() >= val; } else if (maxPrefix) { return val != null && deviceDescription.getMonochrome() <= val; } else { return val == null ? deviceDescription.getMonochrome() > 0 : val == deviceDescription.getMonochrome(); } } case MediaFeature.HEIGHT: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getHeight() >= val; } else if (maxPrefix) { return deviceDescription.getHeight() <= val; } else { return deviceDescription.getHeight() > 0; } } case MediaFeature.WIDTH: { float val = parseAbsoluteLength(value); if (minPrefix) { return deviceDescription.getWidth() >= val; } else if (maxPrefix) { return deviceDescription.getWidth() <= val; } else { return deviceDescription.getWidth() > 0; } } case MediaFeature.RESOLUTION: { float val = CssUtils.parseResolution(value); if (minPrefix) { return deviceDescription.getResolution() >= val; } else if (maxPrefix) { return deviceDescription.getResolution() <= val; } else { return deviceDescription.getResolution() > 0; } } default: return false; } } MediaExpression(String feature, String value); boolean matches(MediaDeviceDescription deviceDescription);  }