Java Code Examples for java.util.HashSet#retainAll()

The following examples show how to use java.util.HashSet#retainAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: eQtlsInRepeatData.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public HashSet<String> getSharedProbes(String eQtlProbeFile, String permutationDataLocation)throws IOException{
	HashSet<String> eqtlProbes = makeProbesList(eQtlProbeFile);
	HashSet<String> permutationProbes = new HashSet<String>();
	for(int n=1;n<=100;n++){
		HashSet<String> tmpProbes = makeProbesList(permutationDataLocation + "PermutedEQTLsPermutationRound" + n + ".txt.gz");
		if(n > 1){
			permutationProbes.retainAll(tmpProbes);
		}
		else{
			permutationProbes = tmpProbes;
		}
	}
	
	if(eqtlProbes.size() > permutationProbes.size()){
		eqtlProbes.retainAll(permutationProbes);
		return eqtlProbes;
	}
	else{
		permutationProbes.retainAll(eqtlProbes);
		return permutationProbes;
	}
}
 
Example 2
Source File: DissolveJointTransformationCommand.java    From workcraft with MIT License 6 votes vote down vote up
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> joints = new HashSet<>();
    if (model instanceof VisualCircuit) {
        VisualCircuit circuit = (VisualCircuit) model;
        joints.addAll(Hierarchy.getDescendantsOfType(circuit.getRoot(), VisualJoint.class));
        Collection<VisualNode> selection = circuit.getSelection();
        if (!selection.isEmpty()) {
            HashSet<VisualNode> selectedJoints = new HashSet<>(selection);
            selectedJoints.retainAll(joints);
            if (!selectedJoints.isEmpty()) {
                joints.retainAll(selection);
            }
        }
    }
    return joints;
}
 
Example 3
Source File: FastClasspathScanner.java    From uavstack with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the names of classes on the classpath that have all of the specified annotations. Should be called after
 * scan(), and returns matching classes whether or not a ClassAnnotationMatchProcessor was added to the scanner
 * before the call to scan(). Does not call the classloader on the matching classes, just returns their names.
 * 
 * @param annotationNames
 *            The annotation names.
 * @return A list of the names of classes that have all of the annotations, or the empty list if none.
 */
public List<String> getNamesOfClassesWithAnnotationsAllOf(final String... annotationNames) {

    HashSet<String> classNames = new HashSet<String>();
    for (int i = 0; i < annotationNames.length; i++) {
        String annotationName = annotationNames[i];
        List<String> namesOfClassesWithMetaAnnotation = getNamesOfClassesWithAnnotation(annotationName);
        if (i == 0) {
            classNames.addAll(namesOfClassesWithMetaAnnotation);
        }
        else {
            classNames.retainAll(namesOfClassesWithMetaAnnotation);
        }
    }
    return new ArrayList<String>(classNames);
}
 
Example 4
Source File: eQtlsInEncodeAnnotationData.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public HashSet<String> getSharedProbes(String eQtlProbeFile, String permutationDataLocation)throws IOException{
	HashSet<String> eqtlProbes = makeProbesList(eQtlProbeFile);
	HashSet<String> permutationProbes = new HashSet<String>();
	for(int n=1;n<=100;n++){
		HashSet<String> tmpProbes = makeProbesList(permutationDataLocation + "PermutedEQTLsPermutationRound" + n + ".txt.gz");
		if(n > 1){
			permutationProbes.retainAll(tmpProbes);
		}
		else{
			permutationProbes = tmpProbes;
		}
	}
	
	if(eqtlProbes.size() > permutationProbes.size()){
		eqtlProbes.retainAll(permutationProbes);
		return eqtlProbes;
	}
	else{
		permutationProbes.retainAll(eqtlProbes);
		return permutationProbes;
	}
}
 
