Example usage for java.util SortedSet remove

List of usage examples for java.util SortedSet remove

Introduction

In this page you can find the example usage for java.util SortedSet remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes the specified element from this set if it is present (optional operation).

Usage

From source file:de.uni_potsdam.hpi.asg.logictool.helper.BDDHelper.java

public static BDD mergeBDDs(BDD bdd, NetlistVariable replaceVar, BDD replaceBdd, Netlist netlist) {

    Set<NetlistVariable> bddvars = BDDHelper.getVars(bdd, netlist);
    if (!bddvars.contains(replaceVar)) {
        logger.error("ReplaceVar not in Vars");
        return null;
    }//  w w  w  .  ja v  a  2  s .co m

    if (bddvars.size() == 1) {
        //         logger.debug("Shortcut");
        //         logger.debug("BDD: " + getFunctionString(bdd, netlist));
        //         logger.debug("ReplBDD: " + getFunctionString(replaceBdd, netlist));
        //         logger.debug("ReplVar: " + replaceVar.getName());
        if (isPos(bdd, replaceVar)) {
            return replaceBdd;
        } else {
            return replaceBdd.not();
        }
        //         return replaceBdd;//.and(netlist.getFac().one());
    }

    SortedSet<NetlistVariable> newinputs = new TreeSet<>();
    newinputs.addAll(bddvars);
    newinputs.addAll(BDDHelper.getVars(replaceBdd, netlist));
    newinputs.remove(replaceVar);
    //      System.out.println("New Inp: " + newinputs.toString());

    BDD retVal = netlist.getFac().zero();
    BitSet b = new BitSet(newinputs.size());
    for (int i = 0; i < Math.pow(2, newinputs.size()); i++) {
        //         System.out.println(i + ": " + BitSetHelper.formatBitset(b, newinputs.size()));
        int index = 0;
        BDD bdd_new = bdd;
        BDD replacBdd_new = replaceBdd;
        BDD minterm = netlist.getFac().one();
        //TODO: xWITH
        for (NetlistVariable var : newinputs) {
            if (b.get(index)) {
                bdd_new = bdd_new.restrict(var.toBDD());
                replacBdd_new = replacBdd_new.restrict(var.toBDD());
                minterm = minterm.and(var.toBDD());
            } else {
                bdd_new = bdd_new.restrict(var.toNotBDD());
                replacBdd_new = replacBdd_new.restrict(var.toNotBDD());
                minterm = minterm.and(var.toNotBDD());
            }
            index++;
        }
        if (replacBdd_new.isZero()) {
            bdd_new = bdd_new.restrict(replaceVar.toNotBDD());
        } else if (replacBdd_new.isOne()) {
            bdd_new = bdd_new.restrict(replaceVar.toBDD());
        } else {
            logger.error("Repl BDD should be one or zero");
        }

        if (bdd_new.isZero()) {

        } else if (bdd_new.isOne()) {
            retVal.orWith(minterm);
        } else {
            logger.error("BDD should be one or zero");
        }

        BitSetHelper.dualNext(b);
    }

    //      if(bddvars.size() == 1) {
    //         logger.debug("RetVal: " + getFunctionString(retVal, netlist));
    //      }

    return retVal;
}

From source file:com.opencredo.portlet.MyBooksController.java

@RequestMapping("EDIT")
public void myEditBooksAction(ActionRequest request, PortletPreferences prefs,
        @RequestParam("what") String what, @RequestParam("book") Integer id) {
    Book book = bookService.getBook(id);
    if (book == null)
        return;//  www  .j a va  2 s.  com
    SortedSet<Book> myBooks = loadMyBooks(prefs);
    if (what.equals("add")) {
        myBooks.add(book);
    } else if (what.equals("remove")) {
        myBooks.remove(book);
    }
    storeMyBooks(prefs, myBooks);
}

From source file:sample.portlet.MyBooksEditController.java

@Override
protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {

    String what = request.getParameter("what");
    if (what == null)
        return;//from   w ww  . j a  v  a 2s  .c om

    Integer id = Integer.valueOf(request.getParameter("book"));
    if (id == null)
        return;

    Book book = bookService.getBook(id);
    if (book == null)
        return;

    SortedSet<Book> myBooks = loadMyBooks(request);

    if (what.equals("add")) {
        myBooks.add(book);
    } else if (what.equals("remove")) {
        myBooks.remove(book);
    }

    storeMyBooks(request, myBooks);
}

From source file:com.sonymobile.jenkins.plugins.gitlab.gitlabauth.acl.GitLabGlobalACL.java

@Override
public Collection<PermissionGroup> getApplicablePermissionGroups() {
    SortedSet<PermissionGroup> permissionGroups = new TreeSet<PermissionGroup>(PermissionGroup.getAll());
    permissionGroups.remove(PermissionGroup.get(Permission.class));

    return permissionGroups;
}

From source file:cn.loveapple.client.android.database.impl.TemperatureDaoImpl.java

/**
 * {@inheritDoc}//  w  w w.  ja  v a  2  s .c  om
 */
@Override
public SortedMap<String, TemperatureEntity> findTemperatureMap(String datePoint) {
    Calendar current = Calendar.getInstance();
    Calendar start = Calendar.getInstance();
    if (StringUtils.isNotEmpty(datePoint)) {
        current.setTime(DateUtil.paseDate(datePoint, DateUtil.DATE_PTTERN_YYYYMMDD));
    }
    start.set(current.get(Calendar.YEAR), current.get(Calendar.MONTH) - LIMIT_MONTH,
            current.get(Calendar.DAY_OF_MONTH));

    List<TemperatureEntity> tempList = findByTerm(DateUtil.toDateString(start.getTime()),
            DateUtil.toDateString(current.getTime()));

    SortedMap<String, TemperatureEntity> result = new TreeMap<String, TemperatureEntity>();

    if (CollectionUtils.isEmpty(tempList)) {
        return result;
    }

    // ???
    SortedSet<String> dateSet = createDateKey(tempList.get(0).getDate());
    for (TemperatureEntity temp : tempList) {
        dateSet.remove(temp.getDate());
        result.put(temp.getDate(), temp);
    }
    for (String date : dateSet) {
        TemperatureEntity temperature = new TemperatureEntity();
        temperature.setDate(date);
        result.put(date, temperature);
    }

    return result;
}

From source file:hu.ppke.itk.nlpg.purepos.decoder.BeamedViterbi.java

private List<Pair<List<Integer>, Double>> findMax(final HashMap<NGram<Integer>, Node> beam, int resultsNumber) {

    // Node max = Collections.max(beam.values());
    // Node act = max;
    // return decompose(max);

    SortedSet<Node> sortedKeys = new TreeSet<Node>(beam.values());

    List<Pair<List<Integer>, Double>> ret = new ArrayList<Pair<List<Integer>, Double>>();
    Node max;/*from   www .ja v  a  2s .c o m*/
    for (int i = 0; i < resultsNumber && !sortedKeys.isEmpty(); ++i) {
        max = sortedKeys.last();
        sortedKeys.remove(max);
        List<Integer> maxTagSeq = decompose(max);
        ret.add(Pair.of(maxTagSeq, max.weight));
    }
    return ret;

}

From source file:mondrian.olap.IdBatchResolver.java

/**
 *  Loops through the SortedSet of Ids, attempting to load sets of
 *  children of parent Ids.//from www .j  av  a 2s  .  c o  m
 *  The loop below assumes the the SortedSet is ordered by segment
 *  size from smallest to largest, such that parent identifiers will
 *  occur before their children.
 */
private Map<QueryPart, QueryPart> resolveInParentGroupings(SortedSet<Id> identifiers) {
    final Map<QueryPart, QueryPart> resolvedIdentifiers = new HashMap<QueryPart, QueryPart>();

    while (identifiers.size() > 0) {
        Id parent = identifiers.first();
        identifiers.remove(parent);

        if (!supportedIdentifier(parent)) {
            continue;
        }
        Exp exp = (Exp) resolvedIdentifiers.get(parent);
        if (exp == null) {
            exp = lookupExp(resolvedIdentifiers, parent);
        }
        Member parentMember = getMemberFromExp(exp);
        if (!supportedMember(parentMember)) {
            continue;
        }
        batchResolveChildren(parent, parentMember, identifiers, resolvedIdentifiers);
    }
    return resolvedIdentifiers;
}

From source file:org.openmrs.web.controller.maintenance.SettingsController.java

