List of usage examples for com.google.common.collect Ordering arbitrary
public static Ordering<Object> arbitrary()
From source file:brooklyn.location.docker.strategy.DepthFirstPlacementStrategy.java
/** Use an arbitrary, but fixed, ordering. */ @Override/* w w w . j a va2s . c o m*/ public int compare(DockerHostLocation l1, DockerHostLocation l2) { return Ordering.arbitrary().compare(l1, l2); }
From source file:org.gradle.api.internal.tasks.compile.FieldMember.java
@Override public int compareTo(FieldMember o) { return super.compare(o).compare(value, o.value, Ordering.arbitrary()).result(); }
From source file:org.cinchapi.concourse.util.Comparators.java
/** * Perform an arbitrary comparison between {@code o1} and {@code o2}. This * method assumes that the two objects are not considered equal. * //from w w w . j a va 2s.c o m * @param o1 * @param o2 * @return the comparison value */ private static <T> int arbitraryCompare(T o1, T o2) { return Ordering.arbitrary().compare(o1, o2); }
From source file:eu.interedition.text.mem.SimpleAnnotation.java
public int compareTo(Annotation o) { return Annotations.compare(this, o).compare(this, o, Ordering.arbitrary()).result(); }
From source file:org.grouplens.lenskit.scored.AbstractScoredId.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w .jav a 2 s . c o m*/ public boolean equals(Object o) { if (o == this) { return true; } else if (o instanceof ScoredId) { ScoredId oid = (ScoredId) o; Ordering<SymbolValue<?>> ord = Ordering.arbitrary().onResultOf(SymbolValue.extractSymbol()); return new EqualsBuilder().append(getId(), oid.getId()).append(getScore(), oid.getScore()) // FIXME Don't incur the boxing cost of doing this to double side channels .append(ord.sortedCopy(getChannels()), ord.sortedCopy(oid.getChannels())).isEquals(); } return false; }
From source file:org.apache.crunch.Pair.java
private int cmp(Object lhs, Object rhs) { if (lhs == rhs) { return 0; } else if (lhs != null && Comparable.class.isAssignableFrom(lhs.getClass())) { return Ordering.natural().nullsLast().compare((Comparable) lhs, (Comparable) rhs);//(Comparable) lhs).compareTo(rhs); }/* w w w. ja va2s. c o m*/ if (lhs == null) { return 1; // nulls last } if (rhs == null) { return -1; // nulls last } if (lhs.equals(rhs)) { return 0; } // Now we compare based on hash code. We already know that the two sides are not equal, so // if the hash codes are equal, we just use arbitrary (but consistent) ordering return ComparisonChain.start().compare(lhs.hashCode(), rhs.hashCode()) .compare(lhs, rhs, Ordering.arbitrary()).result(); }
From source file:org.onosproject.rest.resources.MetricsWebResource.java
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 (Map.Entry<String, Counter> entry : counters.entrySet()) { metrics.put(entry.getKey(), entry.getValue()); }/*from w ww . j av a2 s . c o m*/ Map<String, Gauge> gauges = metricsService.getGauges(filter); for (Map.Entry<String, Gauge> entry : gauges.entrySet()) { metrics.put(entry.getKey(), entry.getValue()); } Map<String, Histogram> histograms = metricsService.getHistograms(filter); for (Map.Entry<String, Histogram> entry : histograms.entrySet()) { metrics.put(entry.getKey(), entry.getValue()); } Map<String, Meter> meters = metricsService.getMeters(filter); for (Map.Entry<String, Meter> entry : meters.entrySet()) { metrics.put(entry.getKey(), entry.getValue()); } Map<String, Timer> timers = metricsService.getTimers(filter); for (Map.Entry<String, Timer> entry : timers.entrySet()) { metrics.put(entry.getKey(), entry.getValue()); } return metrics; }
From source file:org.sonar.server.setting.ws.SettingsFinder.java
/** * Return list of settings by component uuid, sorted from project to lowest module *///from www.j a v a2 s.co m public Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, 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 = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, keys, componentIds); List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, getPropertySetKeys(properties), componentIds); Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids), Ordering.arbitrary()); for (PropertyDto propertyDto : properties) { Long componentId = propertyDto.getResourceId(); String componentUuid = uuidsById.get(componentId); String propertyKey = propertyDto.getKey(); settingsByUuid.put(componentUuid, Setting.createFromDto(propertyDto, getPropertySets(propertyKey, propertySets, componentId), definitions.get(propertyKey))); } return settingsByUuid; }
From source file:org.sonar.server.settings.ws.SettingsFinder.java
/** * Return list of settings by component uuid, sorted from project to lowest module *///from www . j ava 2 s . co m public Multimap<String, Setting> loadComponentSettings(DbSession dbSession, Set<String> keys, 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 = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, keys, componentIds); List<PropertyDto> propertySets = dbClient.propertiesDao().selectPropertiesByKeysAndComponentIds(dbSession, getPropertySetKeys(properties), componentIds); Multimap<String, Setting> settingsByUuid = TreeMultimap.create(Ordering.explicit(componentUuids), Ordering.arbitrary()); for (PropertyDto propertyDto : properties) { Long componentId = propertyDto.getResourceId(); String componentUuid = uuidsById.get(componentId); String propertyKey = propertyDto.getKey(); settingsByUuid.put(componentUuid, Setting.createForDto(propertyDto, getPropertySets(propertyKey, propertySets, componentId), definitions.get(propertyKey))); } return settingsByUuid; }
From source file:org.apache.beam.sdk.util.IOChannelUtils.java
@VisibleForTesting static void checkDuplicateScheme(Set<IOChannelFactoryRegistrar> registrars) { Multimap<String, IOChannelFactoryRegistrar> registrarsBySchemes = TreeMultimap .create(Ordering.<String>natural(), Ordering.arbitrary()); for (IOChannelFactoryRegistrar registrar : registrars) { registrarsBySchemes.put(registrar.getScheme(), registrar); }//w w w.ja va2s. c o m for (Entry<String, Collection<IOChannelFactoryRegistrar>> entry : registrarsBySchemes.asMap().entrySet()) { if (entry.getValue().size() > 1) { String conflictingRegistrars = Joiner.on(", ").join(FluentIterable.from(entry.getValue()) .transform(new Function<IOChannelFactoryRegistrar, String>() { @Override public String apply(@Nonnull IOChannelFactoryRegistrar input) { return input.getClass().getName(); } }).toSortedList(Ordering.<String>natural())); throw new IllegalStateException(String.format("Scheme: [%s] has conflicting registrars: [%s]", entry.getKey(), conflictingRegistrars)); } } }