List of usage examples for com.google.common.collect Ordering onResultOf
@GwtCompatible(serializable = true) public <F> Ordering<F> onResultOf(Function<F, ? extends T> function)
From source file:com.isotrol.impe3.pms.core.impl.PageLoaderImpl.java
private static <K, F extends WithPosition> Ordering<Entry<K, F>> ordering() { final Ordering<Integer> o = Ordering.natural(); return o.onResultOf(new Function<Entry<K, F>, Integer>() { public Integer apply(Entry<K, F> from) { return from.getValue().getPosition(); }//from w w w .j av a 2s . co m }); }
From source file:org.apache.phoenix.iterate.OrderedResultIterator.java
/** * Builds a comparator from the list of columns in ORDER BY clause. * @param orderByExpressions the columns in ORDER BY clause. * @return the comparator built from the list of columns in ORDER BY clause. *//* w ww . j av a 2s .c om*/ // ImmutableBytesWritable.Comparator doesn't implement generics @SuppressWarnings("unchecked") private static Comparator<ResultEntry> buildComparator(List<OrderByExpression> orderByExpressions) { Ordering<ResultEntry> ordering = null; int pos = 0; for (OrderByExpression col : orderByExpressions) { Expression e = col.getExpression(); Comparator<ImmutableBytesWritable> comparator = e.getSortOrder() == SortOrder.DESC && !e.getDataType().isFixedWidth() ? buildDescVarLengthComparator() : new ImmutableBytesWritable.Comparator(); Ordering<ImmutableBytesWritable> o = Ordering.from(comparator); if (!col.isAscending()) o = o.reverse(); o = col.isNullsLast() ? o.nullsLast() : o.nullsFirst(); Ordering<ResultEntry> entryOrdering = o.onResultOf(new NthKey(pos++)); ordering = ordering == null ? entryOrdering : ordering.compound(entryOrdering); } return ordering; }
From source file:com.evidon.areweprivateyet.ValueComparableMap.java
private ValueComparableMap(Ordering<? super V> partialValueOrdering, HashMap<K, V> valueMap) { super(partialValueOrdering //Apply the value ordering .onResultOf(Functions.forMap(valueMap)) //On the result of getting the value for the key from the map .compound(Ordering.natural())); //as well as ensuring that the keys don't get clobbered this.valueMap = valueMap; }
From source file:org.obiba.opal.web.ws.provider.AbstractProtobufProvider.java
private Iterable<Message> sortMessages(Iterable<Message> msgs, final FieldDescriptor field, Ordering<Comparable<?>> ordering) { return ordering.onResultOf(new Function<Message, Comparable<?>>() { @Override/*from w w w .java 2 s . c o m*/ public Comparable<?> apply(Message input) { Object value = input.getField(field); if (value == null) return null; // This can throw a ClassCastException, but we tested JavaType earlier, so it shouldn't return Comparable.class.cast(value); } }).sortedCopy(msgs); }
From source file:io.v.baku.toolkit.bind.PrefixBindingBuilder.java
public PrefixBindingBuilder<T, A> valueOrdering(final Ordering<? super T> ordering) { return ordering(ordering.onResultOf(RxTable.Row::getValue)); }
From source file:com.ibm.bi.dml.runtime.transform.DummycodeAgent.java
public String constructDummycodedHeader(String header, Pattern delim) { if (_dcdList == null && _binList == null) // none of the columns are dummycoded, simply return the given header return header; String[] names = delim.split(header, -1); List<String> newNames = null; StringBuilder sb = new StringBuilder(); // Dummycoding can be performed on either on a recoded column or on a binned column // process recoded columns if (_finalMapsCP != null && _dcdList != null) { for (int i = 0; i < _dcdList.length; i++) { int colID = _dcdList[i]; HashMap<String, Long> map = _finalMapsCP.get(colID); String colName = UtilFunctions.unquote(names[colID - 1]); if (map != null) { // order map entries by their recodeID Ordering<String> valueComparator = Ordering.natural().onResultOf(Functions.forMap(map)); newNames = valueComparator.sortedCopy(map.keySet()); // construct concatenated string of map entries sb.setLength(0);// w w w . ja v a 2s. c o m for (int idx = 0; idx < newNames.size(); idx++) { if (idx == 0) sb.append(colName + DCD_NAME_SEP + newNames.get(idx)); else sb.append(delim + colName + DCD_NAME_SEP + newNames.get(idx)); } names[colID - 1] = sb.toString(); // replace original column name with dcd name } } } else if (_finalMaps != null && _dcdList != null) { for (int i = 0; i < _dcdList.length; i++) { int colID = _dcdList[i]; HashMap<String, String> map = _finalMaps.get(colID); String colName = UtilFunctions.unquote(names[colID - 1]); if (map != null) { // order map entries by their recodeID (represented as Strings .. "1", "2", etc.) Ordering<String> orderByID = new Ordering<String>() { public int compare(String s1, String s2) { return (Integer.parseInt(s1) - Integer.parseInt(s2)); } }; newNames = orderByID.onResultOf(Functions.forMap(map)).sortedCopy(map.keySet()); // construct concatenated string of map entries sb.setLength(0); for (int idx = 0; idx < newNames.size(); idx++) { if (idx == 0) sb.append(colName + DCD_NAME_SEP + newNames.get(idx)); else sb.append(delim + colName + DCD_NAME_SEP + newNames.get(idx)); } names[colID - 1] = sb.toString(); // replace original column name with dcd name } } } // process binned columns if (_binList != null) for (int i = 0; i < _binList.length; i++) { int colID = _binList[i]; // need to consider only binned and dummycoded columns if (isDummyCoded(colID) == -1) continue; int numBins = _numBins[i]; String colName = UtilFunctions.unquote(names[colID - 1]); sb.setLength(0); for (int idx = 0; idx < numBins; idx++) if (idx == 0) sb.append(colName + DCD_NAME_SEP + "Bin" + (idx + 1)); else sb.append(delim + colName + DCD_NAME_SEP + "Bin" + (idx + 1)); names[colID - 1] = sb.toString(); // replace original column name with dcd name } // Construct the full header sb.setLength(0); for (int colID = 0; colID < names.length; colID++) { if (colID == 0) sb.append(names[colID]); else sb.append(delim + names[colID]); } //System.out.println("DummycodedHeader: " + sb.toString()); return sb.toString(); }