List of usage examples for org.apache.commons.lang3 Validate inclusiveBetween
@SuppressWarnings("boxing") public static void inclusiveBetween(final double start, final double end, final double value)
From source file:com.offbynull.peernetic.debug.visualizer.VisualizerUtils.java
/** * Creates a random point within a rectangle. * @param width rectangle width//from www .j a v a2 s . co m * @param height rectangle height * @return new random point within rectangle specified by {@code width} and {@code height} * @throws IllegalArgumentException if any argument is negative or a special double value (e.g. NaN/infinite/etc..) */ public static Point randomPointInRectangle(double width, double height) { Validate.inclusiveBetween(0.0, Double.MAX_VALUE, width); Validate.inclusiveBetween(0.0, Double.MAX_VALUE, height); return new Point((int) (Math.random() * width), (int) (Math.random() * height)); }
From source file:io.github.seiferma.jameica.hibiscus.dkb.creditcard.util.DateUtils.java
public static Date getDateAgo(Unit unit, int amount) { Validate.inclusiveBetween(0, Integer.MAX_VALUE, amount); Calendar calendar = new GregorianCalendar(); calendar.add(unit.getCalendarField(), -amount); return calendar.getTime(); }
From source file:com.offbynull.portmapper.common.ProcessUtils.java
/** * Run a process and dump the stdout stream to a string. * @param timeout maximum amount of time the process can take to run * @param command command/*from ww w .ja v a 2 s. c o m*/ * @param args arguments * @return stdout from the process dumped to a string * @throws IOException if the process encounters an error * @throws NullPointerException if any arguments are {@code null} or contains {@code null} * @throws IllegalArgumentException any numeric argument is negative */ public static String runProcessAndDumpOutput(long timeout, String command, String... args) throws IOException { Validate.notNull(command); Validate.noNullElements(args); Validate.inclusiveBetween(0L, Long.MAX_VALUE, timeout); String[] pbCmd = new String[args.length + 1]; pbCmd[0] = command; System.arraycopy(args, 0, pbCmd, 1, args.length); ProcessBuilder builder = new ProcessBuilder(pbCmd); final AtomicBoolean failedFlag = new AtomicBoolean(); Timer timer = new Timer("Process timeout timer", true); Process proc = null; try { proc = builder.start(); final Process finalProc = proc; timer.schedule(new TimerTask() { @Override public void run() { failedFlag.set(true); finalProc.destroy(); } }, timeout); String ret = IOUtils.toString(proc.getInputStream()); if (failedFlag.get()) { throw new IOException("Process failed"); } return ret; } finally { if (proc != null) { proc.destroy(); } timer.cancel(); timer.purge(); } }
From source file:com.offbynull.peernetic.debug.visualizer.VisualizerUtils.java
/** * Creates point on a circle.//w w w.ja v a2 s .c o m * @param radius radius of circle * @param percentage 0 to 1 percentage of where point is on circle -- 0.0 indicates that the point is at the top middle * @return new point on circle specified by {@code radius} and {@code percentage} * @throws IllegalArgumentException if {@code radius} is negative or a special double value (e.g. NaN/infinite/etc..), or if * {@code percentage} isn't between {@code 0.0 - 1.0} */ public static Point pointOnCircle(double radius, double percentage) { Validate.inclusiveBetween(0.0, Double.MAX_VALUE, radius); Validate.inclusiveBetween(0.0, 1.0, percentage); double angle = percentage * Math.PI * 2.0; angle -= Math.PI / 2.0; // adjust so that percentage 0.0 is at top middle, if not it'ld be at middle right double y = (Math.sin(angle) * radius) + radius; // NOPMD double x = (Math.cos(angle) * radius) + radius; // NOPMD return new Point((int) x, (int) y); }
From source file:com.offbynull.portmapper.natpmp.NatPmpRequest.java
/** * Constructs a {@link NatPmpRequest} object. * @param op NAT-PMP opcode//w ww . j a v a 2s . c o m * @throws IllegalArgumentException if any numeric argument is negative, or if {@code op > 127} */ public NatPmpRequest(int op) { Validate.inclusiveBetween(0, 127, op); this.op = op; }
From source file:com.offbynull.portmapper.MappedPort.java
/** * Constructs a {@link MappedPort} object. * @param internalPort internal port//from w ww. j ava 2 s . c o m * @param externalPort external port * @param externalAddress external address * @param portType port type * @param duration mapping lifetime * @throws NullPointerException if any argument is {@code null} * @throws IllegalArgumentException if any numeric argument is non-positive, or if {@code internalPort > 65535 || externalPort > 65535} */ public MappedPort(int internalPort, int externalPort, InetAddress externalAddress, PortType portType, long duration) { Validate.inclusiveBetween(1, 65535, internalPort); Validate.inclusiveBetween(1, 65535, externalPort); Validate.notNull(externalAddress); Validate.notNull(portType); Validate.inclusiveBetween(0L, Long.MAX_VALUE, duration); this.internalPort = internalPort; this.externalPort = externalPort; this.externalAddress = externalAddress; this.portType = portType; this.lifetime = duration; }
From source file:com.joyent.manta.client.crypto.AesCbcCipherDetails.java
@Override public long ciphertextSize(final long plaintextSize) { Validate.inclusiveBetween(0L, Long.MAX_VALUE, plaintextSize); int blockBytes = getBlockSizeInBytes(); int tagOrHmacBytes = getAuthenticationTagOrHmacLengthInBytes(); byte[] iv = this.getCipher().getIV(); boolean hasIV = (iv != null && iv.length > 0); return calculateContentLength(plaintextSize, blockBytes, tagOrHmacBytes, hasIV); }
From source file:com.joyent.manta.client.crypto.AesCtrCipherDetails.java
@Override public long ciphertextSize(final long plaintextSize) { Validate.inclusiveBetween(0L, Long.MAX_VALUE, plaintextSize); return plaintextSize + getAuthenticationTagOrHmacLengthInBytes(); }
From source file:com.joyent.manta.client.crypto.AesCtrCipherDetails.java
@Override public long plaintextSize(final long ciphertextSize) { Validate.inclusiveBetween(0L, Long.MAX_VALUE, ciphertextSize); return ciphertextSize - getAuthenticationTagOrHmacLengthInBytes(); }
From source file:com.joyent.manta.client.crypto.AesCbcCipherDetails.java
@Override public long plaintextSize(final long ciphertextSize) { Validate.inclusiveBetween(0L, Long.MAX_VALUE, ciphertextSize); if (ciphertextSize == getBlockSizeInBytes() + getAuthenticationTagOrHmacLengthInBytes()) { return 0L; }//from w ww . ja va 2 s . com return ciphertextSize - getBlockSizeInBytes() - getAuthenticationTagOrHmacLengthInBytes(); }