Java Code Examples for java.util.HashSet

The following are top voted examples for showing how to use java.util.HashSet. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: SAPManagerPack   File: InstructionComparator.java View source code Vote up 7 votes
private static InsnListSection insnListMatchesL(InsnList haystack, InsnList needle, int start,
                                                HashSet<LabelNode> controlFlowLabels) {
    int h = start, n = 0;

    for(; h < haystack.size() && n < needle.size(); h++ ) {
        AbstractInsnNode insn = haystack.get(h);

        if( insn.getType() == 15 ) {
            continue;
        }
        if( insn.getType() == 8 && !controlFlowLabels.contains(insn) ) {
            continue;
        }
        if( !insnEqual(haystack.get(h), needle.get(n)) ) {
            return null;
        }
        n++;
    }
    if( n != needle.size() ) {
        return null;
    }

    return new InsnListSection(haystack, start, h - 1);
}
 
Example 2
Project: iswc2012metadata   File: AbstractPropertyValuesMap.java View source code Vote up 7 votes
public Set<V> getValues(){
	HashSet<V> ret = new HashSet<V>();
	for (P p: keySet()){
		ret.addAll(getValues(p));
	}
	return ret;
}
 
Example 3
Project: SimpleAlgebra_V2   File: Sampling.java View source code Vote up 7 votes
/**
 * Calculates the mean of a set of positions.
 * 
 * @param y The set of positions from which to calculate the mean.
 * @return The calculated mean.
 */
public R mean( GeometricAlgebraMultivectorElem<U,A,R,S> y )
{
	R sum = y.getFac().getFac().zero();
	final Iterator<HashSet<BigInteger>> it = y.getKeyIterator();
	while( it.hasNext() )
	{
		final HashSet<BigInteger> key = it.next();
		if( key.size() != 1 )
		{
			throw( new RuntimeException( "Inconsistent" ) );
		}
		sum = sum.add( y.get(key ) );
	}
	final U dim = y.getFac().getDim();
	final BigInteger ndim = dim.getVal();
	sum = sum.divideBy( ndim );
	return( sum );
}
 
Example 4
Project: aws-toolkit-eclipse   File: FunctionJarExportHelper.java View source code Vote up 6 votes
/**
 * @param classpathEntries the path to the package fragment roots
 * @param projectName the root of the project dependency tree
 * @return all package fragment roots corresponding to each classpath entry start the search at project with projectName
 */
private static IPackageFragmentRoot[] getRequiredPackageFragmentRoots(IPath[] classpathEntries, final String projectName) {
    HashSet<IPackageFragmentRoot> result= new HashSet<IPackageFragmentRoot>();

    IJavaProject[] searchOrder= getProjectSearchOrder(projectName);

    for (int i= 0; i < classpathEntries.length; i++) {
        IPath entry= classpathEntries[i];
        IPackageFragmentRoot[] elements= findRootsForClasspath(entry, searchOrder);
        if (elements != null) {
            for (int j= 0; j < elements.length; j++) {
                result.add(elements[j]);
            }
        }
    }

    return result.toArray(new IPackageFragmentRoot[result.size()]);
}
 
Example 5
Project: lucene-addons   File: TestComplexPhraseQuery.java View source code Vote up 6 votes
protected void checkMatches(String qString, String expectedVals)
    throws Exception {
  Query q = getQuery(qString);

  HashSet<String> expecteds = new HashSet<String>();
  String[] vals = expectedVals.split(",");
  for (int i = 0; i < vals.length; i++) {
    if (vals[i].length() > 0)
      expecteds.add(vals[i]);
  }

  TopDocs td = searcher.search(q, 10);
  ScoreDoc[] sd = td.scoreDocs;
  for (int i = 0; i < sd.length; i++) {
    StoredDocument doc = searcher.doc(sd[i].doc);
    String id = doc.get("id");
    assertTrue(qString + "matched doc#" + id + " not expected", expecteds
        .contains(id));
    expecteds.remove(id);
  }

  assertEquals(qString + " missing some matches ", 0, expecteds.size());

}
 
Example 6
Project: SimpleAlgebra_V2   File: SymbolicAdd.java View source code Vote up 6 votes
/**
 * Simplifies the elem, where two elems in the underlying negation true are known to be negations of each other.
 * 
 * @param elA An elem in the addition tree under this elem.
 * @param elB An elem in the addition tree under this elem which is the negation of elA.
 * @param ds The Drools ( http://drools.org ) session in which to simplify the addition.
 * @return The simplified expression, with elA and elB replaced by zero.
 */
