Search in sources :

Example 1 with AbstractCollection

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);
}
Also used : CustomNumberEditor(org.springframework.beans.propertyeditors.CustomNumberEditor) PropertyEditorRegistry(org.springframework.beans.PropertyEditorRegistry) HashMap(java.util.HashMap) PropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar) AbstractCollection(java.util.AbstractCollection) ArrayList(java.util.ArrayList) GenericBean(org.springframework.tests.sample.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with AbstractCollection

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);
}
Also used : StringTokenizer(java.util.StringTokenizer) UMSException(com.iplanet.ums.UMSException) AbstractCollection(java.util.AbstractCollection) PersistentObject(com.iplanet.ums.PersistentObject)

Example 3 with AbstractCollection

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();
        }
    };
}
Also used : PrefixCodedTerms(org.apache.lucene.index.PrefixCodedTerms) AbstractCollection(java.util.AbstractCollection) Iterator(java.util.Iterator) TermIterator(org.apache.lucene.index.PrefixCodedTerms.TermIterator) BytesRefIterator(org.apache.lucene.util.BytesRefIterator) TermIterator(org.apache.lucene.index.PrefixCodedTerms.TermIterator) IntPoint(org.apache.lucene.document.IntPoint) NoSuchElementException(java.util.NoSuchElementException) BytesRef(org.apache.lucene.util.BytesRef)

Example 4 with AbstractCollection

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);
}
Also used : CustomNumberEditor(org.springframework.beans.propertyeditors.CustomNumberEditor) PropertyEditorRegistry(org.springframework.beans.PropertyEditorRegistry) HashMap(java.util.HashMap) PropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar) AbstractCollection(java.util.AbstractCollection) ArrayList(java.util.ArrayList) GenericBean(org.springframework.tests.sample.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AbstractCollection (java.util.AbstractCollection)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 PropertyEditorRegistrar (org.springframework.beans.PropertyEditorRegistrar)2 PropertyEditorRegistry (org.springframework.beans.PropertyEditorRegistry)2 CustomNumberEditor (org.springframework.beans.propertyeditors.CustomNumberEditor)2 GenericBean (org.springframework.tests.sample.beans.GenericBean)2 PersistentObject (com.iplanet.ums.PersistentObject)1 UMSException (com.iplanet.ums.UMSException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 StringTokenizer (java.util.StringTokenizer)1 IntPoint (org.apache.lucene.document.IntPoint)1 PrefixCodedTerms (org.apache.lucene.index.PrefixCodedTerms)1 TermIterator (org.apache.lucene.index.PrefixCodedTerms.TermIterator)1 BytesRef (org.apache.lucene.util.BytesRef)1 BytesRefIterator (org.apache.lucene.util.BytesRefIterator)1