Example usage for org.apache.commons.collections.comparators BooleanComparator compare

List of usage examples for org.apache.commons.collections.comparators BooleanComparator compare

Introduction

In this page you can find the example usage for org.apache.commons.collections.comparators BooleanComparator compare.

Prototype

public int compare(Boolean b1, Boolean b2) 

Source Link

Document

Compares two non-null Boolean objects according to the value of #sortsTrueFirst() .

Usage

From source file:org.openbase.bco.manager.util.launch.BCOSystemValidator.java

public static void main(String[] args) {
    BCO.printLogo();/*w  w  w  .j a  v a2 s  .  co  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));
}