Example usage for java.util Comparator equals

List of usage examples for java.util Comparator equals

Introduction

In this page you can find the example usage for java.util Comparator equals.

Prototype

boolean equals(Object obj);

Source Link

Document

Indicates whether some other object is "equal to" this comparator.

Usage

From source file:Main.java

public static <T> boolean isNaturalSortedSet(Iterable<? extends T> it) {
    if (it instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) it;
        Comparator<?> comparator = sortedSet.comparator();
        return (comparator == null) || comparator.equals(Ordering.natural());
    }/*from   w w  w . j ava2 s.c  o m*/
    return false;
}

From source file:Main.java

public static <T> boolean isNaturalSortedSet(@Nonnull Iterable<? extends T> it) {
    if (it instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) it;
        Comparator<?> comparator = sortedSet.comparator();
        return (comparator == null) || comparator.equals(Ordering.natural());
    }/*from w  w w. j  a v a  2  s  .  c om*/
    return false;
}

From source file:Main.java

@Nonnull
private static <T> SortedSet<? extends T> toSortedSet(@Nonnull Comparator<? super T> elementComparator,
        @Nonnull Collection<? extends T> collection) {
    if (collection instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) collection;
        Comparator<?> comparator = sortedSet.comparator();
        if (comparator != null && comparator.equals(elementComparator)) {
            return sortedSet;
        }//from   w ww  .  j  a v  a2  s .  co m
    }
    return ImmutableSortedSet.copyOf(elementComparator, collection);
}

From source file:Main.java

private static <T> SortedSet<? extends T> toSortedSet(Comparator<? super T> elementComparator,
        Collection<? extends T> collection) {
    if (collection instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) collection;
        Comparator<?> comparator = sortedSet.comparator();
        if (comparator != null && comparator.equals(elementComparator)) {
            return sortedSet;
        }/*w ww.  j av  a2 s  . c  o m*/
    }
    return ImmutableSortedSet.copyOf(elementComparator, collection);
}

From source file:Main.java

public static <T> boolean isSortedSet(Comparator<? extends T> elementComparator, Iterable<? extends T> it) {
    if (it instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) it;
        Comparator<?> comparator = sortedSet.comparator();
        if (comparator == null) {
            return elementComparator.equals(Ordering.natural());
        }//from  ww  w  . jav a 2 s.  c om
        return elementComparator.equals(comparator);
    }
    return false;
}

From source file:Main.java

public static <T> boolean isSortedSet(@Nonnull Comparator<? extends T> elementComparator,
        @Nonnull Iterable<? extends T> it) {
    if (it instanceof SortedSet) {
        SortedSet<? extends T> sortedSet = (SortedSet<? extends T>) it;
        Comparator<?> comparator = sortedSet.comparator();
        if (comparator == null) {
            return elementComparator.equals(Ordering.natural());
        }//from  w  ww .j av  a2 s  .  c om
        return elementComparator.equals(comparator);
    }
    return false;
}

From source file:Main.java

/**
 * @param a/*from  www.j  a  v a2 s.  co  m*/
 * @param b
 * @return
 */
