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:net.sourceforge.fenixedu.presentationTier.Action.coordinator.thesis.ManageThesisDA.java

private void fillLastThesisInfo(final ThesisBean bean, final Student student, final Enrolment enrolment) {
    final SortedSet<Enrolment> dissertationEnrolments = student.getDissertationEnrolments(null);
    dissertationEnrolments.remove(enrolment);
    if (!dissertationEnrolments.isEmpty()) {
        final Thesis previous = findPreviousThesis(dissertationEnrolments);
        if (previous != null) {
            bean.setTitle(previous.getTitle());
            return;
        }/*www  . j a  v a 2  s . c  o m*/
    }
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java

@Transactional
@Override//from w ww.  j a  va2s. c  om
public AvailableSchedule removeFromSchedule(final IScheduleOwner owner,
        final Set<AvailableBlock> blocksToRemove) {
    // retrieve existing schedule
    AvailableSchedule stored = retrieve(owner);

    // expand it to minimum possible size
    SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(stored.getAvailableBlocks(), 1);
    // expand the argument to minimum possible size blocks
    SortedSet<AvailableBlock> blocksToRemoveExpanded = AvailableBlockBuilder.expand(blocksToRemove, 1);

    boolean modified = false;
    for (AvailableBlock toRemove : blocksToRemoveExpanded) {
        if (expanded.contains(toRemove)) {
            // remove the specified block
            boolean result = expanded.remove(toRemove);
            if (result && !modified) {
                modified = true;
            }
        }
    }

    if (modified) {
        replaceSchedule(owner, expanded);
    }
    // retrieve the new complete schedule and return
    return retrieve(owner);
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Removes all instances of {@code protocolInfo} from all the
 * {@link DeviceProtocolInfoSource} {@link Set}s, if it is present. Returns
 * {@code true} if any of the {@link DeviceProtocolInfoSource} {@link Set}s
 * contained the specified element (or equivalently, if any of the
 * {@link DeviceProtocolInfoSource} {@link Set}s changed as a result of the
 * call).//from   ww  w  . j ava2  s.  co  m
 *
 * @param protocolInfo element to be removed, if present.
 * @return {@code true} if an element was removed as a result of this call,
 *         {@code false} otherwise.
 */
public boolean remove(ProtocolInfo protocolInfo) {
    boolean result = false;
    setsLock.writeLock().lock();
    try {
        for (SortedSet<ProtocolInfo> set : protocolInfoSets.values()) {
            result |= set != null && set.remove(protocolInfo);
        }
        if (result) {
            updateImageProfiles();
        }
    } finally {
        setsLock.writeLock().unlock();
    }
    return result;
}

From source file:net.pms.dlna.protocolinfo.DeviceProtocolInfo.java

/**
 * Removes a given instance of {@link ProtocolInfo}, if it is present in the
 * {@link Set} for the given {@link DeviceProtocolInfoSource}. Returns
 * {@code true} if the {@link Set} for the given
 * {@link DeviceProtocolInfoSource} contained the specified element (or
 * equivalently, if the {@link Set} for the given
 * {@link DeviceProtocolInfoSource} changed as a result of the call).
 *
 * @param type the {@link DeviceProtocolInfoSource} type.
 * @param protocolInfo element to be removed, if present.
 * @return {@code true} if an element was removed from the {@link Set} for
 *         {@code type} as a result of this call, {@code false} otherwise.
 *///w w w.j  ava  2  s  . c o  m
public boolean remove(DeviceProtocolInfoSource<?> type, ProtocolInfo protocolInfo) {
    setsLock.writeLock().lock();
    try {
        SortedSet<ProtocolInfo> set = protocolInfoSets.get(type);
        if (set != null) {
            if (set.remove(protocolInfo)) {
                updateImageProfiles();
                return true;
            }
        }
        return false;
    } finally {
        setsLock.writeLock().unlock();
    }
}

From source file:com.espertech.esper.core.deploy.EPDeploymentAdminImpl.java

public synchronized DeploymentOrder getDeploymentOrder(Collection<Module> modules,
        DeploymentOrderOptions options) throws DeploymentOrderException {
    if (options == null) {
        options = new DeploymentOrderOptions();
    }//from w  w  w  . ja v a 2s  .  com
    String[] deployments = deploymentStateService.getDeployments();

    List<Module> proposedModules = new ArrayList<Module>();
    proposedModules.addAll(modules);

    Set<String> availableModuleNames = new HashSet<String>();
    for (Module proposedModule : proposedModules) {
        if (proposedModule.getName() != null) {
            availableModuleNames.add(proposedModule.getName());
        }
    }

    // Collect all uses-dependencies of existing modules
    Map<String, Set<String>> usesPerModuleName = new HashMap<String, Set<String>>();
    for (String deployment : deployments) {
        DeploymentInformation info = deploymentStateService.getDeployment(deployment);
        if (info == null) {
            continue;
        }
        if ((info.getModule().getName() == null) || (info.getModule().getUses() == null)) {
            continue;
        }
        Set<String> usesSet = usesPerModuleName.get(info.getModule().getName());
        if (usesSet == null) {
            usesSet = new HashSet<String>();
            usesPerModuleName.put(info.getModule().getName(), usesSet);
        }
        usesSet.addAll(info.getModule().getUses());
    }

    // Collect uses-dependencies of proposed modules
    for (Module proposedModule : proposedModules) {

        // check uses-dependency is available
        if (options.isCheckUses()) {
            if (proposedModule.getUses() != null) {
                for (String uses : proposedModule.getUses()) {
                    if (availableModuleNames.contains(uses)) {
                        continue;
                    }
                    if (isDeployed(uses)) {
                        continue;
                    }
                    String message = "Module-dependency not found";
                    if (proposedModule.getName() != null) {
                        message += " as declared by module '" + proposedModule.getName() + "'";
                    }
                    message += " for uses-declaration '" + uses + "'";
                    throw new DeploymentOrderException(message);
                }
            }
        }

        if ((proposedModule.getName() == null) || (proposedModule.getUses() == null)) {
            continue;
        }
        Set<String> usesSet = usesPerModuleName.get(proposedModule.getName());
        if (usesSet == null) {
            usesSet = new HashSet<String>();
            usesPerModuleName.put(proposedModule.getName(), usesSet);
        }
        usesSet.addAll(proposedModule.getUses());
    }

    Map<String, SortedSet<Integer>> proposedModuleNames = new HashMap<String, SortedSet<Integer>>();
    int count = 0;
    for (Module proposedModule : proposedModules) {
        SortedSet<Integer> moduleNumbers = proposedModuleNames.get(proposedModule.getName());
        if (moduleNumbers == null) {
            moduleNumbers = new TreeSet<Integer>();
            proposedModuleNames.put(proposedModule.getName(), moduleNumbers);
        }
        moduleNumbers.add(count);
        count++;
    }

    DependencyGraph graph = new DependencyGraph(proposedModules.size(), false);
    int fromModule = 0;
    for (Module proposedModule : proposedModules) {
        if ((proposedModule.getUses() == null) || (proposedModule.getUses().isEmpty())) {
            fromModule++;
            continue;
        }
        SortedSet<Integer> dependentModuleNumbers = new TreeSet<Integer>();
        for (String use : proposedModule.getUses()) {
            SortedSet<Integer> moduleNumbers = proposedModuleNames.get(use);
            if (moduleNumbers == null) {
                continue;
            }
            dependentModuleNumbers.addAll(moduleNumbers);
        }
        dependentModuleNumbers.remove(fromModule);
        graph.addDependency(fromModule, dependentModuleNumbers);
        fromModule++;
    }

    if (options.isCheckCircularDependency()) {
        Stack<Integer> circular = graph.getFirstCircularDependency();
        if (circular != null) {
            String message = "";
            String delimiter = "";
            for (int i : circular) {
                message += delimiter;
                message += "module '" + proposedModules.get(i).getName() + "'";
                delimiter = " uses (depends on) ";
            }
            throw new DeploymentOrderException(
                    "Circular dependency detected in module uses-relationships: " + message);
        }
    }

    List<Module> reverseDeployList = new ArrayList<Module>();
    Set<Integer> ignoreList = new HashSet<Integer>();
    while (ignoreList.size() < proposedModules.size()) {

        // seconardy sort according to the order of listing
        Set<Integer> rootNodes = new TreeSet<Integer>(new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return -1 * o1.compareTo(o2);
            }
        });
        rootNodes.addAll(graph.getRootNodes(ignoreList));

        if (rootNodes.isEmpty()) { // circular dependency could cause this
            for (int i = 0; i < proposedModules.size(); i++) {
                if (!ignoreList.contains(i)) {
                    rootNodes.add(i);
                    break;
                }
            }
        }

        for (Integer root : rootNodes) {
            ignoreList.add(root);
            reverseDeployList.add(proposedModules.get(root));
        }
    }

    Collections.reverse(reverseDeployList);
    return new DeploymentOrder(reverseDeployList);
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.coordinator.thesis.ManageThesisDA.java

private Thesis findPreviousThesis(final SortedSet<Enrolment> dissertationEnrolments) {
    if (dissertationEnrolments.isEmpty()) {
        return null;
    }//from w  ww  .  j a v a 2 s.c o m
    final Enrolment previous = dissertationEnrolments.last();
    if (previous != null) {
        if (!previous.getThesesSet().isEmpty()) {
            return previous.getThesis();
        } else {
            dissertationEnrolments.remove(previous);
            return findPreviousThesis(dissertationEnrolments);
        }
    }
    return null;
}

From source file:net.big_oh.algorithms.search.informed.astar.AStarSearch.java

public AStarSearchResult<SearchNodeType> doSearch(SearchNodeType startNode) {

    Duration searchDuration = new Duration();

    // create priority queue
    SortedSet<SearchNodeType> prioritySet = new TreeSet<SearchNodeType>(new Comparator<SearchNodeType>() {

        public int compare(SearchNodeType o1, SearchNodeType o2) {
            switch (searchType) {
            case MIN:
                return Double.compare(getF(o1), getF(o2));
            case MAX:
                return -1 * Double.compare(getF(o1), getF(o2));
            default:
                throw new RuntimeException("Unexpected search type: " + searchType);
            }//from   w  ww  .  j ava2s. co  m
        }

    });

    // enqueue the start node
    prioritySet.add(startNode);

    // declare tracking member variables
    int numSearchNodesGenerated = 0;
    int numSearchNodesConsidered = 0;
    int maxPossibleBranchingFactor = 1;

    // search for a goal state
    SearchNodeType goalNode = null;
    while (!prioritySet.isEmpty()) {

        // Remove the best candidate node from the queue
        SearchNodeType candidateSearchNode = prioritySet.first();
        prioritySet.remove(candidateSearchNode);
        numSearchNodesConsidered++;

        // get the next search node candidates
        Collection<SearchNodeType> nextSearchNodes = nextNodesGenerator.getNextSearchNodes(candidateSearchNode);

        // do some record keeping
        numSearchNodesGenerated += nextSearchNodes.size();
        maxPossibleBranchingFactor = Math.max(maxPossibleBranchingFactor, nextSearchNodes.size());

        if (candidateSearchNode.isGoalState()) {
            // sanity check
            assert (nextSearchNodes.isEmpty());

            // found an optimal solution
            goalNode = candidateSearchNode;
            break;
        } else {
            // enqueue all next search nodes
            Duration enqueueDuration = new Duration();

            prioritySet.addAll(nextSearchNodes);

            if (logger.isDebugEnabled()) {
                logger.debug("Enqueued " + nextSearchNodes.size() + " A* search nodes in "
                        + enqueueDuration.stop() + " milliseconds.");
            }
        }

    }

    // return the search results
    AStarSearchResult<SearchNodeType> results = new AStarSearchResult<SearchNodeType>(goalNode,
            numSearchNodesGenerated, calculateEffectiveBranchingFactor(goalNode.getNodeDepth(),
                    numSearchNodesConsidered, maxPossibleBranchingFactor));

    logger.debug("Completed an A* search in " + searchDuration.stop() + " milliseconds.");
    logger.debug("Number of nodes generated: " + results.getNumSearchNodesGenerated());
    logger.debug("Depth of goal node: " + results.getGoalNode().getNodeDepth());
    logger.debug("Effective branching factor: " + results.getEfectiveBranchingFactor());

    return results;

}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public YearMonthDay getNextPossibleLessonInstanceDate() {

    SortedSet<YearMonthDay> allLessonDates = getAllLessonDates();
    LessonInstance lastLessonInstance = getLastLessonInstance();

    if (lastLessonInstance != null) {
        YearMonthDay day = lastLessonInstance.getDay();
        SortedSet<YearMonthDay> nextLessonDates = allLessonDates.tailSet(day);
        nextLessonDates.remove(day);
        return nextLessonDates.isEmpty() ? null : nextLessonDates.first();
    }//w  w w .ja  v  a 2 s.c  o m

    return allLessonDates.isEmpty() ? null : allLessonDates.first();
}

From source file:com.amazonaws.services.kinesis.connectors.redshift.RedshiftManifestEmitter.java

/**
 * Selects the count of files that are already present in Amazon Redshift using a SQL Query in the
 * format: SELECT COUNT(*) FROM fileTable WHERE fileKeyColumn IN ('f1','f2',...);
 * /*ww w  .j ava2  s.c  o  m*/
 * @param records
 * @return Deduplicated list of files
 * @throws IOException
 */

private List<String> checkForExistingFiles(Connection conn, List<String> records) throws IOException {
    SortedSet<String> recordSet = new TreeSet<>(records);
    String files = getCollectionString(recordSet, "(", ",", ")");
    StringBuilder selectExisting = new StringBuilder();
    selectExisting.append("SELECT " + fileKeyColumn + " FROM ");
    selectExisting.append(fileTable);
    selectExisting.append(" WHERE ");
    selectExisting.append(fileKeyColumn);
    selectExisting.append(" IN ");
    selectExisting.append(files);
    selectExisting.append(";");
    Statement stmt = null;
    ResultSet resultSet = null;
    try {
        stmt = conn.createStatement();
        final String query = selectExisting.toString();
        resultSet = stmt.executeQuery(query);
        while (resultSet.next()) {
            String existingFile = resultSet.getString(1);
            LOG.info("File " + existingFile + " has already been copied. Leaving it out.");
            recordSet.remove(existingFile);
        }
        resultSet.close();
        stmt.close();
        return new ArrayList<String>(recordSet);
    } catch (SQLException e) {
        try {
            resultSet.close();
        } catch (Exception e1) {
        }
        try {
            stmt.close();
        } catch (Exception e1) {
        }
        throw new IOException(e);
    }
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

public YearMonthDay getNextPossibleSummaryDate() {

    YearMonthDay currentDate = new YearMonthDay();
    HourMinuteSecond now = new HourMinuteSecond();
    Summary lastSummary = getLastSummary();

    if (lastSummary != null) {

        SortedSet<YearMonthDay> datesEvenToday = getAllLessonDatesUntil(currentDate);
        SortedSet<YearMonthDay> possibleDates = datesEvenToday
                .tailSet(lastSummary.getSummaryDateYearMonthDay());

        possibleDates.remove(lastSummary.getSummaryDateYearMonthDay());
        if (!possibleDates.isEmpty()) {
            YearMonthDay nextPossibleDate = possibleDates.first();
            return isTimeValidToInsertSummary(now, nextPossibleDate) ? nextPossibleDate : null;
        }//from   ww  w. jav a  2 s  . co m

    } else {
        YearMonthDay nextPossibleDate = hasAnyLessonInstances() ? getFirstLessonInstance().getDay()
                : getLessonStartDay();
        return isTimeValidToInsertSummary(now, nextPossibleDate) ? nextPossibleDate : null;
    }

    return null;
}