DeferredValueMatcher implements ValueMatcher { public boolean matches(Class<?> parentEntityType, String propertyName, Object value) { if (value == null) { return _value == null; } else if (_value == null) { return false; } if (_resolvedValueSet) { return value.equals(_resolvedValue); } Class<?> expectedValueType = value.getClass(); Class<?> actualValueType = _value.getClass(); if (expectedValueType.isAssignableFrom(actualValueType)) { if (isRegexObj(_value)) { return regexMatch((String)value, ((String)_value)); } return value.equals(_value); } if (actualValueType == String.class) { String actualValue = (String) _value; if (expectedValueType == AgencyAndId.class) { AgencyAndId expectedId = (AgencyAndId) value; if (isRegexObj(_value)) { return regexMatch(expectedId.getId(), actualValue); } return expectedId.getId().equals(actualValue); } else if (IdentityBean.class.isAssignableFrom(expectedValueType)) { IdentityBean<?> bean = (IdentityBean<?>) value; Object expectedId = bean.getId(); if (expectedId == null) { return false; } if (expectedId instanceof AgencyAndId) { AgencyAndId expectedFullId = (AgencyAndId) expectedId; return expectedFullId.getId().equals(actualValue); } else if (expectedId instanceof String) { return expectedId.equals(actualValue); } } else { Converter converter = _support.resolveConverter(parentEntityType, propertyName, expectedValueType); if (converter != null) { _resolvedValue = converter.convert(expectedValueType, _value); _resolvedValueSet = true; return value.equals(_resolvedValue); } else { throw new IllegalStateException( "no type conversion from type String to type \"" + expectedValueType.getName() + "\" for value comparison"); } } } throw new IllegalStateException("no type conversion from type \"" + actualValueType.getName() + "\" to type \"" + expectedValueType.getName() + "\" for value comparison"); } DeferredValueMatcher(GtfsReader reader, EntitySchemaCache schemaCache,
      Object value); boolean matches(Class<?> parentEntityType, String propertyName,
      Object value);  }
@Test public void testString() { DeferredValueMatcher matcher = matcher("tacos"); assertTrue(matcher.matches(Stop.class, "name", "tacos")); assertFalse(matcher.matches(Stop.class, "name", "nachos")); }
@Test public void testInteger() { DeferredValueMatcher matcher = matcher(1); assertTrue(matcher.matches(Stop.class, "locationType", 1)); assertFalse(matcher.matches(Stop.class, "locationType", 2)); }
@Test public void testEntitySchema_ServiceDate() { DeferredValueMatcher matcher = matcher("20130105"); assertTrue(matcher.matches(ServiceCalendar.class, "startDate", new ServiceDate(2013, 01, 05))); assertFalse(matcher.matches(ServiceCalendar.class, "startDate", new ServiceDate(2013, 01, 06))); }
@Test public void testEntitySchema_ArrivalTime() { DeferredValueMatcher matcher = matcher("06:00:00"); assertTrue(matcher.matches(StopTime.class, "arrivalTime", 6 * 60 * 60)); assertFalse(matcher.matches(StopTime.class, "arrivalTime", 7 * 60 * 60)); }
@Test public void testEntity() { DeferredValueMatcher matcher = matcher("R10"); Route routeA = new Route(); routeA.setId(new AgencyAndId("1", "R10")); Route routeB = new Route(); routeB.setId(new AgencyAndId("1", "R20")); assertTrue(matcher.matches(Trip.class, "route", routeA)); assertFalse(matcher.matches(Trip.class, "route", routeB)); }
@Test public void testAgencyAndId() { DeferredValueMatcher matcher = matcher("R10"); assertTrue(matcher.matches(Route.class, "id", new AgencyAndId("1", "R10"))); assertFalse(matcher.matches(Route.class, "id", new AgencyAndId("1", "R20"))); }