com.google.common.collect.Table#contains ( )源码实例Demo

下面列出了com.google.common.collect.Table#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: scava   文件: SimilarityManager.java
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);
		}
	}

}
 
源代码2 项目: triplea   文件: DiceRoll.java
/**
 * 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);
}
 
源代码3 项目: tutorials   文件: GuavaTableUnitTest.java
@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);
}
 
源代码4 项目: qmq   文件: CheckpointManager.java
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);
}
 
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;
}
 
源代码6 项目: spotbugs   文件: Guava.java
@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);
}
 
源代码7 项目: spotbugs   文件: Guava.java
@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);
}
 
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("####################################");
	}			
}