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:org.openmrs.module.metadatamapping.api.impl.MetadataMappingServiceImpl.java

@Transactional
@Override//from  w w  w.  j a  v  a2s . c  o m
public boolean removeSubscribedConceptSource(ConceptSource conceptSource) {
    Set<ConceptSource> subscribedConceptSources = new HashSet<ConceptSource>(getSubscribedConceptSources());
    if (!subscribedConceptSources.remove(conceptSource)) {
        return false;
    }

    updateSubscribedConceptSourcesGlobalProperty(subscribedConceptSources);

    return true;
}

From source file:org.obiba.onyx.core.service.impl.ConfigurablePasswordValidationStrategyImplTest.java

@Test
public void testCreateValidPasswordCharArray() {
    ((ConfigurablePasswordValidationStrategyImpl) passwordStrategy)
            .setAllowedCharacterGroups(new String[] { "A-C", "A-B", "F-H", "J-L", "0-2", "[[@!()]" });
    char[] allowedPasswordChars = ((ConfigurablePasswordValidationStrategyImpl) passwordStrategy)
            .createValidPasswordCharArray();
    char[] correct = { 'A', 'B', 'C', 'F', 'G', 'H', 'J', 'K', 'L', '0', '1', '2', '[', '@', '!', '(', ')' };
    Set<Character> correctSet = new HashSet<Character>(correct.length);
    for (char c : correct) {
        correctSet.add(c); // Populate Hash with correct chars.
    }/*from www. j  a v a2 s.  c  o  m*/
    for (char c : allowedPasswordChars) {
        correctSet.remove(c); // Remove chars from Hash contained in allowedPasswordChars.
    }
    Assert.assertTrue(correctSet.size() == 0); // The size of the Hash should be zero [0]. All chars accounted for.
}

From source file:com.autonomy.aci.client.transport.impl.AciHttpClientImpl.java

/**
 * Converts a list of {@code AciParameter} objects into an array of {@code NameValuePair} objects suitable for use
 * in both POST and GET methods./*  ww  w  . j  av a2 s.  c  o m*/
 * @param parameters  The set of parameters to convert.
 * @param charsetName The name of the charset to use when encoding the parameters
 * @return an <tt>String</tt> representing the query string portion of a URI
 */
private String convertParameters(final Set<? extends ActionParameter<?>> parameters, final String charsetName) {
    LOGGER.trace("convertParameters() called...");

    // Just incase, remove the allowed null entry...
    parameters.remove(null);

    final List<NameValuePair> pairs = new ArrayList<>(parameters.size());

    LOGGER.debug("Converting {} parameters...", parameters.size());

    NameValuePair actionPair = null;

    for (final ActionParameter<?> parameter : parameters) {
        final Object value = parameter.getValue();

        if (value instanceof String) {
            final String stringValue = (String) value;

            if (AciConstants.PARAM_ACTION.equalsIgnoreCase(parameter.getName())) {
                actionPair = new BasicNameValuePair(parameter.getName(), stringValue);
            } else {
                pairs.add(new BasicNameValuePair(parameter.getName(), stringValue));
            }
        }
    }

    // Ensure that the action=XXX parameter is the first thing in the list...
    Validate.isTrue(actionPair != null,
            "No action parameter found in parameter set, please set one before trying to execute an ACI request.");
    pairs.add(0, actionPair);

    // Convert to a string and return...
    return URLEncodedUtils.format(pairs, charsetName);
}

From source file:com.facebook.presto.accumulo.tools.TimestampCheckTask.java

private void getCountViaIndex(Connector connector, AccumuloTable table, AccumuloColumnHandle column,
        long timestamp, Set<Range> indexRanges, Set<ByteBuffer> indexRowIDs) throws Exception {
    LOG.info("Number of index ranges is " + indexRanges.size());

    // Scan table with these entries
    Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator();
    BatchScanner scanner = connector.createBatchScanner(table.getFullTableName(), auths, 10);
    scanner.setRanges(indexRanges);/*from www  .  ja v a  2 s. c om*/
    scanner.fetchColumn(new Text(column.getFamily().get()), new Text(column.getQualifier().get()));

    IteratorSetting iteratorSetting = new IteratorSetting(Integer.MAX_VALUE, TimestampFilter.class);
    TimestampFilter.setEnd(iteratorSetting, timestamp, true);
    scanner.addScanIterator(iteratorSetting);

    Set<ByteBuffer> values = new HashSet<>(indexRowIDs);

    Text text = new Text();
    long numRows = 0;
    long outsideRange = 0;
    for (Entry<Key, Value> entry : scanner) {
        values.remove(ByteBuffer.wrap(entry.getKey().getRow(text).copyBytes()));

        byte[] timestampValue = entry.getValue().get();
        if (comparator.compare(timestampValue, startBytes) >= 0
                && comparator.compare(timestampValue, endBytes) <= 0) {
            ++numRows;
        } else {
            ++outsideRange;
        }
    }
    scanner.close();

    LOG.info("Number of rows from data table via index is " + numRows);
    LOG.info("Number of rows from data table outside the time range is " + outsideRange);
    LOG.info("Number of rows in the index not scanned from the table is " + values.size());

    if (values.size() > 0) {
        LOG.info("Sample records:");
        values.stream().limit(10).forEach(x -> LOG.info(new String(x.array(), UTF_8)));
    }
}

From source file:net.sf.infrared.web.action.PerfDataSummaryAction.java