Example 5
Source File: ConflictGenerator.java    From modeldb with Apache License 2.0 6 votes vote down vote up
private static List<AutogenS3DatasetComponentDiff> getS3DatasetConflictBlob(
    List<AutogenS3DatasetComponentDiff> a,
    List<AutogenS3DatasetComponentDiff> b,
    List<AutogenS3DatasetComponentBlob> c) {
  Map<String, AutogenS3DatasetComponentBlob> mapA = getS3DiffMap(a);
  Map<String, AutogenS3DatasetComponentBlob> mapB = getS3DiffMap(b);
  Map<String, AutogenS3DatasetComponentBlob> mapC = getS3Map(c);
  HashSet<String> keys = new HashSet<>();

  keys.addAll(mapA.keySet());
  if (keys.isEmpty()) keys.addAll(mapB.keySet());
  else if (!mapB.keySet().isEmpty()) keys.retainAll(mapB.keySet());
  List<AutogenS3DatasetComponentDiff> retList = new LinkedList<AutogenS3DatasetComponentDiff>();
  for (String key : keys) {
    if (!mapA.containsKey(key) || !mapA.get(key).equals(mapB.get(key))) {
      retList.add(
          Utils.removeEmpty(
              new AutogenS3DatasetComponentDiff()
                  .setA(mapA.get(key))
                  .setB(mapB.get(key))
                  .setC(mapC.get(key))
                  .setStatus(AutogenDiffStatusEnumDiffStatus.fromProto(DiffStatus.CONFLICTED))));
    }
  }
  return retList;
}
 
Example 6
Source File: BasePolygonBuilder.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * Validates only 1 vertex is tangential (shared) between the interior and exterior of a polygon
 */
protected void validateHole(BaseLineStringBuilder shell, BaseLineStringBuilder hole) {
    HashSet exterior = Sets.newHashSet(shell.points);
    HashSet interior = Sets.newHashSet(hole.points);
    exterior.retainAll(interior);
    if (exterior.size() >= 2) {
        throw new InvalidShapeException("Invalid polygon, interior cannot share more than one point with the exterior");
    }
}
 
Example 7
Source File: DatasetUtil.java    From BPR with Apache License 2.0 5 votes vote down vote up
/**
 * Find features from the review.
 * @param features
 * @param review
 * @return
 */
private static HashSet<String> findFeaturesFromReview(HashSet<String> features, String review) {
	// A feature may contain at most 3 words.
	HashSet<String> grams = new HashSet<String>();
	grams.addAll(CommonUtils.StringToGramSet(review, 1));
	grams.addAll(CommonUtils.StringToGramSet(review, 2));
	grams.addAll(CommonUtils.StringToGramSet(review, 3));
	
	grams.retainAll(features);
	return grams;
}
 
Example 8
Source File: ContractJointTransformationCommand.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public Collection<VisualNode> collect(VisualModel model) {
    Collection<VisualNode> joints = new HashSet<>();
    joints.addAll(Hierarchy.getDescendantsOfType(model.getRoot(), VisualJoint.class));
    Collection<VisualNode> selection = model.getSelection();
    if (!selection.isEmpty()) {
        HashSet<VisualNode> selectedConnections = new HashSet<>(selection);
        selectedConnections.retainAll(joints);
        if (!selectedConnections.isEmpty()) {
            joints.retainAll(selection);
        }
    }
    return joints;
}
 
Example 9
Source File: ExtractClassCandidateGroup.java    From JDeodorant with MIT License 5 votes vote down vote up
public void groupConcepts() {
	ArrayList<ExtractClassCandidateRefactoring> tempCandidates = new ArrayList<ExtractClassCandidateRefactoring>(candidates);
	Collections.sort(tempCandidates, new ClusterSizeComparator());
	while (!tempCandidates.isEmpty()) {
		Set<Entity> conceptEntities = new HashSet<Entity>(tempCandidates.get(0).getExtractedEntities());
		Set<Integer> indexSet = new LinkedHashSet<Integer>();
		indexSet.add(0);
		int previousSize = 0;
		do {
			previousSize = conceptEntities.size();
			for (int i = 1; i < tempCandidates.size(); i++) {
				HashSet<Entity> copiedConceptEntities = new HashSet<Entity>(conceptEntities);
				copiedConceptEntities.retainAll(tempCandidates.get(i).getExtractedEntities());
				if (!copiedConceptEntities.isEmpty()) {
					conceptEntities.addAll(tempCandidates.get(i).getExtractedEntities());
					indexSet.add(i);
				}
			}
		} while (previousSize < conceptEntities.size());
		Set<ExtractClassCandidateRefactoring> candidatesToBeRemoved = new HashSet<ExtractClassCandidateRefactoring>();
		ExtractedConcept newConcept = new ExtractedConcept(conceptEntities, source);
		for (Integer j : indexSet) {
			newConcept.addConceptCluster(tempCandidates.get(j));
			candidatesToBeRemoved.add(tempCandidates.get(j));
		}
		tempCandidates.removeAll(candidatesToBeRemoved);
		extractedConcepts.add(newConcept);
	}
	findConceptTerms();
}
 
