Example usage for com.google.common.collect Ordering arbitrary

List of usage examples for com.google.common.collect Ordering arbitrary

Introduction

In this page you can find the example usage for com.google.common.collect Ordering arbitrary.

Prototype

public static Ordering<Object> arbitrary() 

Source Link

Document

Returns an arbitrary ordering over all objects, for which compare(a, b) == 0 implies a == b (identity equality).

Usage

From source file:org.sonar.server.property.ws.IndexAction.java

/**
 * Return list of propertyDto by component uuid, sorted from project to lowest module
 *///from   w  w  w. j  a va 2  s  .  c  o m
private Multimap<String, PropertyDto> loadComponentSettings(DbSession dbSession, Optional<String> key,
        ComponentDto component) {
    List<String> componentUuids = DOT_SPLITTER.splitToList(component.moduleUuidPath());
    List<ComponentDto> componentDtos = dbClient.componentDao().selectByUuids(dbSession, componentUuids);
    Set<Long> componentIds = componentDtos.stream().map(ComponentDto::getId).collect(Collectors.toSet());
    Map<Long, String> uuidsById = componentDtos.stream()
            .collect(Collectors.toMap(ComponentDto::getId, ComponentDto::uuid));
    List<PropertyDto> properties = key.isPresent()
            ? dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession,
                    Collections.singleton(key.get()), componentIds)
            : dbClient.propertiesDao().selectPropertiesByComponentIds(dbSession, componentIds);

    Multimap<String, PropertyDto> propertyDtosByUuid = TreeMultimap.create(Ordering.explicit(componentUuids),
            Ordering.arbitrary());
    for (PropertyDto propertyDto : properties) {
        Long componentId = propertyDto.getResourceId();
        String componentUuid = uuidsById.get(componentId);
        propertyDtosByUuid.put(componentUuid, propertyDto);
    }
    return propertyDtosByUuid;
}

From source file:org.onosproject.EvacuateCommand.java

@SuppressWarnings("rawtypes")
private TreeMultimap<String, Metric> listMetrics(MetricsService metricsService, MetricFilter filter) {
    TreeMultimap<String, Metric> metrics = TreeMultimap.create(Comparator.naturalOrder(), Ordering.arbitrary());

    Map<String, Counter> counters = metricsService.getCounters(filter);
    for (Entry<String, Counter> entry : counters.entrySet()) {
        metrics.put(entry.getKey(), entry.getValue());
    }//from   w  w  w  .ja v  a 2  s .  c  o m
    Map<String, Gauge> gauges = metricsService.getGauges(filter);
    for (Entry<String, Gauge> entry : gauges.entrySet()) {
        metrics.put(entry.getKey(), entry.getValue());
    }
    Map<String, Histogram> histograms = metricsService.getHistograms(filter);
    for (Entry<String, Histogram> entry : histograms.entrySet()) {
        metrics.put(entry.getKey(), entry.getValue());
    }
    Map<String, Meter> meters = metricsService.getMeters(filter);
    for (Entry<String, Meter> entry : meters.entrySet()) {
        metrics.put(entry.getKey(), entry.getValue());
    }
    Map<String, Timer> timers = metricsService.getTimers(filter);
    for (Entry<String, Timer> entry : timers.entrySet()) {
        metrics.put(entry.getKey(), entry.getValue());
    }

    return metrics;
}

From source file:cpw.mods.fml.common.Loader.java

private void identifyDuplicates(List<ModContainer> mods) {
    TreeMultimap<ModContainer, File> dupsearch = TreeMultimap.create(new ModIdComparator(),
            Ordering.arbitrary());
    for (ModContainer mc : mods) {
        if (mc.getSource() != null) {
            dupsearch.put(mc, mc.getSource());
        }//from  ww  w . ja va2s  . c o m
    }

    ImmutableMultiset<ModContainer> duplist = Multisets.copyHighestCountFirst(dupsearch.keys());
    SetMultimap<ModContainer, File> dupes = LinkedHashMultimap.create();
    for (Entry<ModContainer> e : duplist.entrySet()) {
        if (e.getCount() > 1) {
            FMLLog.severe("Found a duplicate mod %s at %s", e.getElement().getModId(),
                    dupsearch.get(e.getElement()));
            dupes.putAll(e.getElement(), dupsearch.get(e.getElement()));
        }
    }
    if (!dupes.isEmpty()) {
        throw new DuplicateModsFoundException(dupes);
    }
}

From source file:org.apache.beam.sdk.io.FileSystems.java

@VisibleForTesting
static Map<String, FileSystem> verifySchemesAreUnique(PipelineOptions options,
        Set<FileSystemRegistrar> registrars) {
    Multimap<String, FileSystem> fileSystemsBySchemes = TreeMultimap.create(Ordering.<String>natural(),
            Ordering.arbitrary());

    for (FileSystemRegistrar registrar : registrars) {
        for (FileSystem fileSystem : registrar.fromOptions(options)) {
            fileSystemsBySchemes.put(fileSystem.getScheme(), fileSystem);
        }/*from   w  w w .  ja v  a  2 s.  c  o  m*/
    }
    for (Entry<String, Collection<FileSystem>> entry : fileSystemsBySchemes.asMap().entrySet()) {
        if (entry.getValue().size() > 1) {
            String conflictingFileSystems = Joiner.on(", ")
                    .join(FluentIterable.from(entry.getValue()).transform(new Function<FileSystem, String>() {
                        @Override
                        public String apply(@Nonnull FileSystem input) {
                            return input.getClass().getName();
                        }
                    }).toSortedList(Ordering.<String>natural()));
            throw new IllegalStateException(String.format("Scheme: [%s] has conflicting filesystems: [%s]",
                    entry.getKey(), conflictingFileSystems));
        }
    }

    ImmutableMap.Builder<String, FileSystem> schemeToFileSystem = ImmutableMap.builder();
    for (Entry<String, FileSystem> entry : fileSystemsBySchemes.entries()) {
        schemeToFileSystem.put(entry.getKey(), entry.getValue());
    }
    return schemeToFileSystem.build();
}