public SymbolicElem<R, S> handleAddSimplify( SymbolicElem<R, S> elA , SymbolicElem<R, S> elB , DroolsSession ds )
{
	HashSet<SymbolicElem<R, S>> elS = new HashSet<SymbolicElem<R, S>>();
	elS.add( elA );
	elS.add( elB );
	SymbolicElem<R, S> ret = this.handleAddSimplify( elS , ds );
	if( !( elS.isEmpty() ) )
	{
		throw( new RuntimeException( "Internal Error." ) );
	}
	return( ret );
}
 
Example 7
Project: AIDR   File: WordSet.java View source code Vote up 6 votes
public double getSimilarity(WordSet other) {
    int l1 = words.size();
    int l2 = other.words.size();
    
    // intersection of two sets
    HashSet<String> intersection = (HashSet<String>) (l1 < l2 ? words.clone() : other.words.clone());
    intersection.retainAll(l1 < l2 ? other.words : words);
    int l3 = intersection.size();
    
    // similarity using Jaccard coefficient
    return l3 / (double) (l1 + l2 -l3);
}
 
Example 8
Project: richfaces   File: JsonTest.java View source code Vote up 6 votes
public void testMapAddiition() throws Exception {
    JSONMap map = new JSONMap();
    Set set = map.entrySet();

    set.add(new JsonTestMockMapEntry("boolean", new Boolean(true)));
    set.add(new JsonTestMockMapEntry("double", new Double(23.45)));
    set.add(new JsonTestMockMapEntry("integer", new Integer(56)));
    set.add(new JsonTestMockMapEntry("long", new Long(89)));
    set.add(new JsonTestMockMapEntry("string", "testString"));

    HashSet hashSet = new HashSet();

    hashSet.add("15");
    hashSet.add(new Double(45.01));

    HashSet etalonSet = (HashSet) hashSet.clone();
    HashMap hashMap = new HashMap();

    hashMap.put("16", new Boolean(false));
    hashMap.put("key", new Double(145.01));

    HashMap etalonMap = (HashMap) hashMap.clone();

    set.add(new JsonTestMockMapEntry("collection", hashSet));
    set.add(new JsonTestMockMapEntry("map", hashMap));
    assertEquals(Boolean.TRUE, map.get("boolean"));
    assertEquals(new Double(23.45), map.get("double"));
    assertEquals(new Integer(56), map.get("integer"));
    assertEquals(new Long(89), map.get("long"));
    assertEquals("testString", map.get("string"));

    Collection collection = (Collection) map.get("collection");

    assertTrue(etalonSet.containsAll(collection));
    etalonSet.removeAll(collection);
    assertTrue(etalonSet.isEmpty());
    assertEquals(etalonMap, map.get("map"));
}
 
Example 9
Project: bitseal   File: DatabaseContentProvider.java View source code Vote up 6 votes
private void checkColumns(String[] projection, int uriType) 
{
   String[] available = getAvailable(uriType);

   if (projection != null)
   {
    HashSet<String> requestedColumns = new HashSet<String>(Arrays.asList(projection));
    HashSet<String> availableColumns = new HashSet<String>(Arrays.asList(available));
    // check if all columns which are requested are available
    if (!availableColumns.containsAll(requestedColumns)) 
    {
	    throw new IllegalArgumentException("Unknown columns in projection. Exception occurred in DatabaseContentProvider.checkColumns()");
    }
  }
}
 
Example 10
Project: fiji   File: TrackSpeedStatisticsAnalyzerTest.java View source code Vote up 6 votes
@Before
public void setUp() {
	model = new TrackMateModel();
	model.beginUpdate();
	try {

		expectedVmean 		= new HashMap<Integer, Double>(N_TRACKS); 
		expectedVmax 		= new HashMap<Integer, Double>(N_TRACKS); 

		// Linear movement
		for (int i = 1; i < N_TRACKS+1; i++) {

			Spot previous = null;

			HashSet<Spot> track = new HashSet<Spot>();
			for (int j = 0; j <= DEPTH; j++) {
				// We use deterministic locations
				double[] location = new double[] { j * i, i, i }; 
				Spot spot = new Spot(location);
				spot.putFeature(Spot.POSITION_T, j);
				model.addSpotTo(spot, j);
				track.add(spot);
				if (null != previous) {
					model.addEdge(previous, spot, 1);
				}
				previous = spot;
			}

			int key = track.hashCode(); // a hack: the track ID will be the hash of the spot set
			double speed = i; 
			expectedVmean.put(key, Double.valueOf(speed));
			expectedVmax.put(key, Double.valueOf(speed));
		}

	} finally {
		model.endUpdate();
	}
}
 
