Java Code Examples for com.google.common.collect.Table#contains()

The following examples show how to use com.google.common.collect.Table#contains() . 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: SimilarityManager.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
public void storeDistanceMatrix(Table<String, String, Double> distanceMatrix, ISimilarityCalculator simCalculator) {
	List<Artifact> artifacts = appliableProjects(simCalculator);
	Artifact[] artifactsArray = new Artifact[artifacts.size()];
	artifactsArray = artifacts.toArray(artifactsArray);
	for (int i = 0; i < artifactsArray.length - 1; i++) {
		for (int j = i + 1; j < artifactsArray.length; j++) {
			double similarity = 0;
			try {
				if (distanceMatrix.contains(artifactsArray[i].getFullName(), artifactsArray[j].getFullName()))
					similarity = distanceMatrix.get(artifactsArray[i].getFullName(),
							artifactsArray[j].getFullName());
			} catch (Exception e) {
				logger.error(e.getMessage());
			}
			RelationType relType = getRelationType(simCalculator.getSimilarityName());
			Relation rel = new Relation();
			rel.setType(relType);
			rel.setFromProject(artifactsArray[i]);
			rel.setToProject(artifactsArray[j]);
			rel.setValue(similarity);
			relationRepository.save(rel);
		}
	}

}
 
Example 2
Source File: DiceRoll.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sorts the specified collection of units in ascending order of their attack or defense strength.
 *
 * @param defending {@code true} if the units should be sorted by their defense strength;
 *     otherwise the units will be sorted by their attack strength.
 */
public static void sortByStrength(final List<Unit> units, final boolean defending) {
  // Pre-compute unit strength information to speed up the sort.
  final Table<UnitType, GamePlayer, Integer> strengthTable = HashBasedTable.create();
  for (final Unit unit : units) {
    final UnitType type = unit.getType();
    final GamePlayer owner = unit.getOwner();
    if (!strengthTable.contains(type, owner)) {
      if (defending) {
        strengthTable.put(type, owner, UnitAttachment.get(type).getDefense(owner));
      } else {
        strengthTable.put(type, owner, UnitAttachment.get(type).getAttack(owner));
      }
    }
  }
  final Comparator<Unit> comp =
      (u1, u2) -> {
        final int v1 = strengthTable.get(u1.getType(), u1.getOwner());
        final int v2 = strengthTable.get(u2.getType(), u2.getOwner());
        return Integer.compare(v1, v2);
      };
  units.sort(comp);
}
 
Example 3
Source File: GuavaTableUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenTable_whenContains_returnsSuccessfully() {
    final Table<String, String, Integer> universityCourseSeatTable = HashBasedTable.create();
    universityCourseSeatTable.put("Mumbai", "Chemical", 120);
    universityCourseSeatTable.put("Mumbai", "IT", 60);
    universityCourseSeatTable.put("Harvard", "Electrical", 60);
    universityCourseSeatTable.put("Harvard", "IT", 120);

    final boolean entryIsPresent = universityCourseSeatTable.contains("Mumbai", "IT");
    final boolean entryIsAbsent = universityCourseSeatTable.contains("Oxford", "IT");
    final boolean courseIsPresent = universityCourseSeatTable.containsColumn("IT");
    final boolean universityIsPresent = universityCourseSeatTable.containsRow("Mumbai");
    final boolean seatCountIsPresent = universityCourseSeatTable.containsValue(60);

    assertThat(entryIsPresent).isEqualTo(true);
    assertThat(entryIsAbsent).isEqualTo(false);
    assertThat(courseIsPresent).isEqualTo(true);
    assertThat(universityIsPresent).isEqualTo(true);
    assertThat(seatCountIsPresent).isEqualTo(true);
}
 
Example 4
Source File: CheckpointManager.java    From qmq with Apache License 2.0 5 votes vote down vote up
private ConsumerGroupProgress getOrCreateConsumerGroupProgress(final String subject, final String group, final boolean broadcast) {
    final Table<String, String, ConsumerGroupProgress> progresses = actionCheckpoint.getProgresses();
    if (!progresses.contains(subject, group)) {
        final ConsumerGroupProgress progress = new ConsumerGroupProgress(subject, group, broadcast, -1, new HashMap<>());
        progresses.put(subject, group, progress);

    }
    return progresses.get(subject, group);
}
 
