@Test public void testArray() { String name = "hmily.yml"; Map<String, Object> map = new HashMap<>(); map.put("hmily.intArray[0]", 123); map.put("hmily.intArray[1]", 234); PropertyKeySource<?> propertySource = new MapPropertyKeySource(name, map); ConfigPropertySource configPropertySource = new DefaultConfigPropertySource<>(propertySource, PropertyKeyParse.INSTANCE); Binder binder = Binder.of(configPropertySource); BindData<CollectionPojo> data = BindData.of(DataType.of(CollectionPojo.class), CollectionPojo::new); CollectionPojo bind = binder.bind("hmily", data); Assert.assertEquals(bind.getIntArray()[0], Integer.valueOf(123)); Assert.assertEquals(bind.getIntArray()[1], Integer.valueOf(234)); }
@Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { DataType type = target.getType(); Class<?> collectionType = target.getValue() != null ? List.class : type.getTypeClass(); DataType aggregateType = DataType.of(collectionType); DataType elementType = type.getGenerics().length > 0 ? type.getGenerics()[0] : DataType.of(Object.class); IndexedBinder.IndexedCollectionSupplier result = new IndexedBinder.IndexedCollectionSupplier(() -> CollectionUtils.createFactory().create(collectionType, 0)); bindIndexed(propertyName, target, elementBinder, aggregateType, elementType, result); if (result.wasSupplied()) { return result.get(); } return null; }
CollectionBinder extends IndexedBinder<Collection<Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { DataType type = target.getType(); Class<?> collectionType = target.getValue() != null ? List.class : type.getTypeClass(); DataType aggregateType = DataType.of(collectionType); DataType elementType = type.getGenerics().length > 0 ? type.getGenerics()[0] : DataType.of(Object.class); IndexedBinder.IndexedCollectionSupplier result = new IndexedBinder.IndexedCollectionSupplier(() -> CollectionUtils.createFactory().create(collectionType, 0)); bindIndexed(propertyName, target, elementBinder, aggregateType, elementType, result); if (result.wasSupplied()) { return result.get(); } return null; } }
CollectionBinder extends IndexedBinder<Collection<Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { DataType type = target.getType(); Class<?> collectionType = target.getValue() != null ? List.class : type.getTypeClass(); DataType aggregateType = DataType.of(collectionType); DataType elementType = type.getGenerics().length > 0 ? type.getGenerics()[0] : DataType.of(Object.class); IndexedBinder.IndexedCollectionSupplier result = new IndexedBinder.IndexedCollectionSupplier(() -> CollectionUtils.createFactory().create(collectionType, 0)); bindIndexed(propertyName, target, elementBinder, aggregateType, elementType, result); if (result.wasSupplied()) { return result.get(); } return null; } CollectionBinder(final Binder.Env env); }
CollectionBinder extends IndexedBinder<Collection<Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { DataType type = target.getType(); Class<?> collectionType = target.getValue() != null ? List.class : type.getTypeClass(); DataType aggregateType = DataType.of(collectionType); DataType elementType = type.getGenerics().length > 0 ? type.getGenerics()[0] : DataType.of(Object.class); IndexedBinder.IndexedCollectionSupplier result = new IndexedBinder.IndexedCollectionSupplier(() -> CollectionUtils.createFactory().create(collectionType, 0)); bindIndexed(propertyName, target, elementBinder, aggregateType, elementType, result); if (result.wasSupplied()) { return result.get(); } return null; } CollectionBinder(final Binder.Env env); @Override Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder); @Override Object merge(final Supplier<?> targetValue, final Collection<Object> object); }
CollectionBinder extends IndexedBinder<Collection<Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { DataType type = target.getType(); Class<?> collectionType = target.getValue() != null ? List.class : type.getTypeClass(); DataType aggregateType = DataType.of(collectionType); DataType elementType = type.getGenerics().length > 0 ? type.getGenerics()[0] : DataType.of(Object.class); IndexedBinder.IndexedCollectionSupplier result = new IndexedBinder.IndexedCollectionSupplier(() -> CollectionUtils.createFactory().create(collectionType, 0)); bindIndexed(propertyName, target, elementBinder, aggregateType, elementType, result); if (result.wasSupplied()) { return result.get(); } return null; } CollectionBinder(final Binder.Env env); @Override Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder); @Override Object merge(final Supplier<?> targetValue, final Collection<Object> object);  }