use of com.google.common.collect.Ordering in project gerrit by GerritCodeReview.
the class Schema_124 method fixInvalidSequenceNumbers.
private Collection<AccountSshKey> fixInvalidSequenceNumbers(Collection<AccountSshKey> keys) {
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
List<AccountSshKey> fixedKeys = new ArrayList<>(keys);
AccountSshKey minKey = o.min(keys);
while (minKey.getKey().get() <= 0) {
AccountSshKey fixedKey = new AccountSshKey(new AccountSshKey.Id(minKey.getKey().getParentKey(), Math.max(o.max(keys).getKey().get() + 1, 1)), minKey.getSshPublicKey());
Collections.replaceAll(fixedKeys, minKey, fixedKey);
minKey = o.min(fixedKeys);
}
return fixedKeys;
}
use of com.google.common.collect.Ordering in project android by JetBrains.
the class PreviewIconsPanel method initializeIconComponents.
private void initializeIconComponents(@NotNull Collection<Density> densities) {
// Sort the densities, so that we always line up icons from highest to lowest densities.
Ordering<Density> densityOrdering = new Ordering<Density>() {
@Override
public int compare(Density left, Density right) {
// The lower the enum index, the higher the density
return Ints.compare(left.ordinal(), right.ordinal());
}
};
densities = densityOrdering.immutableSortedCopy(densities);
for (Density density : densities) {
JPanel iconPanel = new JPanel(new VerticalFlowLayout(false, false));
iconPanel.setBackground(myTheme.getMainColor());
iconPanel.setOpaque(myTheme != Theme.TRANSPARENT);
JBLabel title = new JBLabel(density.getResourceValue());
title.setForeground(myTheme.getAltColor());
iconPanel.add(title);
ImageComponent iconImage = new ImageComponent(null);
iconImage.setBorder(new LineBorder(myTheme.getAltColor()));
iconImage.setOpaque(false);
iconPanel.add(iconImage);
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.PAGE_START;
myIconsPanel.add(iconPanel, c);
myIconImages.put(density, iconImage);
}
}
use of com.google.common.collect.Ordering in project druid by druid-io.
the class IndexMerger method merge.
public File merge(List<IndexableAdapter> indexes, final boolean rollup, final AggregatorFactory[] metricAggs, File outDir, IndexSpec indexSpec, ProgressIndicator progress) throws IOException {
FileUtils.deleteDirectory(outDir);
FileUtils.forceMkdir(outDir);
final List<String> mergedDimensions = getMergedDimensions(indexes);
final List<String> mergedMetrics = Lists.transform(mergeIndexed(Lists.newArrayList(FunctionalIterable.create(indexes).transform(new Function<IndexableAdapter, Iterable<String>>() {
@Override
public Iterable<String> apply(@Nullable IndexableAdapter input) {
return input.getMetricNames();
}
}))), new Function<String, String>() {
@Override
public String apply(@Nullable String input) {
return input;
}
});
final AggregatorFactory[] sortedMetricAggs = new AggregatorFactory[mergedMetrics.size()];
for (int i = 0; i < metricAggs.length; i++) {
AggregatorFactory metricAgg = metricAggs[i];
int metricIndex = mergedMetrics.indexOf(metricAgg.getName());
/*
If metricIndex is negative, one of the metricAggs was not present in the union of metrics from the indices
we are merging
*/
if (metricIndex > -1) {
sortedMetricAggs[metricIndex] = metricAgg;
}
}
/*
If there is nothing at sortedMetricAggs[i], then we did not have a metricAgg whose name matched the name
of the ith element of mergedMetrics. I.e. There was a metric in the indices to merge that we did not ask for.
*/
for (int i = 0; i < sortedMetricAggs.length; i++) {
if (sortedMetricAggs[i] == null) {
throw new IAE("Indices to merge contained metric[%s], but requested metrics did not", mergedMetrics.get(i));
}
}
for (int i = 0; i < mergedMetrics.size(); i++) {
if (!sortedMetricAggs[i].getName().equals(mergedMetrics.get(i))) {
throw new IAE("Metric mismatch, index[%d] [%s] != [%s]", i, sortedMetricAggs[i].getName(), mergedMetrics.get(i));
}
}
Function<ArrayList<Iterable<Rowboat>>, Iterable<Rowboat>> rowMergerFn = new Function<ArrayList<Iterable<Rowboat>>, Iterable<Rowboat>>() {
@Override
public Iterable<Rowboat> apply(@Nullable ArrayList<Iterable<Rowboat>> boats) {
if (rollup) {
return CombiningIterable.create(new MergeIterable<Rowboat>(Ordering.<Rowboat>natural().nullsFirst(), boats), Ordering.<Rowboat>natural().nullsFirst(), new RowboatMergeFunction(sortedMetricAggs));
} else {
return new MergeIterable<Rowboat>(new Ordering<Rowboat>() {
@Override
public int compare(Rowboat left, Rowboat right) {
return Longs.compare(left.getTimestamp(), right.getTimestamp());
}
}.nullsFirst(), boats);
}
}
};
return makeIndexFiles(indexes, sortedMetricAggs, outDir, progress, mergedDimensions, mergedMetrics, rowMergerFn, indexSpec);
}
use of com.google.common.collect.Ordering in project presto by prestodb.
the class StateCompiler method enumerateFields.
/**
* Enumerates all the fields in this state interface.
*
* @param clazz a subclass of AccumulatorState
* @param fieldTypes a map of field name and Type
* @return list of state fields. Ordering is guaranteed to be stable, and have all primitive fields at the beginning.
*/
private static List<StateField> enumerateFields(Class<?> clazz, Map<String, Type> fieldTypes) {
ImmutableList.Builder<StateField> builder = ImmutableList.builder();
final Set<Class<?>> primitiveClasses = ImmutableSet.of(byte.class, boolean.class, long.class, double.class);
Set<Class<?>> supportedClasses = getSupportedFieldTypes();
for (Method method : clazz.getMethods()) {
if (method.getName().equals("getEstimatedSize")) {
continue;
}
if (method.getName().startsWith("get")) {
Class<?> type = method.getReturnType();
checkArgument(supportedClasses.contains(type), type.getName() + " is not supported");
String name = method.getName().substring(3);
builder.add(new StateField(name, type, getInitialValue(method), method.getName(), Optional.ofNullable(fieldTypes.get(name))));
}
if (method.getName().startsWith("is")) {
Class<?> type = method.getReturnType();
checkArgument(type == boolean.class, "Only boolean is support for 'is' methods");
String name = method.getName().substring(2);
builder.add(new StateField(name, type, getInitialValue(method), method.getName(), Optional.of(BOOLEAN)));
}
}
// We need this ordering because the serializer and deserializer are on different machines, and so the ordering of fields must be stable
Ordering<StateField> ordering = new Ordering<StateField>() {
@Override
public int compare(StateField left, StateField right) {
if (primitiveClasses.contains(left.getType()) && !primitiveClasses.contains(right.getType())) {
return -1;
}
if (primitiveClasses.contains(right.getType()) && !primitiveClasses.contains(left.getType())) {
return 1;
}
// If they're the category, just sort by name
return left.getName().compareTo(right.getName());
}
};
List<StateField> fields = ordering.sortedCopy(builder.build());
checkInterface(clazz, fields);
return fields;
}
use of com.google.common.collect.Ordering in project gerrit by GerritCodeReview.
the class VersionedAuthorizedKeys method setKeys.
/**
* Sets new SSH keys.
*
* <p>The existing SSH keys are overwritten.
*
* @param newKeys the new public SSH keys
*/
public void setKeys(Collection<AccountSshKey> newKeys) {
Ordering<AccountSshKey> o = Ordering.from(comparing(k -> k.getKey().get()));
keys = new ArrayList<>(Collections.nCopies(o.max(newKeys).getKey().get(), Optional.empty()));
for (AccountSshKey key : newKeys) {
keys.set(key.getKey().get() - 1, Optional.of(key));
}
}
Aggregations