List of usage examples for org.apache.commons.lang3 BooleanUtils or
public static Boolean or(final Boolean... array)
Performs an or on an array of Booleans.
BooleanUtils.or(Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE) = Boolean.TRUE BooleanUtils.or(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE) = Boolean.FALSE
From source file:it.unimi.dsi.webgraph.algo.HyperBall.java
/** Performs a new iteration of HyperBall. */ public void iterate() throws IOException { ensureOpen();// ww w .j av a 2s .c o m try { iteration++; // Let us record whether the previous computation was systolic or local. final boolean previousWasSystolic = systolic; final boolean previousWasLocal = local; /* If less than one fourth of the nodes have been modified, and we have the transpose, * it is time to pass to a systolic computation. */ systolic = gotTranspose && iteration > 0 && modified.get() < numNodes / 4; /* Non-systolic computations add up the value of all counter. * Systolic computations modify the last value by compensating for each modified counter. */ current = systolic ? last : 0; // If we completed the last iteration in pre-local mode, we MUST run in local mode. local = preLocal; // We run in pre-local mode if we are systolic and few nodes where modified. preLocal = systolic && modified.get() < .1 * numNodes * numNodes / numArcs; info("Starting " + (systolic ? "systolic iteration (local: " + local + "; pre-local: " + preLocal + ")" : "standard " + (external ? "external " : "") + "iteration")); if (!external) { if (previousWasLocal) for (int x : localCheckList) modifiedResultCounter[x] = false; else BooleanArrays.fill(modifiedResultCounter, false); assert !BooleanUtils.or(modifiedResultCounter); } if (local) { /* In case of a local computation, we convert the set of must-be-checked for the * next iteration into a check list. */ localCheckList = localNextMustBeChecked.toIntArray(); Arrays.sort(localCheckList); localNextMustBeChecked.clear(); } else if (systolic) { // Systolic, non-local computations store the could-be-modified set implicitly into this array. BooleanArrays.fill(nextMustBeChecked, false); // If the previous computation wasn't systolic, we must assume that all registers could have changed. if (!previousWasSystolic) BooleanArrays.fill(mustBeChecked, true); } adaptiveGranularity = granularity; if (numberOfThreads > 1 && !local) { if (iteration > 0) { adaptiveGranularity = (long) Math.min(Math.max(1, numNodes / numberOfThreads), granularity * (numNodes / Math.max(1., modified()))); adaptiveGranularity = (adaptiveGranularity + Long.SIZE - 1) & ~(Long.SIZE - 1); } info("Adaptive granularity for this iteration: " + adaptiveGranularity); } modified.set(0); totalIoMillis = 0; numberOfWrites = 0; final ProgressLogger npl = pl == null ? null : new ProgressLogger(LOGGER, 1, TimeUnit.MINUTES, "arcs"); if (npl != null) { arcs.set(0); npl.expectedUpdates = systolic || local ? -1 : numArcs; npl.start("Scanning graph..."); } nodes.set(0); nextArcs = nextNode = 0; unwritten.set(0); if (external) fileChannel.position(0); // Start all threads. lock.lock(); try { phase = 0; aliveThreads = numberOfThreads; start.signalAll(); // Wait for all threads to complete their tasks, logging some stuff in the mean time. while (aliveThreads != 0) { allWaiting.await(1, TimeUnit.MINUTES); if (threadThrowable != null) throw new RuntimeException(threadThrowable); final int aliveThreads = this.aliveThreads; if (npl != null && aliveThreads != 0) { if (arcs.longValue() != 0) npl.set(arcs.longValue()); if (external && numberOfWrites > 0) { final long time = npl.millis(); info("Writes: " + numberOfWrites + "; per second: " + Util.format(1000.0 * numberOfWrites / time)); info("I/O time: " + Util.format((totalIoMillis / 1000.0)) + "s; per write: " + (totalIoMillis / 1000.0) / numberOfWrites + "s"); } if (aliveThreads != 0) info("Alive threads: " + aliveThreads + " (" + Util.format(100.0 * aliveThreads / numberOfThreads) + "%)"); } } } finally { lock.unlock(); } if (npl != null) { npl.done(arcs.longValue()); if (!external) info("Unwritten counters: " + Util.format(unwritten.intValue()) + " (" + Util.format(100.0 * unwritten.intValue() / numNodes) + "%)"); info("Unmodified counters: " + Util.format(numNodes - modified.intValue()) + " (" + Util.format(100.0 * (numNodes - modified.intValue()) / numNodes) + "%)"); } if (external) { if (npl != null) { npl.itemsName = "counters"; npl.start("Updating counters..."); } // Read into memory the newly computed counters. fileChannel.truncate(fileChannel.position()); fileChannel.position(0); // In pre-local mode, we do not clear modified counters. if (!preLocal) BooleanArrays.fill(modifiedCounter, false); lock.lock(); try { phase = 1; //System.err.println( "Starting phase 1..." ); aliveThreads = numberOfThreads; start.signalAll(); // Wait for all threads to complete the counter update. if (aliveThreads != 0) allWaiting.await(); if (threadThrowable != null) throw new RuntimeException(threadThrowable); } finally { lock.unlock(); } if (npl != null) { npl.count = modified(); npl.done(); } } else { // Switch the bit vectors. for (int i = 0; i < bits.length; i++) { if (npl != null) npl.update(bits[i].length); final LongBigList r = registers[i]; registers[i] = resultRegisters[i]; resultRegisters[i] = r; final long[] b = bits[i]; bits[i] = resultBits[i]; resultBits[i] = b; } // Switch modifiedCounters and modifiedResultCounters. final boolean[] t = modifiedCounter; modifiedCounter = modifiedResultCounter; modifiedResultCounter = t; } if (systolic) { // Switch mustBeChecked and nextMustBeChecked. final boolean[] t = mustBeChecked; mustBeChecked = nextMustBeChecked; nextMustBeChecked = t; } last = current; /* We enforce monotonicity. Non-monotonicity can only be caused * by approximation errors. */ final double lastOutput = neighbourhoodFunction.getDouble(neighbourhoodFunction.size() - 1); if (current < lastOutput) current = lastOutput; relativeIncrement = current / lastOutput; if (pl != null) { pl.logger().info("Pairs: " + current + " (" + current * 100.0 / squareNumNodes + "%)"); pl.logger().info("Absolute increment: " + (current - lastOutput)); pl.logger().info("Relative increment: " + relativeIncrement); } neighbourhoodFunction.add(current); if (pl != null) pl.updateAndDisplay(); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:org.sejda.cli.transformer.MergeCliArgumentsTransformer.java
private MultiplePdfMergeInputAdapter extractPdfMergeInputs(MergeTaskCliArguments taskCliArguments) { // input files can be specified in 3 ways: explicitly, via a folder or via a config file List<PdfFileSource> inputFiles = null; if (taskCliArguments.isDirectory()) { if (taskCliArguments.isMatchingRegEx()) { inputFiles = taskCliArguments.getDirectory().filter(taskCliArguments.getMatchingRegEx()) .getFileSourceList(); } else {/*from w ww . j a v a 2s .c o m*/ inputFiles = taskCliArguments.getDirectory().getFileSourceList(); } } else if (taskCliArguments.isFiles()) { inputFiles = extractFiles(taskCliArguments.getFiles()); } else if (taskCliArguments.isFilesListConfig()) { inputFiles = taskCliArguments.getFilesListConfig().getFileSourceList(); } if (!BooleanUtils.or(new boolean[] { taskCliArguments.isDirectory(), taskCliArguments.isFiles(), taskCliArguments.isFilesListConfig() })) { throw new SejdaRuntimeException( "No option given for input. Please use one of the following options: --directory --filesListConfig --file"); } if (!BooleanUtils.xor(new boolean[] { taskCliArguments.isDirectory(), taskCliArguments.isFiles(), taskCliArguments.isFilesListConfig() })) { throw new SejdaRuntimeException( "Too many options given for input. Please use only one of the following options: --directory --filesListConfig --file"); } if (inputFiles == null) { throw new SejdaRuntimeException("No input files specified"); } MultiplePdfMergeInputAdapter mergeInputsAdapter = new MultiplePdfMergeInputAdapter(inputFiles, taskCliArguments.getPageSelection().ranges()); return mergeInputsAdapter; }
From source file:yoyo.framework.standard.shared.commons.lang.BooleanUtilsTest.java
@Test public void test() { assertThat(BooleanUtils.and(new boolean[] { true }), is(true)); assertThat(BooleanUtils.and(new boolean[] { true, false }), is(false)); assertThat(BooleanUtils.isFalse(false), is(true)); assertThat(BooleanUtils.isNotFalse(false), is(false)); assertThat(BooleanUtils.isNotTrue(true), is(false)); assertThat(BooleanUtils.isTrue(true), is(true)); assertThat(BooleanUtils.negate(Boolean.FALSE), is(true)); assertThat(BooleanUtils.or(new boolean[] { true }), is(true)); assertThat(BooleanUtils.or(new boolean[] { true, false }), is(true)); assertThat(BooleanUtils.toBoolean(Boolean.TRUE), is(true)); assertThat(BooleanUtils.toBoolean(0), is(false)); assertThat(BooleanUtils.toBoolean(1), is(true)); assertThat(BooleanUtils.toBoolean((String) null), is(false)); assertThat(BooleanUtils.toBoolean("true"), is(true)); assertThat(BooleanUtils.toBoolean("hoge"), is(false)); assertThat(BooleanUtils.toBooleanDefaultIfNull(null, false), is(false)); assertThat(BooleanUtils.toBooleanObject(0), is(Boolean.FALSE)); assertThat(BooleanUtils.toBooleanObject(1), is(Boolean.TRUE)); assertThat(BooleanUtils.toInteger(true), is(1)); assertThat(BooleanUtils.toInteger(false), is(0)); assertThat(BooleanUtils.toIntegerObject(true), is(Integer.valueOf(1))); assertThat(BooleanUtils.toIntegerObject(false), is(Integer.valueOf(0))); assertThat(BooleanUtils.toString(true, "true", "false"), is("true")); assertThat(BooleanUtils.toString(false, "true", "false"), is("false")); assertThat(BooleanUtils.toStringOnOff(true), is("on")); assertThat(BooleanUtils.toStringOnOff(false), is("off")); assertThat(BooleanUtils.toStringTrueFalse(true), is("true")); assertThat(BooleanUtils.toStringTrueFalse(false), is("false")); assertThat(BooleanUtils.toStringYesNo(true), is("yes")); assertThat(BooleanUtils.toStringYesNo(false), is("no")); assertThat(BooleanUtils.xor(new boolean[] { true }), is(true)); assertThat(BooleanUtils.xor(new boolean[] { true, false }), is(true)); assertThat(BooleanUtils.xor(new boolean[] { true, true }), is(false)); }