@ModelAttribute(SECTIONS)
public List<String> getSections() {
    SortedSet<String> sortedSections = new TreeSet<String>();
    List<GlobalProperty> globalProperties = getService().getAllGlobalProperties();
    for (GlobalProperty globalProperty : globalProperties) {
        SettingsProperty property = new SettingsProperty(globalProperty);
        if (!isHidden(property)) {
            sortedSections.add(property.getSection());
        }/*w  w w.j ava2 s. com*/
    }

    List<String> sections = new ArrayList<String>();
    if (sortedSections.remove(SettingsProperty.GENERAL)) {
        sections.add(SettingsProperty.GENERAL);
    }
    sections.addAll(sortedSections);

    return sections;
}

From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java

public Distance getDistance(RealVector vec, int id, boolean approx) {
    double distance = Double.POSITIVE_INFINITY;
    int closestPoint = -1;
    if (approx) {
        if (updated) {
            rebuildIndices();//from w  w w. ja v  a 2s  .c o  m
        }

        BitSet q = index(vec);
        List<BitSet> index = indices.get(id);
        SortedSet<Idx> lookup = Sets.newTreeSet();
        for (int j = 0; j < index.size(); j++) {
            Idx idx = new Idx(hammingDistance(q, index.get(j)), j);
            if (lookup.size() < projectionSamples) {
                lookup.add(idx);
            } else if (idx.compareTo(lookup.last()) < 0) {
                lookup.add(idx);
                lookup.remove(lookup.last());
            }
        }

        List<RealVector> p = points.get(id);
        List<Double> lsq = lengthSquared.get(id);
        for (Idx idx : lookup) {
            double lenSq = lsq.get(idx.getIndex());
            double length = vec.getNorm();
            double d = length * length + lenSq - 2 * vec.dotProduct(p.get(idx.getIndex()));
            if (d < distance) {
                distance = d;
                closestPoint = idx.getIndex();
            }
        }
    } else { // More expensive exact computation
        List<RealVector> px = points.get(id);
        List<Double> lsq = lengthSquared.get(id);
        for (int j = 0; j < px.size(); j++) {
            RealVector p = px.get(j);
            double lenSq = lsq.get(j);
            double length = vec.getNorm();
            double d = length * length + lenSq - 2 * vec.dotProduct(p);
            if (d < distance) {
                distance = d;
                closestPoint = j;
            }
        }
    }

    return new Distance(distance, closestPoint);
}

From source file:com.streamsets.pipeline.stage.destination.cassandra.CassandraTarget.java

/**
 * Convert a Record into a fully-bound statement.
 *///from   ww  w.j av  a  2  s  . c  o  m
private BoundStatement recordToBoundStatement(Record record) throws StageException {
    ImmutableList.Builder<Object> values = new ImmutableList.Builder<>();
    SortedSet<String> columnsPresent = Sets.newTreeSet(columnMappings.keySet());
    for (Map.Entry<String, String> mapping : columnMappings.entrySet()) {
        String columnName = mapping.getKey();
        String fieldPath = mapping.getValue();

        // If we're missing fields, skip them.
        if (!record.has(fieldPath)) {
            columnsPresent.remove(columnName);
            continue;
        }

        final Object value = record.get(fieldPath).getValue();
        // Special cases for handling SDC Lists and Maps,
        // basically unpacking them into raw types.
        if (value instanceof List) {
            List<Object> unpackedList = new ArrayList<>();
            for (Field item : (List<Field>) value) {
                unpackedList.add(item.getValue());
            }
            values.add(unpackedList);
        } else if (value instanceof Map) {
            Map<Object, Object> unpackedMap = new HashMap<>();
            for (Map.Entry<String, Field> entry : ((Map<String, Field>) value).entrySet()) {
                unpackedMap.put(entry.getKey(), entry.getValue().getValue());
            }
            values.add(unpackedMap);
        } else {
            values.add(value);
        }
    }

    PreparedStatement stmt = statementCache.getUnchecked(columnsPresent);
    // .toArray required to pass in a list to a varargs method.
    Object[] valuesArray = values.build().toArray();
    BoundStatement boundStmt = null;
    try {
        boundStmt = stmt.bind(valuesArray);
    } catch (InvalidTypeException | NullPointerException e) {
        // NPE can occur if one of the values is a collection type with a null value inside it. Thus, it's a record
        // error. Note that this runs the risk of mistakenly treating a bug as a record error.
        errorRecordHandler.onError(new OnRecordErrorException(record, Errors.CASSANDRA_06,
                record.getHeader().getSourceId(), e.toString(), e));
    }
    return boundStmt;
}