Example 10
Source File: ControlFlowGraph.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void splitJsrExceptionRanges(Set<BasicBlock> common_blocks, Map<Integer, BasicBlock> mapNewNodes) {

        for (int i = exceptions.size() - 1; i >= 0; i--) {

            ExceptionRangeCFG range = exceptions.get(i);
            List<BasicBlock> lstRange = range.getProtectedRange();

            HashSet<BasicBlock> setBoth = new HashSet<>(common_blocks);
            setBoth.retainAll(lstRange);

            if (setBoth.size() > 0) {
                List<BasicBlock> lstNewRange;

                if (setBoth.size() == lstRange.size()) {
                    lstNewRange = new ArrayList<>();
                    ExceptionRangeCFG newRange = new ExceptionRangeCFG(lstNewRange,
                            mapNewNodes.get(range.getHandler().id), range.getExceptionTypes());
                    exceptions.add(newRange);
                } else {
                    lstNewRange = lstRange;
                }

                for (BasicBlock block : setBoth) {
                    lstNewRange.add(mapNewNodes.get(block.id));
                }
            }
        }
    }
 
Example 11
Source File: ServiceByHcPartyTagCodeDateFilter.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Set<String> resolve(org.taktik.icure.dto.filter.service.ServiceByHcPartyTagCodeDateFilter filter, Filters context) {
	try {
           String hcPartyId = filter.getHealthcarePartyId() != null ? filter.getHealthcarePartyId() : getLoggedHealthCarePartyId();
           HashSet<String> ids = null;

           String patientSFK = filter.getPatientSecretForeignKey();
           List<String> patientSFKList = patientSFK != null ? Arrays.asList(patientSFK) : null;

           if (filter.getTagType() != null && filter.getTagCode() != null) {
               ids = new HashSet<>(contactLogic.listServiceIdsByTag(
                       hcPartyId,
                       patientSFKList, filter.getTagType(),
                       filter.getTagCode(), filter.getStartValueDate(), filter.getEndValueDate()
               ));
           }

           if (filter.getCodeType() != null && filter.getCodeCode() != null) {
               List<String> byCode = contactLogic.listServiceIdsByCode(
                       hcPartyId,
                       patientSFKList, filter.getCodeType(),
                       filter.getCodeCode(), filter.getStartValueDate(), filter.getEndValueDate()
               );
               if (ids==null) { ids = new HashSet<>(byCode); } else { ids.retainAll(byCode); }
           }

           return ids != null ? ids : new HashSet<>();
	} catch (LoginException e) {
		throw new IllegalArgumentException(e);
	}
}
 
Example 12
Source File: Corpus.java    From AMC with Apache License 2.0 5 votes vote down vote up
/**
 * Get the co-document frequency which is the number of documents that both
 * words appear.
 */
public int getCoDocumentFrequency(String wordstr1, String wordstr2) {
	if (!wordstrToSetOfDocsMap.containsKey(wordstr1)
			|| !wordstrToSetOfDocsMap.containsKey(wordstr2)) {
		return 0;
	}
	HashSet<Integer> setOfDocs1 = wordstrToSetOfDocsMap.get(wordstr1);
	HashSet<Integer> setOfDocs2 = wordstrToSetOfDocsMap.get(wordstr2);
	HashSet<Integer> intersection = new HashSet<Integer>(setOfDocs1);
	intersection.retainAll(setOfDocs2);
	return intersection.size();
}
 
Example 13
Source File: ControlFlowGraph.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
private void splitJsrExceptionRanges(Set<BasicBlock> common_blocks, Map<Integer, BasicBlock> mapNewNodes) {

    for (int i = exceptions.size() - 1; i >= 0; i--) {

      ExceptionRangeCFG range = exceptions.get(i);
      List<BasicBlock> lstRange = range.getProtectedRange();

      HashSet<BasicBlock> setBoth = new HashSet<>(common_blocks);
      setBoth.retainAll(lstRange);

      if (setBoth.size() > 0) {
        List<BasicBlock> lstNewRange;

        if (setBoth.size() == lstRange.size()) {
          lstNewRange = new ArrayList<>();
          ExceptionRangeCFG newRange = new ExceptionRangeCFG(lstNewRange, mapNewNodes.get(range.getHandler().id), range.getExceptionTypes());
          exceptions.add(newRange);
        } else {
          lstNewRange = lstRange;
        }

        for (BasicBlock block : setBoth) {
          lstNewRange.add(mapNewNodes.get(block.id));
        }
      }
    }
  }
 