private void getAppNameToInstNameMapping(Set applicationNames, String[][] map) {
    Set appName = new HashSet();
    int i = 0;//from w  w w.  ja v  a  2 s.  co  m
    for (Iterator itr1 = applicationNames.iterator(); itr1.hasNext();) {
        int j = 0;
        String app = (String) itr1.next();
        appName.add(app);
        Set tempInstance = DataFetchUtil.getInstanceNames(appName);
        appName.remove(app);
        map[i] = new String[tempInstance.size()];
        for (Iterator itr2 = tempInstance.iterator(); itr2.hasNext();) {
            String instanceName = (String) itr2.next();
            map[i][j++] = instanceName;
        }
        i++;
    }
}

From source file:com.catify.processengine.core.nodes.eventdefinition.EventDefinitionFactory.java

/**
 * Gets all actor references of the process (including sub processes) 
 * but excluding the actor reference of a given flow node.
 *
 * @param clientId the client id//from  w  w  w.j a v a  2  s  .  c o m
 * @param processJaxb the process jaxb
 * @param subProcessesJaxb the sub processes jaxb
 * @param flowNodeJaxb the jaxb flow node to be excluded
 * @return the other actor references
 */
private Set<ActorRef> getTopLevelActorReferences(EventDefinitionParameter params) {
    Set<ActorRef> actorReferences = getTopLevelActorReferences(params.clientId, params.processJaxb);

    // remove actor reference of given flow node
    actorReferences
            .remove(new ActorReferenceService().getActorReference(IdService.getUniqueFlowNodeId(params)));

    return actorReferences;
}

From source file:org.duracloud.account.db.util.impl.DuracloudUserServiceImpl.java

private void removeUserFromAccountGroups(Long acctId, Long userId) {
    DuracloudUser user = repoMgr.getUserRepo().findOne(userId);
    DuracloudGroupRepo groupRepo = repoMgr.getGroupRepo();
    List<DuracloudGroup> acctGroups = groupRepo.findByAccountId(acctId);
    for (DuracloudGroup group : acctGroups) {
        Set<DuracloudUser> groupUsers = group.getUsers();
        if (groupUsers.contains(user)) {
            groupUsers.remove(user);
            groupRepo.save(group);//from ww  w  . ja va  2 s .c  om
        }
    }
}

From source file:com.basho.riak.client.http.request.MapReduceBuilder.java

/**
 * Removes a Riak object (bucket name/key pair) for the job's input list
 *//*  w  w w  .  j  a  v  a 2s  .  c o m*/
public void removeRiakObject(String bucket, String key) {
    Set<String> keys = objects.get(bucket);
    if (keys != null) {
        keys.remove(key);
        if (keys.size() == 0) {
            objects.remove(bucket);
        }
    }
}

From source file:me.ryanhamshire.griefprevention.permission.GPPermissionHandler.java

private static Tristate getUserPermission(User user, GPClaim claim, String permission,
        String targetModPermission, String targetMetaPermission, GPPlayerData playerData) {
    final List<Claim> inheritParents = claim.getInheritedParents();
    final Set<Context> contexts = new HashSet<>(PermissionUtils.getActiveContexts(user, playerData));

    for (Claim parentClaim : inheritParents) {
        GPClaim parent = (GPClaim) parentClaim;
        // check parent context
        contexts.add(parent.getContext());

        Tristate value = user.getPermissionValue(contexts, permission);
        if (value != Tristate.UNDEFINED) {
            return processResult(claim, permission, value, user);
        }//from w  w  w.  j a  va  2  s  . c o m
        if (targetModPermission != null) {
            value = user.getPermissionValue(contexts, targetModPermission);
            if (value != Tristate.UNDEFINED) {
                return processResult(claim, targetModPermission, value, user);
            }
        }

        contexts.remove(parent.getContext());
    }

    contexts.add(claim.getContext());
    Tristate value = user.getPermissionValue(contexts, permission);
    if (value != Tristate.UNDEFINED) {
        return processResult(claim, permission, value, user);
    }
    if (targetMetaPermission != null) {
        value = user.getPermissionValue(contexts, targetMetaPermission);
        if (value != Tristate.UNDEFINED) {
            return processResult(claim, targetMetaPermission, value, user);
        }
    }
    if (targetModPermission != null) {
        value = user.getPermissionValue(contexts, targetModPermission);
        if (value != Tristate.UNDEFINED) {
            return processResult(claim, targetModPermission, value, user);
        }
    }

    return getClaimFlagPermission(claim, permission, targetModPermission, targetMetaPermission);
}

From source file:edu.umd.cs.marmoset.utilities.MarmosetUtilities.java

public static <T> Map<T, Boolean> setAsMap(final Set<T> set) {
    return new Map<T, Boolean>() {

        @Override//from  w  w w  .  ja va2 s . c  om
        public void clear() {
            set.clear();

        }

        @Override
        public boolean containsKey(Object arg0) {
            return set.contains(arg0);
        }

        @Override
        public boolean containsValue(Object arg0) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Set<java.util.Map.Entry<T, Boolean>> entrySet() {
            throw new UnsupportedOperationException();
        }

        @Override
        public Boolean get(Object arg0) {
            return set.contains(arg0);
        }

        @Override
        public boolean isEmpty() {
            return set.isEmpty();
        }

        @Override
        public Set<T> keySet() {
            return set;
        }

        @Override
        public Boolean put(T arg0, Boolean arg1) {
            Boolean result = set.contains(arg0);
            if (arg1)
                set.add(arg0);
            else
                set.remove(arg0);
            return result;
        }

        @Override
        public void putAll(Map<? extends T, ? extends Boolean> arg0) {
            throw new UnsupportedOperationException();

        }

        @Override
        public Boolean remove(Object arg0) {
            Boolean result = set.contains(arg0);
            set.remove(arg0);
            return result;
        }

        @Override
        public int size() {
            return set.size();
        }

        @Override
        public Collection<Boolean> values() {
            throw new UnsupportedOperationException();
        }
    };
}