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 byte[] copyOfRange(byte[] original, int from, int to) { int newLength = to - from; if (newLength < 0) throw new IllegalArgumentException(from + " > " + to); byte[] copy = new byte[newLength]; System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy;/* w ww . j a va 2 s .c o m*/ }
From source file:Main.java
/** * Returns a rounded bitmap using specified bitmap image. * // w w w . j a v a2s.c om * @param scaleBitmapImage bitmap to make round image. * @return rounded bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) { if (scaleBitmapImage == null) return null; int targetWidth = (int) DP; int targetHeight = (int) DP; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); Paint p = new Paint(); p.setAntiAlias(true); canvas.clipPath(path); canvas.drawBitmap(scaleBitmapImage, new Rect(0, 0, scaleBitmapImage.getWidth(), scaleBitmapImage.getHeight()), new Rect(0, 0, targetWidth, targetHeight), p); p.setARGB(255, 16, 18, 16); scaleBitmapImage.recycle(); return targetBitmap; }
From source file:Main.java
/** * Make INTERSECTION operation between 2 {@link Collection} * * @param a//from w w w . java 2 s.c o m * @param b * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static Collection intersection(final Collection a, final Collection b) { final ArrayList list = new ArrayList(); final Map mapa = getCardinalityMap(a); final Map mapb = getCardinalityMap(b); final Set elts = new LinkedHashSet(a); elts.addAll(b); final Iterator it = elts.iterator(); while (it.hasNext()) { final Object obj = it.next(); for (int i = 0, m = Math.min(getFreq(obj, mapa), getFreq(obj, mapb)); i < m; i++) { list.add(obj); } } return list; }
From source file:Main.java
/** * Scale down the bitmap in order to make color analysis faster. Taken from Palette. */// ww w .j a v a2s. c om private static Bitmap scaleBitmapDown(Bitmap bitmap) { final int CALCULATE_BITMAP_MIN_DIMENSION = 100; final int minDimension = Math.min(bitmap.getWidth(), bitmap.getHeight()); if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION) { // If the bitmap is small enough already, just return it return bitmap; } final float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float) minDimension; return Bitmap.createScaledBitmap(bitmap, Math.round(bitmap.getWidth() * scaleRatio), Math.round(bitmap.getHeight() * scaleRatio), false); }
From source file:Main.java
/** * Test a value in specified range, returning minimum if it's below, and maximum if it's above * * @param value Value to test/*from w w w .j a v a2s . c om*/ * @param min Minimum value of range * @param max Maximum value of range * @return value if it's between min and max, min if it's below, max if it's above */ public static float clamp(float value, float min, float max) { return Math.max(min, Math.min(max, value)); }
From source file:Main.java
/** * Create a new array by slicing a subset out of an existing one. * * @param <T> the type of the array elements * @param array the array//from w ww. j av a 2 s . c o m * @param off the starting offset of the slice * @param len the length of the slice. * @return a slice of the array starting at the given offset and with the specified length */ public static <T extends Object> T[] slice(T[] array, int off, int len) { len = Math.min(len, array.length - off); T[] res = (T[]) Array.newInstance(array.getClass().getComponentType(), len); System.arraycopy(array, off, res, 0, len); return res; }
From source file:Main.java
public static float clamp(final float num, final float bound1, final float bound2) { final float max = Math.max(bound1, bound2), min = Math.min(bound1, bound2); return Math.max(Math.min(num, max), min); }
From source file:Main.java
static int computeMeasureSize(int measureSpec, int defSize) { final int mode = View.MeasureSpec.getMode(measureSpec); switch (mode) { case View.MeasureSpec.EXACTLY: return View.MeasureSpec.getSize(measureSpec); case View.MeasureSpec.AT_MOST: return Math.min(defSize, View.MeasureSpec.getSize(measureSpec)); default://from w w w . j av a 2s. com return defSize; } }
From source file:Main.java
static long calculateApiDiskCacheSize(File dir) { long size = MIN_DISK_API_CACHE_SIZE; try {/*from w w w . j a v a 2 s . com*/ StatFs statFs = new StatFs(dir.getAbsolutePath()); long available; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { available = statFs.getBlockCountLong() * statFs.getBlockSizeLong(); } else { available = ((long) statFs.getBlockCount()) * statFs.getBlockSize(); } // Target 2% of the total space. size = available / 50; } catch (IllegalArgumentException ignored) { } // Bound inside min/max size for disk cache. return Math.max(Math.min(size, MAX_DISK_API_CACHE_SIZE), MIN_DISK_API_CACHE_SIZE); }
From source file:Main.java
/** * Utility to return a view's standard measurement. Uses the * supplied size when constraints are given. Attempts to * hold to the desired size unless it conflicts with provided * constraints./*from w w w . j av a 2 s .co m*/ * * @param measureSpec Constraints imposed by the parent * @param contentSize Desired size for the view * @return The size the view should be. */ public static int getMeasurement(int measureSpec, int contentSize) { int specMode = View.MeasureSpec.getMode(measureSpec); int specSize = View.MeasureSpec.getSize(measureSpec); int resultSize = 0; switch (specMode) { case View.MeasureSpec.UNSPECIFIED: //Big as we want to be resultSize = contentSize; break; case View.MeasureSpec.AT_MOST: //Big as we want to be, up to the spec resultSize = Math.min(contentSize, specSize); break; case View.MeasureSpec.EXACTLY: //Must be the spec size resultSize = specSize; break; } return resultSize; }