public static boolean containsSome(Collection a, Collection b) {
    // fast paths
    if (a.size() == 0 || b.size() == 0)
        return false;
    if (a == b)
        return true; // must test after size test.

    if (a instanceof SortedSet && b instanceof SortedSet) {
        SortedSet aa = (SortedSet) a;
        SortedSet bb = (SortedSet) b;
        Comparator bbc = bb.comparator();
        Comparator aac = aa.comparator();
        if (bbc == null && aac == null) {
            Iterator ai = aa.iterator();
            Iterator bi = bb.iterator();
            Comparable ao = (Comparable) ai.next(); // these are ok, since the sizes are != 0
            Comparable bo = (Comparable) bi.next();
            while (true) {
                int rel = ao.compareTo(bo);
                if (rel < 0) {
                    if (!ai.hasNext())
                        return false;
                    ao = (Comparable) ai.next();
                } else if (rel > 0) {
                    if (!bi.hasNext())
                        return false;
                    bo = (Comparable) bi.next();
                } else {
                    return true;
                }
            }
        } else if (bbc.equals(a)) {
            Iterator ai = aa.iterator();
            Iterator bi = bb.iterator();
            Object ao = ai.next(); // these are ok, since the sizes are != 0
            Object bo = bi.next();
            while (true) {
                int rel = aac.compare(ao, bo);
                if (rel < 0) {
                    if (!ai.hasNext())
                        return false;
                    ao = ai.next();
                } else if (rel > 0) {
                    if (!bi.hasNext())
                        return false;
                    bo = bi.next();
                } else {
                    return true;
                }
            }
        }
    }
    for (Iterator it = a.iterator(); it.hasNext();) {
        if (b.contains(it.next()))
            return true;
    }
    return false;
}

From source file:Main.java

public static boolean containsAll(Collection a, Collection b) {
    // fast paths
    if (a == b)/*  ww  w .  j av  a2 s .  c  o  m*/
        return true;
    if (b.size() == 0)
        return true;
    if (a.size() < b.size())
        return false;

    if (a instanceof SortedSet && b instanceof SortedSet) {
        SortedSet aa = (SortedSet) a;
        SortedSet bb = (SortedSet) b;
        Comparator bbc = bb.comparator();
        Comparator aac = aa.comparator();
        if (bbc == null && aac == null) {
            Iterator ai = aa.iterator();
            Iterator bi = bb.iterator();
            Comparable ao = (Comparable) ai.next(); // these are ok, since the sizes are != 0
            Comparable bo = (Comparable) bi.next();
            while (true) {
                int rel = ao.compareTo(bo);
                if (rel == 0) {
                    if (!bi.hasNext())
                        return true;
                    if (!ai.hasNext())
                        return false;
                    bo = (Comparable) bi.next();
                    ao = (Comparable) ai.next();
                } else if (rel < 0) {
                    if (!ai.hasNext())
                        return false;
                    ao = (Comparable) ai.next();
                } else {
                    return false;
                }
            }
        } else if (bbc.equals(aac)) {
            Iterator ai = aa.iterator();
            Iterator bi = bb.iterator();
            Object ao = ai.next(); // these are ok, since the sizes are != 0
            Object bo = bi.next();
            while (true) {
                int rel = aac.compare(ao, bo);
                if (rel == 0) {
                    if (!bi.hasNext())
                        return true;
                    if (!ai.hasNext())
                        return false;
                    bo = bi.next();
                    ao = ai.next();
                } else if (rel < 0) {
                    if (!ai.hasNext())
                        return false;
                    ao = ai.next();
                } else {
                    return false;
                }
            }
        }
    }
    return a.containsAll(b);
}

From source file:org.sakaiproject.tool.messageforums.ui.MessageForumStatisticsBean.java

/**
 * Retreives topic statistics while determining whether to retrieve them from the cache or by invoking getTopicStatistics()
 *//*w  w w .  jav  a2s . co  m*/
public List getGradeStatisticsForStatsListByTopic() {
    // Determine if something has changed that warrants the cached gradeStatistics to be refreshed
    // Has the selected gradebook assignment or the selected group changed since the gradeStatistics were cached?
    boolean refreshCachedStatistics = !StringUtils.equals(m_gradeStatisticsAssign, selectedAssign)
            || !StringUtils.equals(m_gradeStatisticsGroup, selectedGroup);
    if (!refreshCachedStatistics) {
        // Are we sorting on a different column?
        Comparator comparator = determineComparator();
        if (comparator != null && !comparator.equals(m_comparator)) {
            refreshCachedStatistics = true;
        }
    }

    if (refreshCachedStatistics) {
        // The selected gradebook assignment or group has changed; our gradeStatistics need to be updated
        getTopicStatistics();
    }
    return gradeStatistics;
}