use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.
the class StringModificationStrategy method run.
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
BeanWrapper wrapper = BeanWrapperFactory.wrap(entity);
for (Map.Entry<String, Pair<String>> entry : _propertyUpdates.entrySet()) {
String property = entry.getKey();
Pair<String> value = entry.getValue();
Object propertyValue = wrapper.getPropertyValue(property);
if (propertyValue != null) {
String propertyStringValue = propertyValue.toString();
propertyStringValue = propertyStringValue.replaceAll(value.getFirst(), value.getSecond());
wrapper.setPropertyValue(property, propertyStringValue);
}
}
}
use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.
the class AgencyMergeStrategy method bulkRenameAgencyIdInProperties.
private <T> void bulkRenameAgencyIdInProperties(Iterable<T> elements, String oldAgencyId, String newAgencyId, String... properties) {
for (Object element : elements) {
BeanWrapper wrapped = BeanWrapperFactory.wrap(element);
for (String property : properties) {
AgencyAndId id = (AgencyAndId) wrapped.getPropertyValue(property);
if (id != null && id.getAgencyId().equals(oldAgencyId)) {
AgencyAndId updatedId = new AgencyAndId(newAgencyId, id.getId());
wrapped.setPropertyValue(property, updatedId);
}
}
}
}
use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsTestData method grep.
public static <T> List<T> grep(Iterable<T> elements, String propertyExpression, Object value) {
String[] properties = propertyExpression.split("\\.");
List<T> matches = new ArrayList<T>();
for (T element : elements) {
Object v = element;
for (String property : properties) {
BeanWrapper wrapper = BeanWrapperFactory.wrap(v);
v = wrapper.getPropertyValue(property);
}
if ((value == null && v == null) || (value != null && value.equals(v)))
matches.add(element);
}
return matches;
}
use of org.onebusaway.csv_entities.schema.BeanWrapper in project onebusaway-gtfs-modules by OneBusAway.
the class DeferredValueSupportTest method testResolveAgencyAndId_DefaultAgencyId.
@Test
public void testResolveAgencyAndId_DefaultAgencyId() {
Stop stop = new Stop();
BeanWrapper bean = BeanWrapperFactory.wrap(stop);
AgencyAndId id = _support.resolveAgencyAndId(bean, "id", "1");
assertEquals(new AgencyAndId("a0", "1"), id);
}
Aggregations