Example 11
Project: google-web-toolkit-svnmirror   File: CollectionsTestServiceImpl.java View source code Vote up 6 votes
public HashSet<MarkerTypeHashSet> echo(HashSet<MarkerTypeHashSet> actual)
    throws CollectionsTestServiceException {
  HashSet<MarkerTypeHashSet> expected = TestSetFactory.createHashSet();
  if (!TestSetValidator.isValid(expected, actual)) {
    throw new CollectionsTestServiceException("expected: "
        + expected.toString() + " actual: " + actual.toString());
  }

  return actual;
}
 
Example 12
Project: jena   File: WGTestSuite.java View source code Vote up 5 votes
@Override
protected void runTest() {
    try {
        m1 = read(in, intype);
        /*
                        if (expectedLevel == 1
                            && expected == null
                            && errorCnt[2] == 0
                            && errorCnt[1] == 0)
                            save(input);
                            */
    } catch (JenaException re) {
        //   System.out.println(re.toString());
        if (re.getCause() instanceof SAXException) {
            // ignore.
        } else {
            fail(re.getMessage());
        }
    } catch (IOException ioe) {
        fail(ioe.getMessage());
    }
    // Tidy up this code a bit, I don't understand it.
    HashSet<Integer> ex2 = expected==null?null:new HashSet<>(expected);
    if (expected==null)
    for (int j = 2; j >= 0; j--)
        if (j != expectedLevel)  {
            if (errorCnt[j] != 0)
                ex2 = new HashSet<>();
        }
    if (ex2 != null && !ex2.equals(found)) {
        Set<Integer> dup = new HashSet<>();
        dup.addAll(found);
        dup.removeAll(ex2);
        ex2.removeAll(found);
        if (expected != null)
            expected.removeAll(found);
        Iterator<Integer> it = ex2.iterator();
        while (it.hasNext()) {
            int eCode = it.next().intValue();
            String msg =
                "Expected error  "
                    + ParseException.errorCodeName(eCode)
                    + ", was not detected.";
            if (errorCnt[2] == 0) {
                fail(msg);
            } else {
                System.err.println("Test: " + getName());
                System.err.println(msg);
            }
        }
        it = dup.iterator();
        while (it.hasNext())
            fail(
                "Detected error  "
                    + ParseException.errorCodeName(
                        it.next().intValue())
                    + ", was not expected.");
    }
    for (int j = 2; j >= 0; j--)
        if (j == expectedLevel) {
            if (errorCnt[j] == 0 && (j != 1 || errorCnt[2] == 0))
                fail(
                    "No "
                        + errorLevelName[expectedLevel]
                        + " in input file of class "
                        + getClass().getName());
        } else if (expected == null) {
            if (errorCnt[j] != 0)
                fail(
                    "Inappropriate "
                        + errorLevelName[j]
                        + " in input file of class "
                        + getClass().getName());
        }

}
 
