protected Object[] getObjects() { Object[] values = new Object[suppliers.length]; for(int i = 0; i < suppliers.length; i ++) { Supplier<?> s = suppliers[i]; if (s != null) { values[i] = s.get(); } } return values; } }
protected Object[] getObjects() { Object[] values = new Object[suppliers.length]; for(int i = 0; i < suppliers.length; i ++) { Supplier<?> s = suppliers[i]; if (s != null) { values[i] = s.get(); } } return values; } }
public T getValue() { return value.get(); } }
public T getValue() { return value.get(); } }
private TimeZone getTimeZone(Object[] params) { TimeZone defaultValue = TimeZone.getDefault(); if (params != null) { for(Object o : params) { if (o instanceof Supplier) { Supplier s = (Supplier) o; Object o1 = s.get(); if (o1 instanceof TimeZone) { return (TimeZone) o1; } } } } return defaultValue; }
private TimeZone getTimeZone(Object[] params) { TimeZone defaultValue = TimeZone.getDefault(); if (params != null) { for(Object o : params) { if (o instanceof Supplier) { Supplier s = (Supplier) o; Object o1 = s.get(); if (o1 instanceof TimeZone) { return (TimeZone) o1; } } } } return defaultValue; }
public static boolean isSupplierOf(Object potentialSupplier, Class<?> supplyClass) { if (!Supplier.class.isInstance(potentialSupplier)) { return false; } Object supply = ((Supplier)potentialSupplier).get(); if (supply == null) return false; return supplyClass.isInstance(supply); }
public static boolean isSupplierOf(Object potentialSupplier, Class<?> supplyClass) { if (!Supplier.class.isInstance(potentialSupplier)) { return false; } Object supply = ((Supplier)potentialSupplier).get(); if (supply == null) return false; return supplyClass.isInstance(supply); }
@Override public Context newContext() { Object[] resources = new Object[suppliers.length]; for(int i = 0; i < resources.length; i++) { resources[i] = suppliers[i].get(); } return new DefaultContext(resources); } }
@SuppressWarnings("unchecked") private ZoneOffset getZoneOffset(Object[] params) { for(Object prop : params) { if (prop instanceof ZoneOffset) { return (ZoneOffset) prop; } else if (SupplierHelper.isSupplierOf(prop, ZoneOffset.class)) { return ((Supplier<ZoneOffset>)prop).get(); } } return ZoneOffset.UTC; } });
@SuppressWarnings("unchecked") private ZoneOffset getZoneOffset(Object[] params) { for(Object prop : params) { if (prop instanceof ZoneOffset) { return (ZoneOffset) prop; } else if (SupplierHelper.isSupplierOf(prop, ZoneOffset.class)) { return ((Supplier<ZoneOffset>)prop).get(); } } return ZoneOffset.UTC; } });
@Override public Context newContext() { Object[] resources = new Object[suppliers.length]; for(int i = 0; i < resources.length; i++) { resources[i] = suppliers[i].get(); } return new DefaultContext(resources); } }
@SuppressWarnings("unchecked") public static ZoneId getZoneId(Object[] params) { if (params != null) { for(Object p : params) { if (p instanceof ZoneId) { return (ZoneId) p; } else if (p instanceof TimeZone) { return ((TimeZone)p).toZoneId(); } else if (SupplierHelper.isSupplierOf(p, ZoneId.class)) { return ((Supplier<ZoneId>)p).get(); } else if (SupplierHelper.isSupplierOf(p, TimeZone.class)) { return (((Supplier<TimeZone>)p).get()).toZoneId(); } } } return null; }
@SuppressWarnings("unchecked") public static ZoneId getZoneId(Object[] params) { if (params != null) { for(Object p : params) { if (p instanceof ZoneId) { return (ZoneId) p; } else if (p instanceof TimeZone) { return ((TimeZone)p).toZoneId(); } else if (SupplierHelper.isSupplierOf(p, ZoneId.class)) { return ((Supplier<ZoneId>)p).get(); } else if (SupplierHelper.isSupplierOf(p, TimeZone.class)) { return (((Supplier<TimeZone>)p).get()).toZoneId(); } } } return null; }
@SuppressWarnings("unchecked") private static DateTimeZone getDateTimeZone(Object[] params) { if (params != null) { for(Object p : params) { if (p instanceof DateTimeZone) { return (DateTimeZone) p; } else if (p instanceof TimeZone) { return DateTimeZone.forTimeZone((TimeZone)p); } else if (SupplierHelper.isSupplierOf(p, DateTimeZone.class)) { return ((Supplier<DateTimeZone>)p).get(); } else if (SupplierHelper.isSupplierOf(p, TimeZone.class)) { return DateTimeZone.forTimeZone(((Supplier<TimeZone>)p).get()); } } } return null; } }
@SuppressWarnings("unchecked") private static DateTimeFormatter toDateTimeFormatter(Object prop, ZoneId zoneId) { if (SupplierHelper.isSupplierOf(prop, DateTimeFormatter.class)) { return withZone(((Supplier<DateTimeFormatter>) prop).get(), zoneId); } else if (prop instanceof DateFormatSupplier) { return withZone(((DateFormatSupplier) prop).get(), zoneId); } else if (prop instanceof DateTimeFormatter) { return (DateTimeFormatter) prop; } return null; }
@SuppressWarnings("unchecked") private static DateTimeFormatter toDateTimeFormater(Object prop, DateTimeZone dateTimeZone) { if (SupplierHelper.isSupplierOf(prop, DateTimeFormatter.class)) { return (withZone(((Supplier<DateTimeFormatter>) prop).get(), dateTimeZone)); } else if (prop instanceof DateFormatSupplier) { return (withZone(((DateFormatSupplier)prop).get(), dateTimeZone)); } else if (prop instanceof DateTimeFormatter) { return (DateTimeFormatter) prop; } return null; }
@SuppressWarnings("unchecked") private static DateTimeFormatter toDateTimeFormatter(Object prop, ZoneId zoneId) { if (SupplierHelper.isSupplierOf(prop, DateTimeFormatter.class)) { return withZone(((Supplier<DateTimeFormatter>) prop).get(), zoneId); } else if (prop instanceof DateFormatSupplier) { return withZone(((DateFormatSupplier) prop).get(), zoneId); } else if (prop instanceof DateTimeFormatter) { return (DateTimeFormatter) prop; } return null; }
private <T> void testWriter(Supplier<T> supplier, String[] headers) throws Exception { T instance1 = supplier.get(); ClassMeta<T> classMeta = ReflectionService.newInstance().<T>getClassMeta(instance1.getClass()); Writerbuilder<T> builder = new Writerbuilder<T>(classMeta); Object[] row = new Object[headers.length]; for(int i = 0; i < headers.length; i++) { String str = headers[i]; builder.addColumn(str); row[i] = classMeta.newPropertyFinder().findProperty(DefaultPropertyNameMatcher.of(str), new Object[0], (TypeAffinity)null, ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).getGetter().get(instance1); } FieldMapper<T, List<Object>> mapper = builder.mapper(); List<Object> objects = new ArrayList<Object>(); mapper.mapTo(instance1, objects, MappingContext.EMPTY_CONTEXT); assertArrayEquals(row, objects.toArray()); }
private <T> void testDbObjectxxxMapper(Supplier<T> supplier, boolean useAsm, String[] headers) throws Exception { T instance1 = supplier.get(); T instance2 = supplier.get(); ClassMeta<T> classMeta = ReflectionService.newInstance(useAsm).<T>getClassMeta(instance1.getClass()); SampleMapperBuilder<T> builder = new SampleMapperBuilder<T>(classMeta); SampleMapperBuilder<T> builderIndexed = new SampleMapperBuilder<T>(classMeta); Object[] row = new Object[headers.length]; for(int i = 0; i < headers.length; i++) { String str = headers[i]; builder.addMapping(str); builderIndexed.addMapping(str, i); row[i] = classMeta.newPropertyFinder().findProperty(DefaultPropertyNameMatcher.of(str), new Object[0], (TypeAffinity)null, ConstantPredicate.<PropertyMeta<?, ?>>truePredicate()).getGetter().get(instance1); } EnumerableMapper<Object[][], T, ?> mapper = builder.mapper(); assertEquals(instance1, mapper.iterator(new Object[][] {row}).next()); Assert.assertEquals(instance1, builderIndexed.mapper().iterator(new Object[][] {row}).next()); assertNotEquals(instance1, instance2); }