Example usage for java.util Set remove

List of usage examples for java.util Set remove

Introduction

In this page you can find the example usage for java.util Set 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:ai.grakn.graql.internal.gremlin.GraqlTraversal.java

/**
 * Create a semi-optimal plan using a greedy approach to execute a single conjunction
 * @param query the conjunction query to find a traversal plan
 * @return a semi-optimal traversal plan to execute the given conjunction
 *///from w w w.  j a v  a2 s.c  o m
private static List<Fragment> semiOptimalConjunction(ConjunctionQuery query) {

    Set<EquivalentFragmentSet> fragmentSets = Sets.newHashSet(query.getEquivalentFragmentSets());
    Set<String> names = new HashSet<>();

    // This list is constructed over the course of the algorithm
    List<Fragment> fragments = new ArrayList<>();

    long numFragments = fragments(fragmentSets).count();
    long depth = 1;
    long numTraversalAttempts = numFragments;

    // Calculate the depth to descend in the tree, based on how many plans we want to evaluate
    while (numFragments > 0 && numTraversalAttempts < MAX_TRAVERSAL_ATTEMPTS) {
        depth += 1;
        numTraversalAttempts *= numFragments;
        numFragments -= 1;
    }

    double cost = 1;

    while (!fragmentSets.isEmpty()) {
        Pair<Double, List<Fragment>> pair = findPlan(fragmentSets, names, cost, depth);
        cost = pair.getValue0();
        List<Fragment> newFragments = Lists.reverse(pair.getValue1());

        if (newFragments.isEmpty()) {
            throw new RuntimeException(ErrorMessage.FAILED_TO_BUILD_TRAVERSAL.getMessage());
        }

        newFragments.forEach(fragment -> {
            fragmentSets.remove(fragment.getEquivalentFragmentSet());
            fragment.getVariableNames().forEach(names::add);
        });
        fragments.addAll(newFragments);
    }

    return fragments;
}

From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImpl.java

/**
 * {@inheritDoc}//w w  w  .j a va2  s .  c om
 */
@Override
public void removeTagForCommand(
        @NotBlank(message = "No command id entered. Unable to remove tag.") final String id,
        @NotBlank(message = "No tag entered. Unable to remove.") final String tag) throws GenieException {
    final CommandEntity command = this.findCommand(id);
    final Set<String> commandTags = command.getTags();
    commandTags.remove(tag);
    command.setTags(commandTags);
}

From source file:org.obp.nmea.NmeaDeviceFinder.java

private boolean listenAndValidate(String portName, Set<String> requiredMessages) throws Exception {
    try {/*from w  w  w  .j av  a2 s  .  com*/
        Set<String> remaining = new HashSet<>(requiredMessages);
        try (NmeaDevice device = NmeaDevice.createAndOpen(portName)) {
            if (device.isOpened()) {
                NmeaBufferedReader reader = device.getReader();
                for (int i = 0; i < MESSAGES_TO_READ; i++) {
                    NmeaLine line = reader.fetchLine();
                    if (line != null) {
                        remaining.remove(line.getName());
                        if (remaining.isEmpty()) {
                            logger.debug("all required messages found");
                            return true;
                        }
                    } else {
                        logger.debug("failed to read line");
                        return false;
                    }
                }
            }
        }
        logger.debug("following messages not found: " + remaining);
        return false;
    } catch (ZeroBytesReadException e) {
        logger.warn("failed to read from port " + portName);
        return false;
    } catch (Exception e) {
        logger.error("error auto-sensing port " + portName, e);
        return false;
    }
}

From source file:cz.strmik.cmmitool.web.controller.RatingController.java

