use of java.util.AbstractCollection in project spring-framework by spring-projects.
the class BeanFactoryGenericsTests method testGenericMapWithCollectionValueFactoryMethod.
@Test
public void testGenericMapWithCollectionValueFactoryMethod() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
}
});
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setFactoryMethodName("createInstance");
Map<String, AbstractCollection<?>> input = new HashMap<>();
HashSet<Integer> value1 = new HashSet<>();
value1.add(new Integer(1));
input.put("1", value1);
ArrayList<Boolean> value2 = new ArrayList<>();
value2.add(Boolean.TRUE);
input.put("2", value2);
rbd.getConstructorArgumentValues().addGenericArgumentValue(Boolean.TRUE);
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
assertTrue(gb.getCollectionMap().get(new Integer(2)) instanceof ArrayList);
}
use of java.util.AbstractCollection in project OpenAM by OpenRock.
the class COSManager method addDefinition.
/**
* This method adds a COS definition to the persistent store. The definition
* is added under the specified "guid" parameter.
*
* @param cosDef
* The COS definition to be added.
*
* @throws UMSException
* The exception thrown from the data layer.
* @supported.api
*/
public void addDefinition(ICOSDefinition cosDef) throws UMSException {
if (!(cosDef instanceof DirectCOSDefinition)) {
String msg = i18n.getString(IUMSConstants.INVALID_COSDEFINITION);
throw new UMSException(msg);
}
String[] cosAttributes = cosDef.getCOSAttributes();
AbstractCollection aList = (AbstractCollection) Arrays.asList(ICOSDefinition.qualifiers);
for (int i = 0; i < cosAttributes.length; i++) {
String cosAttribute = null;
String qualifier = null;
StringTokenizer st = new StringTokenizer(cosAttributes[i]);
if (st.hasMoreTokens()) {
cosAttribute = st.nextToken();
}
if (cosAttribute == null) {
String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
throw new UMSException(msg);
}
if (st.hasMoreTokens())
qualifier = st.nextToken();
if (qualifier == null) {
qualifier = ICOSDefinition.qualifiers[ICOSDefinition.DEFAULT];
cosDef.removeCOSAttribute(cosAttribute);
cosDef.addCOSAttribute(cosAttribute, ICOSDefinition.DEFAULT);
}
if (!aList.contains(qualifier)) {
String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
throw new UMSException(msg);
}
}
PersistentObject po = (PersistentObject) cosDef;
_parentObject.addChild(po);
}
use of java.util.AbstractCollection in project lucene-solr by apache.
the class PointInSetQuery method getPackedPoints.
public Collection<byte[]> getPackedPoints() {
return new AbstractCollection<byte[]>() {
@Override
public Iterator<byte[]> iterator() {
int size = (int) sortedPackedPoints.size();
PrefixCodedTerms.TermIterator iterator = sortedPackedPoints.iterator();
return new Iterator<byte[]>() {
int upto = 0;
@Override
public boolean hasNext() {
return upto < size;
}
@Override
public byte[] next() {
if (upto == size) {
throw new NoSuchElementException();
}
upto++;
BytesRef next = iterator.next();
return Arrays.copyOfRange(next.bytes, next.offset, next.length);
}
};
}
@Override
public int size() {
return (int) sortedPackedPoints.size();
}
};
}
use of java.util.AbstractCollection in project spring-framework by spring-projects.
the class BeanFactoryGenericsTests method testGenericMapWithCollectionValueConstructor.
@Test
public void testGenericMapWithCollectionValueConstructor() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
}
});
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
Map<String, AbstractCollection<?>> input = new HashMap<>();
HashSet<Integer> value1 = new HashSet<>();
value1.add(new Integer(1));
input.put("1", value1);
ArrayList<Boolean> value2 = new ArrayList<>();
value2.add(Boolean.TRUE);
input.put("2", value2);
rbd.getConstructorArgumentValues().addGenericArgumentValue(Boolean.TRUE);
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
assertTrue(gb.getCollectionMap().get(new Integer(2)) instanceof ArrayList);
}
Aggregations