Example 14
Source File: MergeDoubleMatrices.java    From systemsgenetics with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Merge a matrix based on shared column identifiers.
 *
 * @param matrixI
 * @param matrixII
 * @param removeOldMatrix
 * @return
 */
public static DoubleMatrixDataset<String, String> mergeMatrixBasedOnColumns(DoubleMatrixDataset<String, String> matrixI, DoubleMatrixDataset<String, String> matrixII, boolean removeOldMatrix) throws Exception {
    HashSet<String> keepColNames1 = new HashSet<String>();
    keepColNames1.addAll(matrixI.getColObjects());
    HashSet<String> keepColNames2 = new HashSet<String>();
    keepColNames2.addAll(matrixII.getColObjects());
    keepColNames1.retainAll(keepColNames2);

    if (keepColNames1.size() != matrixI.rows() && keepColNames1.size() != matrixI.rows()) {
        if (keepColNames1.size() != matrixI.rows()) {
            matrixI = MatrixHandling.CreatSubsetBasedOnColumns(matrixI, keepColNames1, false);
        }
        if (keepColNames1.size() != matrixII.rows()) {
            matrixII = MatrixHandling.CreatSubsetBasedOnColumns(matrixII, keepColNames1, false);
        }
    }

    if (matrixI.columns() == 0 || matrixII.columns() == 0) {
        System.out.println("Warning indivduals merging. No shared columns");
        throw new Exception("Warning invalid merging. No shared columns");
    } else if (matrixI.columns() != matrixII.columns()) {
        System.out.println("Warning indivduals merging. No equal number of columns");
        throw new Exception("Warning indivduals merging. No equal number of columns");
    }

    matrixI.orderOnColumnnames();
    matrixII.orderOnColumnnames();

    HashSet<String> keepRowNames1 = new HashSet<String>();
    keepRowNames1.addAll(matrixI.getRowObjects());
    keepRowNames1.addAll(matrixII.getRowObjects());

    HashSet<String> removeList = new HashSet<String>();

    for (String key : keepRowNames1) {
        boolean presentMapI = matrixI.hashRows.containsKey(key);
        boolean presentMapII = matrixII.hashRows.containsKey(key);
        if (!presentMapI ^ presentMapII) {
            removeList.add(key);
        }
    }

    if (removeList.size() > 0) {
        matrixI = MatrixHandling.CreatSubsetBasedOnRows(matrixI, removeList, true);
        matrixII = MatrixHandling.CreatSubsetBasedOnRows(matrixII, removeList, true);
    }

    keepRowNames1 = null;
    removeList = null;

    DoubleMatrix2D matrix;
    if (((matrixI.rows() + matrixII.rows()) * (long)matrixI.columns()) < (Integer.MAX_VALUE - 2)) {
        matrix = new DenseDoubleMatrix2D((matrixI.rows() + matrixII.rows()), (matrixI.columns()));
    } else {
        matrix = new DenseLargeDoubleMatrix2D((matrixI.rows() + matrixII.rows()), (matrixI.columns()));
    }

    LinkedHashMap<String, Integer> newRowMap = new LinkedHashMap<String, Integer>((matrixI.rows() + matrixII.rows()));

    int tmpPos = 0;

    for (int r = 0; r < matrixI.rows(); ++r) {
        newRowMap.put(matrixI.getRowObjects().get(r), r);
        for (int s = 0; s < matrixI.columns(); ++s) {
            matrix.setQuick(r, s, matrixI.getMatrix().getQuick(r, s));
        }
        tmpPos++;
    }
    for (int r = 0; r < matrixII.rows(); ++r) {
        newRowMap.put(matrixII.getRowObjects().get(r), r + tmpPos);
        for (int s = 0; s < matrixII.columns(); ++s) {
            matrix.setQuick((r + tmpPos), s, matrixII.getMatrix().getQuick(r, s));
        }
    }

    return new DoubleMatrixDataset<String, String>(matrix, newRowMap, matrixI.getHashCols());
}
 
Example 15
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test extended and built in formats.
 */
