Example usage for java.util Set add

List of usage examples for java.util Set add

Introduction

In this page you can find the example usage for java.util Set add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:com.myGengo.alfresco.utils.MyGengoUtils.java

public static Set<NodeRef> getMyGengoJobs(NodeRef myGengoContainerRef, NodeService nodeService,
        boolean includeApproved) {
    Set<QName> myGengoType = new HashSet<QName>(1, 1.0f);
    myGengoType.add(MyGengoModel.TYPE_TRANSLATIONJOB);
    List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(myGengoContainerRef, myGengoType);
    Set<NodeRef> jobRefs = new HashSet<NodeRef>(childAssocs.size(), 1.0f);
    for (ChildAssociationRef childAssociationRef : childAssocs) {
        NodeRef nodeRef = childAssociationRef.getChildRef();
        if (!nodeService.hasAspect(nodeRef, MyGengoModel.ASPECT_APPROVED)) {
            jobRefs.add(nodeRef);//from  w  w  w.  j a  v a  2 s.c om
        } else {
            LOGGER.debug("Ingnoring approved translation job: " + nodeRef.toString());
        }
    }
    return jobRefs;
}

From source file:cooccurrence.Omer_Levy.java

/**
 * Method that will extract top D singular values from CoVariance Matrix 
 * It will then identify the corresponding columns from U and V and add it to new matrices 
 * @param U//from   w w w  .ja  va 2 s  . c o m
 * @param V
 * @param coVariance
 * @param matrixUd
 * @param matrixVd
 * @param coVarD
 * @param indicesD 
 */
private static void getTopD(RealMatrix U, RealMatrix V, RealMatrix coVariance, RealMatrix matrixUd,
        RealMatrix matrixVd, RealMatrix coVarD, ArrayList<Integer> indicesD) {
    TreeMap<Double, Set<Integer>> tmap = new TreeMap<>();
    for (int i = 0; i < coVariance.getRowDimension(); i++) {
        double val = coVariance.getEntry(i, i);
        if (tmap.containsKey(val)) {
            Set<Integer> temp = tmap.get(val);
            temp.add(i);
        } else {
            Set<Integer> temp = new HashSet<>();
            temp.add(i);
            tmap.put(val, temp);
        }
    }
    Iterator iter = tmap.keySet().iterator();
    while (iter.hasNext()) {
        Double val = (Double) iter.next();
        Set<Integer> indices = tmap.get(val);
        for (int i = 0; i < indices.size(); i++) {
            Iterator iterIndices = indices.iterator();
            while (iterIndices.hasNext()) {
                int index = (Integer) iterIndices.next();
                indicesD.add(index);
                coVarD.addToEntry(index, index, val);
                matrixUd.setColumnVector(index, U.getColumnVector(index));
                matrixVd.setColumnVector(index, V.getColumnVector(index));
            }
        }
    }

}

From source file:edu.msu.cme.rdp.readseq.utils.ResampleSeqFile.java

/**
 * random select (without replacement) a fraction of sequence IDs from the input file
 * @param infile//from   w ww.  jav  a  2 s.c om
 * @param fraction
 * @return 
 * @throws IOException
 */
public static Set<String> randomSelectSeq(File infile, float fraction) throws IOException {
    IndexedSeqReader reader = new IndexedSeqReader(infile);
    Object[] seqIdSet = reader.getSeqIdSet().toArray();
    int num_of_seqs = (int) (fraction * seqIdSet.length);
    HashSet<Integer> selectedIndexSet = randomSelectIndices(seqIdSet, num_of_seqs);
    Set<String> selectedSeqIDs = new HashSet<String>();
    for (int index : selectedIndexSet) {
        selectedSeqIDs.add((String) seqIdSet[index]);

    }
    return selectedSeqIDs;
}

From source file:Main.java

public static <K, V> Map<V, Set<K>> invertMapOfCollection(Map<K, ? extends Collection<V>> mapOfCollection) {
    Map<V, Set<K>> result = new TreeMap<V, Set<K>>();

    for (Entry<K, ? extends Collection<V>> inputEntry : mapOfCollection.entrySet()) {
        K inputKey = inputEntry.getKey();
        Collection<V> inputCollection = inputEntry.getValue();

        for (V inputValue : inputCollection) {
            Set<K> resultSet = result.get(inputValue);
            if (resultSet == null) {
                resultSet = new TreeSet<K>();
                result.put(inputValue, resultSet);
            }/*w w w .j  a v  a  2 s . c  o  m*/
            resultSet.add(inputKey);
        }
    }

    return result;
}

From source file:org.ahp.commons.validator.AbstractValidator.java

/**
 * //from w  ww.  j  a  v a 2s.  c  o  m
 * @param pEmailAddress
 * @param pErrorKeyPrefix
 * @return
 */
public static Set<String> validateEmailAddress(String pEmailAddress, String pErrorKeyPrefix) {
    Set<String> lErrorKeySet = new LinkedHashSet<String>();
    if (pEmailAddress == null || "".equals(pEmailAddress)) {
        lErrorKeySet.add(pErrorKeyPrefix + ".email.required");
        return lErrorKeySet;
    }
    /*if ( pEmailAddress.length() < EMAIL_ADDRESS_MIN_LENGTH ) {
    lErrorKeySet.add( pErrorKeyPrefix + ".email.min" ); 
    return lErrorKeySet;
    } 
    if ( pEmailAddress.length() > EMAIL_ADDRESS_MAX_LENGTH ) { 
    lErrorKeySet.add( pErrorKeyPrefix + ".email.max" ); 
    }*/
    if (!ValidatorUtil.validateAllowedCharacters(pEmailAddress, EMAIL_ADDRESS_ALLOWED_REGEX)) {
        lErrorKeySet.add(pErrorKeyPrefix + ".email.notvalid");
    }
    return lErrorKeySet;
}

From source file:org.hawkular.alerts.actions.sms.SmsPluginTest.java

@BeforeClass
public static void configurePlugin() {
    System.setProperty(SmsPlugin.ACCOUNT_SID_PROPERTY, "account");
    System.setProperty(SmsPlugin.AUTH_TOKEN_PROPERTY, "token");
    System.setProperty(SmsPlugin.FROM_PROPERTY, "+14158141829");

    Trigger trigger = new Trigger(TEST_TENANT, "trigger-test", "trigger-test");
    Alert alert = new Alert(TEST_TENANT, trigger, null);

    AvailabilityCondition aCond = new AvailabilityCondition(TEST_TENANT, "trigger-test", "Default",
            AvailabilityCondition.Operator.UP);
    Data aData = Data.forAvailability(TEST_TENANT, "Metric-test", 1, AvailabilityType.UP);
    AvailabilityConditionEval aEval = new AvailabilityConditionEval(aCond, aData);

    ThresholdCondition tCond = new ThresholdCondition(TEST_TENANT, "trigger-test", "Default",
            ThresholdCondition.Operator.LTE, 50.0);
    Data tData = Data.forNumeric(TEST_TENANT, "Metric-test2", 2, 25.5);
    ThresholdConditionEval tEval = new ThresholdConditionEval(tCond, tData);

    Set<ConditionEval> evals = new HashSet<>();
    evals.add(aEval);
    evals.add(tEval);//from w  w w .j  a va  2 s .  c om

    List<Set<ConditionEval>> list = new ArrayList<>();
    list.add(evals);

    alert.setEvalSets(list);

    preparedMessage = "Alert : " + alert.getTriggerId() + " at " + alert.getCtime() + " -- Severity: "
            + alert.getSeverity().toString();

    Action incomingAction = new Action(TEST_TENANT, "testPlugin", "testActionId", alert);

    phoneTo = "+14158141828";

    Map<String, String> properties = new HashMap<>();
    properties.put("phone", phoneTo);
    incomingAction.setProperties(properties);
    testMessage = new TestActionMessage(incomingAction);
}

From source file:com.newatlanta.appengine.nio.file.attribute.GaeFileAttributes.java

public static Set<String> supportedFileAttributeViews() {
    Set<String> viewSet = new HashSet<String>();
    viewSet.add(BASIC_VIEW);
    viewSet.add(GAE_VIEW);//  www.ja va 2 s  .  c  o  m
    return viewSet;
}

From source file:com.qwazr.QwazrConfiguration.java

private static Set<String> buildGroups(String groupString) {
    if (StringUtils.isEmpty(groupString))
        return null;
    String[] groups_array = StringUtils.split(groupString, ',');
    if (groups_array == null || groups_array.length == 0)
        return null;
    Set<String> groups = new HashSet<>();
    for (String group : groups_array)
        groups.add(group.trim());
    return groups;
}

From source file:edu.stanford.muse.lang.Languages.java

/** returns all languages for a bunch of text, based on the script used */
public static Set<String> getAllLanguages(String text) {
    // can make it more efficient by allowing p to point to multiple languages (e.g. Devanagari)
    Set<String> result = new LinkedHashSet<String>();
    for (LangInfo p : allPatterns) {
        if (p.pattern.matcher(text).matches())
            result.add(InternTable.intern(p.language.toLowerCase()));
    }//from   www.  j  av  a  2s  . co m
    result.add(InternTable.intern("english")); // always adding english, currently
    return result;
}

From source file:Main.java

static Set<Pattern> getFilterFromFile(String filename) {
    try {/*from   w  w  w .j a  va  2 s. c  om*/
        BufferedReader br = new BufferedReader(new FileReader(filename));
        Set<Pattern> filter = new HashSet<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.trim().equals("")) {
                continue;
            }
            filter.add(Pattern.compile(line.trim().toLowerCase()));
        }
        return filter;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}