Example 5
Source File: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private Table<SMTProgram, Stmt, List<Pair<DynamicValueInformation, DynamicValue>>> getSMTProgramUpdateInfos(DynamicValueContainer dynamicValues) {
	Table<SMTProgram, Stmt, List<Pair<DynamicValueInformation, DynamicValue>>> updateInfoTable = HashBasedTable.create();
			
	for(DynamicValue value : dynamicValues.getValues()) {		
		Unit unit = codePositionManager.getUnitForCodePosition(value.getCodePosition()+1);
		int paramIdx = value.getParamIdx();
		
		for(Map.Entry<SMTProgram, Set<DynamicValueInformation>> entry : dynamicValueInfos.entrySet()) {
			for(DynamicValueInformation valueInfo : entry.getValue()) {
				if(valueInfo.getStatement().equals(unit)) {
					//base object
					if(paramIdx == -1) {
						if(valueInfo.isBaseObject()) {								
							if(!updateInfoTable.contains(entry.getKey(), valueInfo.getStatement())) 
								updateInfoTable.put(entry.getKey(), valueInfo.getStatement(), new ArrayList<Pair<DynamicValueInformation, DynamicValue>>());
							updateInfoTable.get(entry.getKey(), valueInfo.getStatement()).add(new Pair<DynamicValueInformation, DynamicValue>(valueInfo, value));		
												
						}
					}
					//method arguments
					else{
						if(valueInfo.getArgPos() == paramIdx) {
							if(!updateInfoTable.contains(entry.getKey(), valueInfo.getStatement())) 
								updateInfoTable.put(entry.getKey(), valueInfo.getStatement(), new ArrayList<Pair<DynamicValueInformation, DynamicValue>>());
							updateInfoTable.get(entry.getKey(), valueInfo.getStatement()).add(new Pair<DynamicValueInformation, DynamicValue>(valueInfo, value));	
						}
					}
				}
			}
		}
	}

	return updateInfoTable;
}
 
Example 6
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning(value="GC", num=9)
public static void testTable(Table<String, Integer, Long> t) {
    t.contains("x", "x");
    t.contains(1, 1);
    t.containsRow(1);
    t.containsColumn("x");
    t.containsValue(1);
    t.get("x", "x");
    t.get(1, 1);
    t.remove("x", "x");
    t.remove(1, 1);
}
 
Example 7
Source File: Guava.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@NoWarning(value="GC")
public static void testTableOK(Table<String, Integer, Long> t) {
    t.contains("x", 1);
    t.containsRow("x");
    t.containsColumn(1);
    t.containsValue(1L);
    t.get("x", 1);
    t.remove("x", 1);
}
 
Example 8
Source File: SmartConstantDataExtractorFuzzyAnalysis.java    From FuzzDroid with Apache License 2.0 4 votes vote down vote up
private void splitAPI_DataFlowtoSMTConvertion(ResultSourceInfo dataFlow, IInfoflowCFG cfg, Set<ResultSourceInfo> preparedDataFlowsForSMT, Table<Stmt, Integer, Set<String>> splitInfos) {			
	SMTConverter converter = new SMTConverter(sources);
	for(int i = 0; i < dataFlow.getPath().length; i++) {				
		System.out.println("\t" + dataFlow.getPath()[i]);
		System.out.println("\t\t" + dataFlow.getPathAccessPaths()[i]);
	}
	
	//we remove the first statement (split-API method)
	int n = dataFlow.getPath().length-1;
	Stmt[] reducedDataFlow = new Stmt[n];
	System.arraycopy(dataFlow.getPath(), 1, reducedDataFlow, 0, n);
				
	//currently only possible if there is a constant index for the array
	if(hasConstantIndexAtArrayForSplitDataFlow(reducedDataFlow)) {
		String valueOfInterest = getValueOfInterestForSplitDataflow(reducedDataFlow);
		
		converter.convertJimpleToSMT(reducedDataFlow,
				dataFlow.getPathAccessPaths(), targetUnits, cfg, null);
					
		converter.printProgramToCmdLine();
		
		File z3str2Script = new File(FrameworkOptions.Z3SCRIPT_LOCATION);
		if(!z3str2Script.exists())
			throw new RuntimeException("There is no z3-script available");
		SMTExecutor smtExecutor = new SMTExecutor(converter.getSmtPrograms(), z3str2Script);
		Set<File> smtFiles = smtExecutor.createSMTFile();
		
		for(File smtFile : smtFiles) {
			String loggingPointValue = smtExecutor.executeZ3str2ScriptAndExtractValue(smtFile, valueOfInterest);
			if(loggingPointValue != null) {
				Stmt splitStmt = dataFlow.getPath()[0];
				int index = getConstantArrayIndexForSplitDataFlow(reducedDataFlow);
				
				if(splitInfos.contains(splitStmt, index))
					splitInfos.get(splitStmt, index).add(loggingPointValue);
				else {
					Set<String> values = new HashSet<String>();
					values.add(loggingPointValue);
					splitInfos.put(splitStmt, index, values);
				}
			}
			System.out.println(loggingPointValue);
		}
		
		System.out.println("####################################");
	}			
}