private void addPAs(Project project, Method method, ModelMap modelMap) {
    List<ProcessAreaSatisfactionRating> pasrs = new ArrayList<ProcessAreaSatisfactionRating>();
    Set<ProcessArea> pas = new HashSet<ProcessArea>(project.getModel().getProcessAreas());
    // add rated PAs
    for (ProcessAreaSatisfactionRating pasr : project.getProcessAreaSatisfaction()) {
        pasrs.add(pasr);/*from   w w w  .  java  2s.  c  om*/
        pas.remove(pasr.getProcessArea());
    }
    // add unrated practices
    RatingScale defaultRating = ratingService.getDefaultRating(method.getProcessAreaSatisfaction());
    for (ProcessArea pa : pas) {
        ProcessAreaSatisfactionRating pir = new ProcessAreaSatisfactionRating();
        pir.setProcessArea(pa);
        pir.setRating(defaultRating);
    }
    modelMap.addAttribute("pas", pasrs);
}

From source file:net.cellar.hazelcast.HazelcastGroupManager.java

public void unRegisterGroup(Group group) {
    String groupName = group.getName();
    //1. Remove local node from group.
    group.getMembers().remove(getNode());
    listGroups().put(groupName, group);//from  w w  w. j  a v  a2s.co  m

    //2. Unregister group consumers
    if (consumerRegistrations != null && !consumerRegistrations.isEmpty()) {
        ServiceRegistration consumerRegistration = consumerRegistrations.get(groupName);
        if (consumerRegistration != null) {
            consumerRegistration.unregister();
            consumerRegistrations.remove(groupName);
        }

    }

    //3. Unregister group producers
    if (producerRegistrations != null && !producerRegistrations.isEmpty()) {
        ServiceRegistration producerRegistration = producerRegistrations.get(groupName);
        if (producerRegistration != null) {
            producerRegistration.unregister();
            producerRegistrations.remove(groupName);
        }
    }

    //Remove group from configuration
    try {
        Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE);
        Dictionary<String, String> properties = configuration.getProperties();
        String groups = properties.get(Configurations.GROUPS_KEY);
        if (groups == null || groups.isEmpty()) {
            groups = "";
        } else if (groups.contains(groupName)) {

            Set<String> groupNamesSet = convertStringToSet(groups);
            groupNamesSet.remove(groupName);
            groups = convertSetToString(groupNamesSet);

        }
        properties.put(Configurations.GROUPS_KEY, groups);
        configuration.update(properties);
    } catch (IOException e) {
        logger.error("Error reading group configuration {}", group);
    }
}

From source file:de.tuberlin.uebb.jdae.llmsl.ExecutableDAE.java

public int lastBlock(final Collection<GlobalVariable> vars) {
    final Set<GlobalVariable> left = Sets.newTreeSet(vars);
    left.removeAll(states);//  w  ww  .ja  v  a  2 s.c o  m

    int i = 0;
    while (!left.isEmpty() && i < blocks.length) {
        for (GlobalVariable gv : blocks[i].variables())
            left.remove(gv);
        i++;
    }

    if (!left.isEmpty())
        throw new RuntimeException("The following variables are not computed: " + left.toString());
    return i;
}

From source file:org.apache.taverna.gis.GisActivityFactoryTest.java

@Test
public void testGetOutputPorts() {
    Set<String> expectedOutputs = new HashSet<String>();
    expectedOutputs.add("simpleOutput");
    expectedOutputs.add("moreOutputs");

    Set<ActivityOutputPort> outputPorts = activityFactory.getOutputPorts(configuration);
    assertEquals("Unexpected outputs", expectedOutputs.size(), outputPorts.size());
    for (ActivityOutputPort outputPort : outputPorts) {
        assertTrue("Wrong output : " + outputPort.getName(), expectedOutputs.remove(outputPort.getName()));
    }/* ww w.  ja v a2 s. c  o m*/

    ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode();
    specialConfiguration.put("exampleString", "specialCase");
    specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint");

    assertEquals("Unexpected outputs", 3, activityFactory.getOutputPorts(specialConfiguration).size());
}

From source file:cz.strmik.cmmitool.web.controller.RatingController.java

