Guava Ordering - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Ordering class.

This code example shows how to use the following methods:immutableSortedCopy, onResultOf
		} 
		return map;
	} 
 
	public static <T> List<T> sortedKeys(Map<T, ? extends Comparable<?>> map, int elements) {
		List<T> list = Ordering.natural().reverse().onResultOf(Functions.forMap(map)).immutableSortedCopy(map.keySet());
		return list.size() > elements ? list.subList(0, elements) : list;
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:max, min
        if (titleMissing(subject) || titleMissing(candidate)) {
            return false; 
        } 
        Set<String> subjectWords = filterCommon(lowerCaseTitleWords(subject));
        Set<String> candidateWords = filterCommon(lowerCaseTitleWords(candidate));
        Set<String> shorter = collectionSize.min(subjectWords, candidateWords);
        Set<String> longer = collectionSize.max(candidateWords, subjectWords);
        return percentOfShorterInLonger(shorter, longer) >= threshold;
    } 
 
    private Set<String> filterCommon(Set<String> words) {
        return Sets.difference(words, commonWords);
    } 
 
    private ImmutableSet<String> lowerCaseTitleWords(Content subject) {
        return ImmutableSet.copyOf(splitter.split(subject.getTitle().toLowerCase()));
    } 
 
    private double percentOfShorterInLonger(Set<String> shorter, Set<String> longer) {
        int contained = Sets.intersection(shorter, longer).size();
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compound, onResultOf
        this(partialValueOrdering, new HashMap<K,V>());
    } 
 
    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;
    } 
 
    public V put(K k, V v) {
        if (valueMap.containsKey(k)){
            //remove the key in the sorted set before adding the key again 
            remove(k);
        } 
        valueMap.put(k,v); //To get "real" unsorted values for the comparator
        return super.put(k, v); //Put it in value order
    } 
 
    public static void main(String[] args){
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compare
    } 
 
    @SuppressWarnings({"unchecked"}) 
    @Override 
    public int compareTo(LexicographicPair<A, B> other) {
        int result = ordering.compare(getLeft(), other.getLeft());
        if (result == 0) {
            return ordering.compare(getRight(), other.getRight());
        } else { 
            return result;
        } 
    } 
 
    public static <A extends Comparable<A>, B extends Comparable<B>> LexicographicPair<A, B> pair(A left, B right) {
        return new LexicographicPair<A, B>(left, right);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compare
	 
	private static final Ordering<Date> ORDERING = Ordering.<Date>natural().nullsFirst();
 
	@Override 
	protected int compareNotNullObjects(ArtifactVersion left, ArtifactVersion right) {
		return ORDERING.compare(left.getLastUpdateDate(), right.getLastUpdateDate());
	} 
	 
	public static ArtifactVersionLastUpdateDateComparator get() { 
		return INSTANCE;
	} 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:onResultOf
	 * Until {@link http://code.google.com/p/guava-libraries/issues/detail?id=332} is addressed. 
	 */ 
	public static <T> Ordering<T> explicitWithUnknownsFirst(List<T> valuesInOrder) {
		Function<T, T> unknownToNullFunction = new IdentityIndicatorFunction<T>(valuesInOrder);
 
		return Ordering.explicit(valuesInOrder).nullsFirst().onResultOf(unknownToNullFunction);
	} 
	 
	/** 
	 * {@link org.cishell.utilities.OrderingUtilities.explicitWithUnknownsFirst(List<T>)} 
	 */ 
	public static <T> Ordering<T> explicitWithUnknownsFirst(
			T leastValue, T... remainingValuesInOrder) {
		return explicitWithUnknownsFirst(Lists.asList(leastValue, remainingValuesInOrder));
	} 
	 
	 
	/** 
	 * Normally Ordering.explicit() gives an Ordering that throws a ClassCastException for 
	 * unspecified values.  This method gives an explicit ordering that puts unspecified values 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compare
    } 
 
    private static Ordering<CategorizedDomainObject> ORDER_BY_CATEGORY = new Ordering<CategorizedDomainObject>() {
        @Override 
        public int compare(CategorizedDomainObject left, CategorizedDomainObject right) { 
            return Ordering.natural().nullsFirst().compare(left.getCategory(), right.getCategory()); 
        } 
    }; 
     
    private static Ordering<CategorizedDomainObject> ORDER_BY_SUBCATEGORY = new Ordering<CategorizedDomainObject>() {
        @Override 
        public int compare(CategorizedDomainObject left, CategorizedDomainObject right) { 
            return Ordering.natural().nullsFirst().compare(left.getSubcategory(), right.getSubcategory()); 
        } 
         
    }; 
 
 
 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:compound, onResultOf
			this(partialValueOrdering, new HashMap<K, V>());
		} 
 
		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;
		} 
 
		@Override 
		public V get(Object key) { 
			return this.valueMap.get(key);
		} 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:min
            } 
 
            // statistics can be missing for any reason 
            if (columnStatistics.getDoubleStatistics() != null) {
                // verify min 
                if (Math.abs(columnStatistics.getDoubleStatistics().getMin() - Ordering.natural().nullsLast().min(chunk)) > 0.001) {
                    return false; 
                } 
 
                // verify max 
                if (Math.abs(columnStatistics.getDoubleStatistics().getMax() - Ordering.natural().nullsFirst().max(chunk)) > 0.001) {
                    return false; 
                } 
            } 
            return true; 
        } 
    } 
 
    private static class DecimalOrcPredicate 
            extends BasicOrcPredicate<SqlDecimal>
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:sortedCopy
    public void testCustomOrderingWithMissingValue() { 
        order.addPartialOrdering(asList(1, 2, 4, 5));
        Assert.assertEquals(asList(1, 2, 4, 5), order.getCompletelyOrderedItems());
 
        Ordering<Integer> completeOrdering = order.getCompleteOrdering();
        Assert.assertEquals(asList(2, 4, 3), completeOrdering.sortedCopy(asList(4, 2, 3)));
    } 
 
    @Test
    public void testSortingCopy() { 
        order.addPartialOrdering(asList(1, 9));
        order.addPartialOrdering(asList(3));
        order.addPartialOrdering(asList(6));
        order.addPartialOrdering(asList(8));
        order.addPartialOrdering(asList(2));
        order.addPartialOrdering(asList(4));
        order.addPartialOrdering(asList(7));
        Assert.assertEquals(asList(1, 3, 6, 8, 2, 4, 7, 9), order.getCompletelyOrderedItems());
 
        Ordering<Integer> completeOrdering = order.getCompleteOrdering();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava Ordering Methods: