Example usage for org.apache.commons.collections.primitives ArrayIntList addAll

List of usage examples for org.apache.commons.collections.primitives ArrayIntList addAll

Introduction

In this page you can find the example usage for org.apache.commons.collections.primitives ArrayIntList addAll.

Prototype

public boolean addAll(IntCollection collection) 

Source Link

Usage

From source file:weka.classifiers.rules.LACFeatureOccurrences.java

/**
 * Gets all instances which contain all given features
 * /*from www. ja va2  s . co m*/
 * @param featuresIndexes
 * @return
 */
public List<Integer> instancesWithFeatures(List<Integer> featuresIndexes) {
    ArrayIntList instances = cache.get(featuresIndexes);
    List<Integer> result = new ArrayList<Integer>();

    if (instances == null) {
        if (featuresIndexes.size() == 1) {
            instances = map.get(featuresIndexes.get(0));
            if (instances != null) {
                for (IntIterator iter = instances.iterator(); iter.hasNext();) {
                    result.add(iter.next());
                }
            }
        } else {
            instances = new ArrayIntList();

            Integer feature = featuresIndexes.get(0);
            ArrayIntList instancesForCurrFeat = map.get(feature);

            if (instancesForCurrFeat == null || instancesForCurrFeat.size() == 0) {
                return Collections.emptyList();
            } else {
                List<Integer> otherfeatures = new ArrayList<Integer>();
                otherfeatures.addAll(featuresIndexes);
                otherfeatures.remove(0);

                instances.addAll(instancesForCurrFeat);
                List<Integer> rest = instancesWithFeatures(otherfeatures);
                if (rest != null) {
                    List<Integer> instancesAsList = new ArrayList<Integer>();
                    for (IntIterator iter = instances.iterator(); iter.hasNext();) {
                        instancesAsList.add(iter.next());
                    }
                    result = calculateIntersection(instancesAsList, rest);
                    ///cache.put(featuresIndexes, instances);
                } else {
                    ///cache.put(featuresIndexes, new ArrayIntList());
                }
            }
        }
    }

    return result;
}