use of com.google.common.collect.SetMultimap in project checkstyle by checkstyle.
the class TranslationCheck method checkFilesForConsistencyRegardingTheirKeys.
/**
* Compares th the specified key set with the key sets of the given translation files (arranged
* in a map). All missing keys are reported.
* @param fileKeys a Map from translation files to their key sets.
* @param keysThatMustExist the set of keys to compare with.
*/
private void checkFilesForConsistencyRegardingTheirKeys(SetMultimap<File, String> fileKeys, Set<String> keysThatMustExist) {
for (File currentFile : fileKeys.keySet()) {
final MessageDispatcher dispatcher = getMessageDispatcher();
final String path = currentFile.getPath();
dispatcher.fireFileStarted(path);
final Set<String> currentFileKeys = fileKeys.get(currentFile);
final Set<String> missingKeys = keysThatMustExist.stream().filter(e -> !currentFileKeys.contains(e)).collect(Collectors.toSet());
if (!missingKeys.isEmpty()) {
for (Object key : missingKeys) {
log(0, MSG_KEY, key);
}
}
fireErrors(path);
dispatcher.fireFileFinished(path);
}
}
use of com.google.common.collect.SetMultimap in project buck by facebook.
the class OwnersReport method generateOwnersReport.
@VisibleForTesting
static OwnersReport generateOwnersReport(Cell rootCell, TargetNode<?, ?> targetNode, Iterable<String> filePaths) {
// Process arguments assuming they are all relative file paths.
Set<Path> inputs = Sets.newHashSet();
Set<String> nonExistentInputs = Sets.newHashSet();
Set<String> nonFileInputs = Sets.newHashSet();
for (String filePath : filePaths) {
Path file = rootCell.getFilesystem().getPathForRelativePath(filePath);
if (!Files.exists(file)) {
nonExistentInputs.add(filePath);
} else if (!Files.isRegularFile(file)) {
nonFileInputs.add(filePath);
} else {
inputs.add(rootCell.getFilesystem().getPath(filePath));
}
}
// Try to find owners for each valid and existing file.
Set<Path> inputsWithNoOwners = Sets.newHashSet(inputs);
SetMultimap<TargetNode<?, ?>, Path> owners = TreeMultimap.create();
for (final Path commandInput : inputs) {
Predicate<Path> startsWith = input -> !commandInput.equals(input) && commandInput.startsWith(input);
Set<Path> ruleInputs = targetNode.getInputs();
if (ruleInputs.contains(commandInput) || FluentIterable.from(ruleInputs).anyMatch(startsWith)) {
inputsWithNoOwners.remove(commandInput);
owners.put(targetNode, commandInput);
}
}
return new OwnersReport(owners, inputsWithNoOwners, nonExistentInputs, nonFileInputs);
}
use of com.google.common.collect.SetMultimap in project github-version-statistics by centic9.
the class SplitStats method main.
public static void main(String[] args) throws IOException {
List<String> lines = FileUtils.readLines(new File("stats.json"), "UTF-8");
// collect all to combine
Map<String, SetMultimap<String, String>> byDate = new HashMap<>();
for (String line : lines) {
Holder holder = JSONWriter.mapper.readValue(line, Holder.class);
SetMultimap<String, String> existing = byDate.get(holder.getDate());
if (existing != null) {
existing.putAll(holder.getVersions());
} else {
byDate.put(holder.getDate(), holder.getVersions());
}
}
for (Entry<String, SetMultimap<String, String>> entry : byDate.entrySet()) {
JSONWriter.write(entry.getKey(), entry.getValue());
}
}
use of com.google.common.collect.SetMultimap in project records-management by Alfresco.
the class PublicAPITestUtil method testPublicAPIConsistency.
/**
* Check the consistency of the public API exposed from the given package. For each class in the package that is
* annotated {@link AlfrescoPublicApi}, check that no exposed methods (or fields, constructors, etc.) use
* non-public-API classes from Alfresco.
*
* @param basePackageName The package to check classes within.
* @param knownBadReferences Any references that would cause this test to fail, but which we don't want to change.
* The keys should be public API classes within our code and the values should be the non-public-API
* class that is being referenced.
*/
public static void testPublicAPIConsistency(String basePackageName, SetMultimap<Class<?>, Class<?>> knownBadReferences) {
Reflections reflections = new Reflections(basePackageName);
Set<Class<?>> publicAPIClasses = reflections.getTypesAnnotatedWith(AlfrescoPublicApi.class, true);
SetMultimap<Class<?>, Class<?>> referencedFrom = HashMultimap.create();
Set<Class<?>> referencedClasses = new HashSet<>();
for (Class<?> publicAPIClass : publicAPIClasses) {
Set<Class<?>> referencedClassesFromClass = getReferencedClassesFromClass(publicAPIClass, new HashSet<>());
referencedClassesFromClass.forEach(clazz -> referencedFrom.put(clazz, publicAPIClass));
// Remove any references in knownBadReferences and error if an expected reference wasn't found.
if (knownBadReferences.containsKey(publicAPIClass)) {
for (Class<?> clazz : knownBadReferences.get(publicAPIClass)) {
assertTrue("Supplied knownBadReferences expects " + clazz + " to be referenced by " + publicAPIClass + ", but no such error was found", referencedClassesFromClass.remove(clazz));
}
}
referencedClasses.addAll(referencedClassesFromClass);
}
List<String> errorMessages = new ArrayList<>();
for (Class<?> referencedClass : referencedClasses) {
if (isInAlfresco(referencedClass) && !isPartOfPublicApi(referencedClass)) {
Set<String> referencerNames = referencedFrom.get(referencedClass).stream().map(c -> c.getName()).collect(Collectors.toSet());
errorMessages.add(referencedClass.getName() + " <- " + StringUtils.join(referencerNames, ", "));
}
}
if (!errorMessages.isEmpty()) {
System.out.println("Errors found:");
System.out.println(StringUtils.join(errorMessages, "\n"));
}
assertEquals("Found references to non-public API classes from public API classes.", Collections.emptyList(), errorMessages);
}
use of com.google.common.collect.SetMultimap in project presto by prestodb.
the class PrestoSparkRddFactory method createTaskSourcesRdd.
private PrestoSparkTaskSourceRdd createTaskSourcesRdd(PlanFragmentId fragmentId, JavaSparkContext sparkContext, Session session, PartitioningHandle partitioning, List<TableScanNode> tableScans, Map<PlanNodeId, SplitSource> splitSources, Optional<Integer> numberOfShufflePartitions) {
ListMultimap<Integer, SerializedPrestoSparkTaskSource> taskSourcesMap = ArrayListMultimap.create();
for (TableScanNode tableScan : tableScans) {
int totalNumberOfSplits = 0;
SplitSource splitSource = requireNonNull(splitSources.get(tableScan.getId()), "split source is missing for table scan node with id: " + tableScan.getId());
try (PrestoSparkSplitAssigner splitAssigner = createSplitAssigner(session, tableScan.getId(), splitSource, partitioning)) {
while (true) {
Optional<SetMultimap<Integer, ScheduledSplit>> batch = splitAssigner.getNextBatch();
if (!batch.isPresent()) {
break;
}
int numberOfSplitsInCurrentBatch = batch.get().size();
log.info("Found %s splits for table scan node with id %s", numberOfSplitsInCurrentBatch, tableScan.getId());
totalNumberOfSplits += numberOfSplitsInCurrentBatch;
taskSourcesMap.putAll(createTaskSources(tableScan.getId(), batch.get()));
}
}
log.info("Total number of splits for table scan node with id %s: %s", tableScan.getId(), totalNumberOfSplits);
}
long allTaskSourcesSerializedSizeInBytes = taskSourcesMap.values().stream().mapToLong(serializedTaskSource -> serializedTaskSource.getBytes().length).sum();
log.info("Total serialized size of all task sources for fragment %s: %s", fragmentId, DataSize.succinctBytes(allTaskSourcesSerializedSizeInBytes));
List<List<SerializedPrestoSparkTaskSource>> taskSourcesByPartitionId = new ArrayList<>();
// If the fragment contains any shuffle inputs, this value will be present
if (numberOfShufflePartitions.isPresent()) {
// non bucketed tables match, an empty partition must be inserted if bucket is missing.
for (int partitionId = 0; partitionId < numberOfShufflePartitions.get(); partitionId++) {
// Eagerly remove task sources from the map to let GC reclaim the memory
// If task sources are missing for a partition the removeAll returns an empty list
taskSourcesByPartitionId.add(requireNonNull(taskSourcesMap.removeAll(partitionId), "taskSources is null"));
}
} else {
taskSourcesByPartitionId.addAll(Multimaps.asMap(taskSourcesMap).values());
}
return new PrestoSparkTaskSourceRdd(sparkContext.sc(), taskSourcesByPartitionId);
}
Aggregations