Example usage for org.apache.commons.collections15 CollectionUtils subtract

List of usage examples for org.apache.commons.collections15 CollectionUtils subtract

Introduction

In this page you can find the example usage for org.apache.commons.collections15 CollectionUtils subtract.

Prototype

public static <E> Collection<E> subtract(final Collection<? extends E> a, final Iterable<? extends E> b) 

Source Link

Document

Returns a new Collection containing a - b.

Usage

From source file:de.tuberlin.uebb.jbop.optimizer.utils.RemoveUnusedFields.java

/**
 * Removes the unused fields./*from ww w  .  j a  v a  2 s  .co  m*/
 * 
 * @param classNode
 *          the class node
 */
public static void removeUnusedFields(final ClassNode classNode) {
    final Set<FieldNode> usedFields = new HashSet<>();
    collectUsedFields(classNode, usedFields);
    final Collection<FieldNode> unusedFields = CollectionUtils.subtract(classNode.fields, usedFields);
    classNode.fields.removeAll(unusedFields);
    correctConstructors(classNode);
}

From source file:edu.uci.ics.jung.algorithms.blockmodel.StructurallyEquivalent.java

public VertexPartition<V, E> transform(Graph<V, E> g) {
    Set<Pair<V>> vertex_pairs = getEquivalentPairs(g);

    Set<Set<V>> rv = new HashSet<Set<V>>();
    Map<V, Set<V>> intermediate = new HashMap<V, Set<V>>();
    for (Pair<V> p : vertex_pairs) {
        Set<V> res = intermediate.get(p.getFirst());
        if (res == null)
            res = intermediate.get(p.getSecond());
        if (res == null) // we haven't seen this one before
            res = new HashSet<V>();
        res.add(p.getFirst());//w ww . ja  v a2 s .  com
        res.add(p.getSecond());
        intermediate.put(p.getFirst(), res);
        intermediate.put(p.getSecond(), res);
    }
    rv.addAll(intermediate.values());

    // pick up the vertices which don't appear in intermediate; they are
    // singletons (equivalence classes of size 1)
    Collection<V> singletons = CollectionUtils.subtract(g.getVertices(), intermediate.keySet());
    for (V v : singletons) {
        Set<V> v_set = Collections.singleton(v);
        intermediate.put(v, v_set);
        rv.add(v_set);
    }

    return new VertexPartition<V, E>(g, intermediate, rv);
}

From source file:edu.northwestern.bioinformatics.studycalendar.restlets.SchedulePreviewResource.java

@Override
protected ScheduledCalendar loadRequestedObject(Request request) throws ResourceException {
    Study study;/*  www .  java 2 s.c  o  m*/
    try {
        study = helper.getAmendedTemplate();
    } catch (AmendedTemplateHelper.NotFound notFound) {
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, notFound.getMessage());
    }
    Form query = request.getResourceRef().getQueryAsForm();

    Map<String, Date> startDates = buildStartDateMap(query);
    Map<String, StudySegment> segments = buildSegmentMap(study, query);

    if (!startDates.keySet().equals(segments.keySet())) {
        Collection<String> startDateOnly = CollectionUtils.subtract(startDates.keySet(), segments.keySet());
        if (startDateOnly.size() > 0) {
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                    "The following start_date(s) do not have matching segment(s): " + startDateOnly);
        }
        Collection<String> segmentOnly = CollectionUtils.subtract(segments.keySet(), startDates.keySet());
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                "The following segment(s) do not have matching start_date(s): " + segmentOnly);
    } else if (startDates.size() == 0) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
                "At least one segment/start_date pair is required");
    }

    for (String key : segments.keySet()) {
        subjectService.scheduleStudySegmentPreview(scheduledCalendar, segments.get(key), startDates.get(key));
    }
    return scheduledCalendar;
}

From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkLoader.java

/**
 * Load the tuples for the given table name
 * @param tableName/*ww w .  ja  va2 s.c o m*/
 */
protected void generateTableData(String tableName) throws SQLException {
    LOG.info("*** START " + tableName);
    final AbstractTableGenerator generator = this.generators.get(tableName);
    assert (generator != null);

    // Generate Data
    final Table catalog_tbl = benchmark.getCatalog().getTable(tableName);
    assert (catalog_tbl != null) : tableName;
    final List<Object[]> volt_table = generator.getVoltTable();
    final String sql = SQLUtil.getInsertSQL(catalog_tbl);
    final PreparedStatement stmt = conn.prepareStatement(sql);
    final int types[] = catalog_tbl.getColumnTypes();

    while (generator.hasMore()) {
        generator.generateBatch();

        //            StringBuilder sb = new StringBuilder();
        //            if (tableName.equalsIgnoreCase("USER_FEEDBACK")) { //  || tableName.equalsIgnoreCase("USER_ATTRIBUTES")) {
        //                sb.append(tableName + "\n");
        //                for (int i = 0; i < volt_table.size(); i++) {
        //                    sb.append(String.format("[%03d] %s\n", i, StringUtil.abbrv(Arrays.toString(volt_table.get(i)), 100)));
        //                }
        //                LOG.info(sb.toString() + "\n");
        //            }

        for (Object row[] : volt_table) {
            for (int i = 0; i < row.length; i++) {
                if (row[i] != null) {
                    stmt.setObject(i + 1, row[i]);
                } else {
                    stmt.setNull(i + 1, types[i]);
                }
            } // FOR
            stmt.addBatch();
        } // FOR
        try {
            stmt.executeBatch();
            conn.commit();
            stmt.clearBatch();
        } catch (SQLException ex) {
            if (ex.getNextException() != null)
                ex = ex.getNextException();
            LOG.warn(tableName + " - " + ex.getMessage());
            throw ex;
            // SKIP
        }

        this.tableSizes.put(tableName, volt_table.size());

        // Release anything to the sub-generators if we have it
        // We have to do this to ensure that all of the parent tuples get
        // insert first for foreign-key relationships
        generator.releaseHoldsToSubTableGenerators();
    } // WHILE
    stmt.close();

    // Mark as finished
    if (this.fail == false) {
        generator.markAsFinished();
        synchronized (this) {
            this.finished.add(tableName);
            LOG.info(String.format("*** FINISH %s - %d tuples - [%d / %d]", tableName,
                    this.tableSizes.get(tableName), this.finished.size(), this.generators.size()));
            if (LOG.isDebugEnabled()) {
                LOG.debug("Remaining Tables: "
                        + CollectionUtils.subtract(this.generators.keySet(), this.finished));
            }
        } // SYNCH
    }
}

From source file:edu.brown.benchmark.auctionmark.AuctionMarkLoader.java

/**
 * Load the tuples for the given table name
 * @param tableName/* w ww. ja v a  2  s  .  c  o m*/
 */
protected void generateTableData(String tableName) {
    LOG.info("*** START " + tableName);
    final AbstractTableGenerator generator = this.generators.get(tableName);
    assert (generator != null);

    // Generate Data
    final VoltTable volt_table = generator.getVoltTable();
    while (generator.hasMore()) {
        generator.generateBatch();
        this.loadVoltTable(generator.getTableName(), volt_table);
        volt_table.clearRowData();
    } // WHILE

    // Mark as finished
    generator.markAsFinished();
    this.finished.add(tableName);
    LOG.info(String.format("*** FINISH %s - %d tuples - [%d / %d]", tableName,
            this.getTableTupleCount(tableName), this.finished.size(), this.generators.size()));
    if (debug.val) {
        LOG.debug("Remaining Tables: " + CollectionUtils.subtract(this.generators.keySet(), this.finished));
    }
}