@Test
public void testExtendedAndBuiltInFormats() {
    final Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
    final Object[] args = new Object[] {"John Doe", cal.getTime(), Double.valueOf("12345.67")};
    final String builtinsPattern = "DOB: {1,date,short} Salary: {2,number,currency}";
    final String extendedPattern = "Name: {0,upper} ";
    final String pattern = extendedPattern + builtinsPattern;

    final HashSet<Locale> testLocales = new HashSet<Locale>();
    testLocales.addAll(Arrays.asList(DateFormat.getAvailableLocales()));
    testLocales.retainAll(Arrays.asList(NumberFormat.getAvailableLocales()));
    testLocales.add(null);

    for (final Locale locale : testLocales) {
        final MessageFormat builtins = createMessageFormat(builtinsPattern, locale);
        final String expectedPattern = extendedPattern + builtins.toPattern();
        DateFormat df = null;
        NumberFormat nf = null;
        ExtendedMessageFormat emf = null;
        if (locale == null) {
            df = DateFormat.getDateInstance(DateFormat.SHORT);
            nf = NumberFormat.getCurrencyInstance();
            emf = new ExtendedMessageFormat(pattern, registry);
        } else {
            df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
            nf = NumberFormat.getCurrencyInstance(locale);
            emf = new ExtendedMessageFormat(pattern, locale, registry);
        }
        final StringBuilder expected = new StringBuilder();
        expected.append("Name: ");
        expected.append(args[0].toString().toUpperCase());
        expected.append(" DOB: ");
        expected.append(df.format(args[1]));
        expected.append(" Salary: ");
        expected.append(nf.format(args[2]));
        assertPatternsEqual("pattern comparison for locale " + locale, expectedPattern, emf.toPattern());
        assertEquals(String.valueOf(locale), expected.toString(), emf.format(args));
    }
}
 
Example 16
Source File: BooleanLogicTreeNode.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
public HashSet<Key> getIntersection(HashSet<Key> h) {
    h.retainAll(uids);
    return h;
}
 
Example 17
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test extended and built in formats.
 */
public void testExtendedAndBuiltInFormats() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
    Object[] args = new Object[] {"John Doe", cal.getTime(), new Double("12345.67")};
    String builtinsPattern = "DOB: {1,date,short} Salary: {2,number,currency}";
    String extendedPattern = "Name: {0,upper} ";
    String pattern = extendedPattern + builtinsPattern;

    HashSet<Locale> testLocales = new HashSet<Locale>();
    testLocales.addAll(Arrays.asList(DateFormat.getAvailableLocales()));
    testLocales.retainAll(Arrays.asList(NumberFormat.getAvailableLocales()));
    testLocales.add(null);

    for (Iterator<Locale> l = testLocales.iterator(); l.hasNext();) {
        Locale locale = l.next();
        MessageFormat builtins = createMessageFormat(builtinsPattern, locale);
        String expectedPattern = extendedPattern + builtins.toPattern();
        DateFormat df = null;
        NumberFormat nf = null;
        ExtendedMessageFormat emf = null;
        if (locale == null) {
            df = DateFormat.getDateInstance(DateFormat.SHORT);
            nf = NumberFormat.getCurrencyInstance();
            emf = new ExtendedMessageFormat(pattern, registry);
        } else {
            df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
            nf = NumberFormat.getCurrencyInstance(locale);
            emf = new ExtendedMessageFormat(pattern, locale, registry);
        }
        StringBuffer expected = new StringBuffer();
        expected.append("Name: ");
        expected.append(args[0].toString().toUpperCase());
        expected.append(" DOB: ");
        expected.append(df.format(args[1]));
        expected.append(" Salary: ");
        expected.append(nf.format(args[2]));
        assertPatternsEqual("pattern comparison for locale " + locale, expectedPattern, emf.toPattern());
        assertEquals(String.valueOf(locale), expected.toString(), emf.format(args));
    }
}
 
Example 18
Source File: BaseChoiceSetManager.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
HashSet<ChoiceCell> choicesToBeDeletedWithArray(List<ChoiceCell> choices){
    HashSet<ChoiceCell> choicesSet = new HashSet<>(choices);
    choicesSet.retainAll(this.preloadedChoices);
    return choicesSet;
}
 
Example 19
Source File: CoordinationMetaData.java    From crate with Apache License 2.0 4 votes vote down vote up
public boolean hasQuorum(Collection<String> votes) {
    final HashSet<String> intersection = new HashSet<>(nodeIds);
    intersection.retainAll(votes);
    return intersection.size() * 2 > nodeIds.size();
}
 
Example 20
Source File: BaseChoiceSetManager.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
HashSet<ChoiceCell> choicesToBeRemovedFromPendingWithArray(List<ChoiceCell> choices){
    HashSet<ChoiceCell> choicesSet = new HashSet<>(choices);
    choicesSet.retainAll(this.pendingPreloadChoices);
    return choicesSet;
}