private void addGoalsOfPA(Project project, Method method, ModelMap modelMap, ProcessArea pa) {
    List<GoalSatisfactionRating> gsrs = new ArrayList<GoalSatisfactionRating>();
    Set<Goal> goals = new HashSet<Goal>(pa.getGoals());
    // add rated goals
    for (GoalSatisfactionRating gsr : project.getGoalSatisfaction()) {
        if (goals.contains(gsr.getGoal())) {
            gsrs.add(gsr);//from ww  w. jav  a  2  s . c  om
            goals.remove(gsr.getGoal());
        }
    }
    // add unrated practices
    RatingScale defaultRating = ratingService.getDefaultRating(method.getGoalSatisfaction());
    for (Goal g : goals) {
        GoalSatisfactionRating pir = new GoalSatisfactionRating();
        pir.setGoal(g);
        pir.setRating(defaultRating);
    }
    modelMap.addAttribute("goals", gsrs);
}

From source file:gov.nih.nci.caarray.application.permissions.PermissionsManagementServiceBean.java

private void addUsersToGroup(Long groupId, List<Long> users, boolean allowAnonymousUser)
        throws CSObjectNotFoundException, CSTransactionException {
    final Set<User> curUsers = SecurityUtils.getUsers(groupId);
    final Set<Long> newUsers = new HashSet<Long>(curUsers.size() + users.size());
    newUsers.addAll(users);// ww w  . j a  v  a 2 s  .  co m
    for (final User u : curUsers) {
        newUsers.add(u.getUserId());
    }
    if (!allowAnonymousUser) {
        newUsers.remove(SecurityUtils.getAnonymousUser().getUserId());
    }

    SecurityUtils.assignUsersToGroup(groupId, newUsers);
}

From source file:com.diversityarrays.kdxplore.stats.StatsUtil.java

static public void initCheck() {
    if (checkDone) {
        return;/*w w  w . ja v  a 2s  . co  m*/
    }
    Set<String> okIfExhibitMissing = new HashSet<>();
    Collections.addAll(okIfExhibitMissing, "getFormat", "getValueClass", "getStatsName", "getLowOutliers",
            "getHighOutliers");
    List<String> errors = new ArrayList<String>();

    Set<String> unMatchedStatNameValues = new HashSet<String>();
    for (SimpleStatistics.StatName sname : StatName.values()) {
        unMatchedStatNameValues.add(sname.displayName);
    }

    for (Method m : SimpleStatistics.class.getDeclaredMethods()) {

        if (!Modifier.isPublic(m.getModifiers())) {
            continue; // shouldn't happen!
        }

        ExhibitColumn ec = m.getAnnotation(ExhibitColumn.class);

        if (ec == null) {
            if (okIfExhibitMissing.contains(m.getName())) {
                //               if ("getQuartiles".equals(m.getName())) {
                //                  System.err.println("%TODO: @ExhibitColumn for 'SimpleStatistics.getQuartiles()'");
                //               }
            } else {
                errors.add("Missing @ExhibitColumn: " + m.getName());
            }
        } else {
            String ecValue = ec.value();
            boolean found = false;
            for (SimpleStatistics.StatName sname : StatName.values()) {
                if (sname.displayName.equals(ecValue)) {
                    unMatchedStatNameValues.remove(sname.displayName);
                    METHOD_BY_STATNAME.put(sname, m);
                    found = true;
                    break;
                }
            }
            if (!found) {
                errors.add("Doesn't match any StatName: '" + ecValue + "', method=" + m.getName());
            }
        }
    }

    if (!unMatchedStatNameValues.isEmpty()) {
        errors.add(StringUtil.join("Unmatched StatName values: ", " ", unMatchedStatNameValues));
    }

    if (!errors.isEmpty()) {
        throw new RuntimeException(StringUtil.join("Problems in SimpleStatistics config: ", "\n", errors));
    }

    checkDone = true;
}