Example 13
Project: bixie   File: GreedyCfgChecker.java View source code Vote up 5 votes
@Override
public Report runAnalysis(Prover prover) {

	TransitionRelation tr = new TransitionRelation(this.procedure,
			this.cff, prover);

	// Statistics.HACK_effectualSetSize = tr.getEffectualSet().size();

	LinkedHashMap<ProverExpr, ProverExpr> ineffFlags = new LinkedHashMap<ProverExpr, ProverExpr>();

	for (BasicBlock block : tr.getEffectualSet()) {
		ProverExpr v = tr.getReachabilityVariables().get(block);
		ineffFlags.put(v, prover.mkVariable("" + v + "_flag",
				prover.getBooleanType()));
	}

	/*
	 * Assert the transition relation of the procedure.
	 */
	prover.push();
	this.pushTransitionRelation(prover, tr);
	prover.addAssertion(tr.getEnsures());

	// construct the inverted reachabilityVariables which is used later
	// to keep track of what has been covered so far.
	Map<ProverExpr, BasicBlock> blocksToCover = createdInvertedReachabilityVariableMap(
			tr, new HashSet<BasicBlock>(tr.getReachabilityVariables()
					.keySet()));

	/*
	 * ===== main algorithm ==== Two steps: In the first step, push the
	 * assertion flag and check which blocks have feasible executions. Then
	 * pop the flag to disable all assertions and check what blocks can now
	 * be reached.
	 * 
	 * Step 1:
	 */
	prover.push();
	prover.addAssertion(prover.mkNot(tr.assertionFlag));
	HashSet<BasicBlock> coveredBlocks = new HashSet<BasicBlock>();
	coveredBlocks.addAll(coverBlocks(blocksToCover, tr, ineffFlags));

	// coverBlocks returns the set of all feasible blocks.
	this.feasibleBlocks = new HashSet<BasicBlock>(coveredBlocks);

	/*
	 * Step 2: Pop the tr.assertionFlag. An re-run coverBlocks to cover
	 * everything that has a feasible execution if assertions are ignored.
	 */
	prover.pop();
	coveredBlocks.addAll(coverBlocks(blocksToCover, tr, ineffFlags));

	/* Pop the transition relation. */
	prover.pop();

	/*
	 * ===== End of the main algorithm ==== everything that was not covered
	 * in either of the iterations is clearly unreachable.
	 */
	HashSet<BasicBlock> unreachable = new HashSet<BasicBlock>(
			blocksToCover.values());

	/*
	 * All blocks that are covered in the second round - that is, the blocks
	 * that are in coveredBlocks but not in feasibleBlocks - are potentially
	 * dangerous, because their inconsistency contains an assertion.
	 */
	HashSet<BasicBlock> dangerous = new HashSet<BasicBlock>(coveredBlocks);
	dangerous.removeAll(this.feasibleBlocks);

	Report report = new Report(tr);
	report.reportInconsistentCode(0, dangerous);
	report.reportInconsistentCode(1, unreachable);

	return report;
}
 
Example 14
Project: SimpleAlgebra_V2   File: QuaternionOrd.java View source code Vote up 5 votes
@Override
public boolean calcOrd( HashSet<BigInteger> ka , HashSet<BigInteger> kb , HashSet<BigInteger> el , U dim )
{
	boolean negate = false;
	
	final TreeSet<BigInteger> kaa = new TreeSet<BigInteger>( ka );
	final TreeSet<BigInteger> kbb = new TreeSet<BigInteger>( kb );
	
	
	final int sz = kaa.size() + kbb.size();
	
	
	final BigInteger[] arr = new BigInteger[ sz ];
	
	
	int cnt = 0;
	Iterator<BigInteger> it = kaa.iterator();
	while( it.hasNext() )
	{
		arr[ cnt ] = it.next();
		cnt++;
	}
	it = kbb.iterator();
	while( it.hasNext() )
	{
		arr[ cnt ] = it.next();
		cnt++;
	}
	
	
	boolean chg = true;
	while( chg )
	{
		chg = false;
		for( cnt = 0 ; cnt < ( sz - 1 ) ; cnt++ )
		{
			final BigInteger a0 = arr[ cnt ];
			final BigInteger a1 = arr[ cnt + 1 ];
			if( ( a0 == null ) && ( a1 != null ) )
			{
				arr[ cnt ] = a1;
				arr[ cnt + 1 ] = a0;
				chg = true;
			}
			else
			{
				if( ( a0 != null ) && ( a1 != null ) )
				{
					final int cmp = a0.compareTo( a1 );
					if( cmp == 0 )
					{
						arr[ cnt ] = null;
						arr[ cnt + 1 ] = null;
						chg = true;
						negate = !negate;
					}
					else
					{
						if( cmp > 0 )
						{
							arr[ cnt ] = a1;
							arr[ cnt + 1 ] = a0;
							chg = true;
							negate = !negate;
						}
					}
				}
			}
		}
	}
	
	
	for( cnt = 0 ; cnt < sz ; cnt++ )
	{
		if( arr[ cnt ] != null )
		{
			el.add( arr[ cnt ] );
		}
	}
	
	
	//
	// Equivalent to ijk = -1.
	//
	if( dim.equals( BigInteger.valueOf( el.size() ) ) )
	{
		el.clear();
		negate = !negate;
	}
	
	
	return( negate );
}