Java Code Examples for com.google.common.collect.Comparators#isInOrder()

The following examples show how to use com.google.common.collect.Comparators#isInOrder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClockManager.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks to ensure the timers are in the correct order.
 * If they are not, sort them and rebuild the clock panel
 *
 * @return whether the timer order was changed or not
 */
public boolean checkTimerOrder()
{
	SortOrder sortOrder = config.sortOrder();
	if (sortOrder != SortOrder.NONE)
	{
		Comparator<Timer> comparator = Comparator.comparingLong(Timer::getDisplayTime);
		if (sortOrder == SortOrder.DESC)
		{
			comparator = comparator.reversed();
		}

		if (!Comparators.isInOrder(timers, comparator))
		{
			timers.sort(comparator);
			SwingUtilities.invokeLater(clockTabPanel::rebuild);
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: ClockManager.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Checks to ensure the timers are in the correct order.
 * If they are not, sort them and rebuild the clock panel
 *
 * @return whether the timer order was changed or not
 */
public boolean checkTimerOrder()
{
	SortOrder sortOrder = config.sortOrder();
	if (sortOrder != SortOrder.NONE)
	{
		Comparator<Timer> comparator = Comparator.comparingLong(Timer::getDisplayTime);
		if (sortOrder == SortOrder.DESC)
		{
			comparator = comparator.reversed();
		}

		if (!Comparators.isInOrder(timers, comparator))
		{
			timers.sort(comparator);
			SwingUtilities.invokeLater(clockTabPanel::rebuild);
			return true;
		}
	}
	return false;
}
 
Example 3
Source File: SortedListChecker.java    From tutorials with MIT License 4 votes vote down vote up
public static boolean checkIfSortedUsingComparators(List<String> listOfStrings) {
    return Comparators.isInOrder(listOfStrings, Comparator.<String> naturalOrder());
}
 
Example 4
Source File: ComparatorsExamples.java    From tutorials with MIT License 3 votes vote down vote up
public static void main(String[] args) {

        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 4, 6, 7, 8, 9, 10);
        boolean isInAscendingOrder = Comparators.isInOrder(integers, new AscedingOrderComparator());
        System.out.println(isInAscendingOrder);

    }
 
Example 5
Source File: ComparatorsUnitTest.java    From tutorials with MIT License 3 votes vote down vote up
@Test
public void isInOrderTest() {

    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 4, 6, 7, 8, 9, 10);

    boolean isInAscendingOrder = Comparators.isInOrder(numbers, new AscendingOrderComparator<Number>());

    Assert.assertTrue(isInAscendingOrder);
}
 
Example 6
Source File: ComparatorsUnitTest.java    From tutorials with MIT License 3 votes vote down vote up
@Test
public void isInStrictOrderTest() {

    List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 3, 6, 7, 8, 9, 10);

    boolean isInAscendingOrder = Comparators.isInOrder(numbers, new AscendingOrderComparator<Number>());

    Assert.assertFalse(isInAscendingOrder);
}