List of usage examples for java.lang Math min
@HotSpotIntrinsicCandidate public static double min(double a, double b)
From source file:Main.java
public static <A, B> List<Pair<A, B>> zip(final List<A> as, final List<B> bs) { return IntStream.range(0, Math.min(as.size(), bs.size())).mapToObj(i -> new Pair<>(as.get(i), bs.get(i))) .collect(Collectors.toList()); }
From source file:Main.java
private static int computeSampleSize(int width, int height, int desiredWidth, int desiredHeight) { double wr = (double) width / desiredWidth; double hr = (double) height / desiredHeight; double ratio = Math.min(wr, hr); float n = 1.0f; while ((n * 2) <= ratio) { n *= 2;/* w ww.j a v a2 s. c om*/ } return (int) n; }
From source file:Main.java
private static int normalizeDouble(double f) { double f2 = Math.max(0.0, Math.min(1.0, f)); return (int) Math.floor(f2 == 1.0 ? COLOR_FLOAT_TO_INT_FACTOR : f2 * (COLOR_FLOAT_TO_INT_FACTOR + 1)); }
From source file:Main.java
private static Rect getCollisionBounds(Rect rect1, Rect rect2) { int left = (int) Math.max(rect1.left, rect2.left); int top = (int) Math.max(rect1.top, rect2.top); int right = (int) Math.min(rect1.right, rect2.right); int bottom = (int) Math.min(rect1.bottom, rect2.bottom); return new Rect(left, top, right, bottom); }
From source file:Main.java
public static int[] copyOfRange(int[] original, int start, int end) { if (start <= end) { if (original.length >= start && 0 <= start) { int length = end - start; int copyLength = Math.min(length, original.length - start); int[] copy = new int[length]; System.arraycopy(original, start, copy, 0, copyLength); return copy; }//w w w . j av a 2s . c om throw new ArrayIndexOutOfBoundsException(); } throw new IllegalArgumentException(); }
From source file:Main.java
public static String difference(String xpath1, String xpath2) { String[] paths1 = split(xpath1); String[] paths2 = split(xpath2); int length = Math.min(paths1.length, paths2.length); int index = 0; while (index < length && paths1[index].equals(paths2[index])) { index++;/*from w w w . j a v a2s .c om*/ } StringBuffer b = new StringBuffer(); for (int i = 0; i < index; i++) { b.append(paths1[i]); } while (index < paths1.length) { b.append(paths1[index++]); b.append('/'); } return b.toString(); }
From source file:Main.java
public static Bitmap getCircularBitmapImage(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() - size) / 2; int y = (source.getHeight() - size) / 2; Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size); if (squaredBitmap != source) { source.recycle();//w w w . ja v a 2 s . c o m } Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); paint.setShader(shader); paint.setAntiAlias(true); float r = size / 2f; canvas.drawCircle(r, r, r, paint); squaredBitmap.recycle(); return bitmap; }
From source file:Main.java
private static Bitmap getScaleLogo(Bitmap logo, int w, int h) { if (logo == null) return null; Matrix matrix = new Matrix(); float scaleFactor = Math.min(w * 1.0f / 5 / logo.getWidth(), h * 1.0f / 5 / logo.getHeight()); matrix.postScale(scaleFactor, scaleFactor); Bitmap result = Bitmap.createBitmap(logo, 0, 0, logo.getWidth(), logo.getHeight(), matrix, true); return result; }
From source file:Main.java
public static int lightenColor(int color, float factor) { float r = Color.red(color) * factor; float g = Color.green(color) * factor; float b = Color.blue(color) * factor; int ir = Math.min(255, (int) r); int ig = Math.min(255, (int) g); int ib = Math.min(255, (int) b); int ia = Color.alpha(color); return (Color.argb(ia, ir, ig, ib)); }
From source file:Main.java
public static long parseNumber(byte[] buf, int len, boolean bigEndian) { if (buf == null || buf.length == 0) { throw new IllegalArgumentException("byte array is null or empty!"); }/*from w w w . java 2 s.c o m*/ int mlen = Math.min(len, buf.length); long r = 0; if (bigEndian) for (int i = 0; i < mlen; i++) { r <<= 8; r |= (buf[i] & 0xff); } else for (int i = mlen - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0xff); } return r; }