Example usage for org.apache.commons.collections ListUtils sum

List of usage examples for org.apache.commons.collections ListUtils sum

Introduction

In this page you can find the example usage for org.apache.commons.collections ListUtils sum.

Prototype

public static List sum(final List list1, final List list2) 

Source Link

Document

Returns the sum of the given lists.

Usage

From source file:com.norconex.commons.lang.map.PropertiesTest.java

@Test
public void testRemoveCaseInsensitiveMultiple() throws Exception {
    Properties properties = new Properties(true);
    List<String> list1 = asList("a", "b", "c");
    List<String> list2 = asList("d", "e", "f");
    properties.put("Key", list1);
    properties.put("KEy", list2);
    assertEquals(ListUtils.sum(list1, list2), properties.remove("key"));
}

From source file:br.ufrj.nce.recureco.distributedindex.search.service.SearchService.java

public List<String> getDocuments(String query, boolean booleanOr) {

    List<String> andWords = lineTokenizer.tokenize(query);

    //if query words list is null, return empty results
    if (andWords == null) {
        return new ArrayList<String>();
    }/*from  ww  w  . jav  a  2 s .c  om*/
    //if query words list is  empty, return empty results
    if (andWords.size() == 0) {
        return new ArrayList<String>();
    }

    //if still here, there is something to search
    List<String> results = searchDAO.getDocuments(andWords);

    List<String> documentsResults = new ArrayList<String>();

    boolean firstTime = true;

    for (String docs : results) {

        List<String> auxList = new ArrayList<String>();
        CollectionUtils.addAll(auxList, docs.split(","));

        if (booleanOr) {
            documentsResults = ListUtils.sum(documentsResults, auxList);
        } else {
            if (firstTime) {
                documentsResults = ListUtils.union(documentsResults, auxList);
                firstTime = false;
            } else {
                documentsResults = ListUtils.intersection(documentsResults, auxList);
            }
        }
    }

    return documentsResults;
}

From source file:de.iteratec.iteraplan.elasticeam.derived.DecoratedUniversalType.java

/**{@inheritDoc}**/
@SuppressWarnings("unchecked")
public final List<FeatureExpression<?>> getFeatures() {
    return ListUtils.sum(this.properties.get(), this.relationshipEnds.get());
}

From source file:edu.isistan.carcha.util.Utils.java

/**
 * Sum./*from w ww  .j a  v a 2  s . c o m*/
 *
 * @param concerns the concerns
 * @param designDecision the design decision
 * @return the list
 */
@SuppressWarnings("unchecked")
public static List<String> sum(List<Entity> concerns, List<Entity> designDecision) {
    List<String> ret = ListUtils.sum(Utils.transformedList(concerns, new Entity2String()),
            Utils.transformedList(designDecision, new Entity2String()));
    return ret;
}

From source file:com.ebay.cloud.cms.entmgr.entity.impl.EntityFieldTargetMerger.java

private List<?> mergeTargetContent(List<?> giveValues, List<?> foundValues, AtomicBoolean hasChange) {
    List<?> result = null;//from w w  w  .j a  v  a2  s.c om
    if (pull) {
        result = ListUtils.subtract(foundValues, giveValues);
    } else {
        result = ListUtils.sum(foundValues, giveValues);
    }
    hasChange.set(!ListUtils.isEqualList(result, foundValues));
    return result;
}

From source file:it.eng.spagobi.engines.worksheet.bo.WorkSheetDefinition.java

public static void addDomainValuesFilters(List<Attribute> toReturn, List<Attribute> sheetFilters) {
    Iterator<Attribute> it = sheetFilters.iterator();
    while (it.hasNext()) {
        Attribute aFilter = it.next();
        if (toReturn.contains(aFilter)) {
            int index = toReturn.indexOf(aFilter);
            Attribute previousFilter = toReturn.get(index);
            List<String> previousValues = previousFilter.getValuesAsList();
            List<String> newValues = aFilter.getValuesAsList();
            List<String> sum = ListUtils.sum(previousValues, newValues);
            previousFilter.setValues(sum);
        } else {//from   ww w .  ja  va2s  . co  m
            Attribute clone = aFilter.clone();
            toReturn.add(clone);
        }
    }
}

From source file:com.hs.mail.imap.dao.MySqlSearchDao.java

private List<Long> query(List<Long> result, UidToMsnMapper map, long mailboxID, SearchKey key, boolean and) {
    List<Long> list = query(map, mailboxID, key);
    if (CollectionUtils.isNotEmpty(result)) {
        return (and) ? ListUtils.intersection(result, list) : ListUtils.sum(result, list);
    } else {//from   www .  j  a  va2s.c o  m
        return list;
    }
}

From source file:nl.intercommit.weaves.grid.PagedGridDataSource.java

public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {
    assert sortConstraints != null;
    this.startIndex = startIndex;
    final int endIndexPlusOne = endIndex + 1;// always try to retrieve on record more
    final List<SortConstraint> constraints = ListUtils.sum(sortConstraints, addAdditionalSorting());
    preparedResults = (List<T>) fetchResult(startIndex, endIndexPlusOne, constraints);
}

