List of usage examples for org.apache.commons.collections.comparators BooleanComparator BooleanComparator
public BooleanComparator(boolean trueFirst)
BooleanComparator
that sorts trueFirst
values before !trueFirst
values. From source file:org.gradle.language.base.internal.model.BinarySourceTransformations.java
private Iterable<LanguageTransform<?, ?>> prioritize(LanguageTransformContainer languageTransforms) { List<LanguageTransform<?, ?>> prioritized = Lists.newArrayList(languageTransforms); Collections.sort(prioritized, new Comparator<LanguageTransform<?, ?>>() { @Override//from w ww.j a v a 2 s . c o m public int compare(LanguageTransform<?, ?> o1, LanguageTransform<?, ?> o2) { boolean joint1 = o1.getTransformTask() instanceof JointCompileTaskConfig; boolean joint2 = o2.getTransformTask() instanceof JointCompileTaskConfig; return new BooleanComparator(true).compare(joint1, joint2); } }); return prioritized; }
From source file:org.openbase.bco.manager.util.launch.BCOSystemValidator.java
public static void main(String[] args) { BCO.printLogo();//from w ww . ja v a 2 s .c o m JPService.setApplicationName("bco-validate"); JPService.registerProperty(JPDebugMode.class); JPService.registerProperty(JPVerbose.class); JPService.parseAndExitOnError(args); try { System.out.println("=================================================="); System.out.println("BaseCubeOne - System Validator"); System.out.println("=================================================="); System.out.println(); System.out.println("=== " + AnsiColor.colorize("Check Registries", AnsiColor.ANSI_BLUE) + " ===\n"); final BooleanComparator trueFirstBooleanComparator = new BooleanComparator(true); final BooleanComparator falseFirstBooleanComparator = new BooleanComparator(false); // check List<RegistryRemote> registries = Registries.getRegistries(false); registries.sort((registryRemote, t1) -> falseFirstBooleanComparator.compare( registryRemote instanceof AbstractVirtualRegistryRemote, t1 instanceof AbstractVirtualRegistryRemote)); for (final RegistryRemote registry : registries) { if (!check(registry, TimeUnit.SECONDS.toMillis(2))) { if (registry.isConsistent()) { System.out.println( StringProcessor.fillWithSpaces(registry.getName(), LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize(OK, AnsiColor.ANSI_GREEN)); } else { System.out.println( StringProcessor.fillWithSpaces(registry.getName(), LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize("INCONSISTENT", AnsiColor.ANSI_RED)); } } } System.out.println(); System.out.println("=== " + AnsiColor.colorize("Check Units", AnsiColor.ANSI_BLUE) + " ===\n"); Future<List<UnitRemote<?>>> futureUnits = Units.getFutureUnits(false); System.out.println(StringProcessor.fillWithSpaces("Unit Pool", LABEL_RANGE, Alignment.RIGHT) + " " + check(futureUnits, DEFAULT_UNIT_POOL_DELAY_TIME)); System.out.println(); if (futureUnits.isCancelled()) { System.out.println(AnsiColor.colorize( "Connection could not be established, please make sure BaseCubeOne is up and running!\n", AnsiColor.ANSI_YELLOW)); try { futureUnits.get(); } catch (ExecutionException | CancellationException ex) { ExceptionPrinter.printHistory("Error Details", ex, System.err); } } else { boolean printed = false; final List<UnitRemote<?>> unitList = new ArrayList<>(futureUnits.get()); unitList.sort((unitRemote, t1) -> { try { return trueFirstBooleanComparator.compare(unitRemote.isDalUnit(), t1.isDalUnit()); } catch (CouldNotPerformException ex) { LOGGER.warn("Could not compare unit[" + unitRemote + "] and unit[" + t1 + "]", ex); return 0; } }); for (final UnitRemote<?> unit : unitList) { printed = check(unit) || printed; } if (!printed) { System.out.println( StringProcessor.fillWithSpaces("Unit Connections", LABEL_RANGE, Alignment.RIGHT) + " " + AnsiColor.colorize(OK, AnsiColor.ANSI_GREEN)); } } } catch (InterruptedException ex) { System.out.println("killed"); System.exit(253); return; } catch (Exception ex) { ExceptionPrinter.printHistory(new CouldNotPerformException("Could not validate system!", ex), System.err); System.exit(254); } System.out.println(); System.out.println("=============================================================="); System.out.print("=== "); switch (errorCounter) { case 0: System.out.print(AnsiColor.colorize("VALIDATION SUCCESSFUL", AnsiColor.ANSI_GREEN)); break; default: System.out.print(errorCounter + " " + AnsiColor .colorize("ERROR" + (errorCounter > 1 ? "S" : "") + " DETECTED", AnsiColor.ANSI_RED)); break; } System.out.println(" average ping is " + AnsiColor.colorize(pingFormat.format(getGlobalPing()), AnsiColor.ANSI_CYAN) + " milli"); System.out.println("=============================================================="); System.out.println(); System.exit(Math.min(errorCounter, 200)); }