From source file:org.anyframe.iam.core.intercept.web.ReloadableRestrictedTimesFilterInvocationSecurityMetadataSource.java

/**
 * in case of roleCheck, return sum of restricted roles in case of
 * resourceCheck, return result of re-operation with Intersection of allowed
 * roles/*from  ww  w .j ava  2s . c  o  m*/
 * 
 * @param isRoleCheck true if roleCheck
 * @param candidateFoundCadList list of candidate permissions that matches
 * the given time
 * @return List<ConfigAttribute> ConfigAttribute List
 */
private List<ConfigAttribute> recalculateCandidate(boolean isRoleCheck, List candidateFoundCadList) {
    List<ConfigAttribute> foundCad = new ArrayList<ConfigAttribute>();
    List configList = null;
    List presentList = null;
    List nextList = null;
    for (int i = 0; i < candidateFoundCadList.size(); i++) {
        presentList = (List<ConfigAttribute>) candidateFoundCadList.get(i);
        if (i == 0) {
            configList = presentList;
        }
        if (i + 1 < candidateFoundCadList.size()) {
            nextList = (List<ConfigAttribute>) candidateFoundCadList.get(i + 1);
            // Role Check ?  restricted Role ? add .
            if (isRoleCheck) {
                configList = ListUtils.sum(configList, nextList);
            } else { // Resource Check ?  unrestricted Role ?  
                //  intersection 
                configList = ListUtils.intersection(configList, nextList);
            }
        }
    }
    foundCad.addAll(configList);
    if (logger.isDebugEnabled())
        logger.debug("candidateFoundCadList : " + candidateFoundCadList
                + (isRoleCheck ? ", summed List : " : ", intersected List : ") + foundCad);
    return foundCad;
}

From source file:org.apache.mahout.knn.search.OldProjectionSearchTest.java

public void testSearch() {
    final EuclideanDistanceMeasure distance = new EuclideanDistanceMeasure();
    for (int d = 10; d < 11; d++) {
        ProjectionSearch ps = new ProjectionSearch(20, distance, d, 1);
        List<Vector> ref = Lists.newArrayList();

        final DoubleFunction random = Functions.random();
        for (int i = 0; i < 40000; i++) {
            Vector v = new DenseVector(20);
            v.assign(random);//ww w.jav a2 s  .c o  m
            ps.add(v, i);
            ref.add(v);
        }

        double sim = 0;
        int nSim = 0;
        double D1 = 0;
        double D2 = 0;
        double D3 = 0;
        int searchSize = 400;
        int returnSize = 100;
        List<Vector> randomNeighbor = Lists.newArrayList();
        randomNeighbor.addAll(ref.subList(0, returnSize));

        long runningTime = 0;

        for (int i = 0; i < 100; i++) {
            // final Vector query = new DenseVector(ref.get(0));
            final Vector query = new DenseVector(20);
            query.assign(random);
            Ordering<Vector> queryOrder = new Ordering<Vector>() {
                @Override
                public int compare(Vector v1, Vector v2) {
                    return Double.compare(distance.distance(query, v1), distance.distance(query, v2));
                }
            };

            Collections.sort(ref, queryOrder);
            List<Vector> trueNeighbor = ref.subList(0, returnSize);

            long t1 = System.nanoTime();
            ps.setSearchSize(searchSize);
            List<WeightedVector> r = ps.search(query, returnSize);
            long t2 = System.nanoTime();
            runningTime = runningTime + t2 - t1;

            List<WeightedVector> proxyNeighbor = r.subList(0, returnSize);
            List<Vector> intersection1 = ListUtils.intersection(trueNeighbor, proxyNeighbor);
            List<Vector> union1 = ListUtils.sum(trueNeighbor, proxyNeighbor);
            // double jaccardSim = intersection1.size() / (double)union1.size();  
            // sim += jaccardSim;
            sim += intersection1.size() / (double) returnSize;
            nSim++;

            double d1 = 0;
            double d2 = 0;
            double d3 = 0;
            for (int j = 0; j < returnSize; j++) {
                d1 += distance.distance(query, trueNeighbor.get(j));
                d2 += distance.distance(query, proxyNeighbor.get(j));
                d3 += distance.distance(query, randomNeighbor.get(j));
                //System.out.print(distance.distance(query,trueNeighbor.get(j)));
                //System.out.print(" ");
                //System.out.println(distance.distance(query,randomNeighbor.get(j)));
            }
            d1 = d1 / returnSize;
            d2 = d2 / returnSize;
            d3 = d3 / returnSize;
            D1 += d1;
            D2 += d2;
            D3 += d3;

            /****
            System.out.print(intersection1.size());
            System.out.print(" ");
            System.out.print(union1.size());
            System.out.print(" ");
            System.out.println(jaccardSim);
            *****/
        }
        System.out.printf(
                "d=%d ave_sim=%.2f trueNeighbor_dist=%.2f proxyNeighbor_dist=%.2f randomNeighbor_dist=%.2f \n",
                d, sim / nSim, D1 / nSim, D2 / nSim, D3 / nSim);
        System.out.printf("running time = %.2f seconds \n", runningTime / 1e9);
    }

}