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 boolean pointOnRect(double x, double y, double x1, double y1, double x2, double y2) { if (x >= Math.min(x1, x2) && x <= Math.max(x1, x2) && y >= Math.min(y1, y2) && y <= Math.max(y1, y2)) { return true; } else {// w w w . j ava 2s. c o m return false; } }
From source file:Main.java
public static Bitmap getRoundedCornerBitmap3(Drawable imageDrawable, int radius) { Bitmap d = ((BitmapDrawable) imageDrawable).getBitmap(); BitmapShader shader = new BitmapShader(d, TileMode.CLAMP, TileMode.CLAMP); int size = Math.min(d.getWidth(), d.getHeight()); Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); RectF outerRect = new RectF(0, 0, size, size); // float cornerRadius = radius; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShader(shader);/*from w w w . j a v a2 s.c o m*/ paint.setAntiAlias(true); paint.setColor(Color.RED); canvas.drawCircle(outerRect.centerX(), outerRect.centerY(), d.getWidth() / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); imageDrawable.setBounds(0, 0, size, size); Canvas canvas1 = new Canvas(output); RectF outerRect1 = new RectF(0, 0, size, size); Paint paint1 = new Paint(Paint.ANTI_ALIAS_FLAG); paint1.setShader(shader); paint1.setAntiAlias(true); paint1.setColor(Color.RED); canvas1.drawCircle(outerRect1.centerX(), outerRect1.centerY(), d.getWidth() / 2, paint); paint1.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); return output; }
From source file:Main.java
public static char[] copyOf(char[] original, int newLength) { char[] copy = new char[newLength]; System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy;/*from w w w. j ava 2 s. com*/ }
From source file:Main.java
public static int setColorAlpha(int color, float alpha) { int alpha_int = Math.min(Math.max((int) (alpha * 255.0f), 0), 255); return Color.argb(alpha_int, Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
public static int clamp(int value, int low, int high) { return Math.min(Math.max(value, low), high); }
From source file:Main.java
/** * Scrolls the given component by its unit or block increment in the given direction (actually a scale factor, so use +1 or -1). * Useful for implementing behavior like in Apple's Mail where page up/page down in the list cause scrolling in the text. *///w ww. j a va 2 s . c om public static void scroll(JComponent c, boolean byBlock, int direction) { JScrollPane scrollPane = (JScrollPane) SwingUtilities.getAncestorOfClass(JScrollPane.class, c); JScrollBar scrollBar = scrollPane.getVerticalScrollBar(); int increment = byBlock ? scrollBar.getBlockIncrement(direction) : scrollBar.getUnitIncrement(direction); int newValue = scrollBar.getValue() + direction * increment; newValue = Math.min(newValue, scrollBar.getMaximum()); newValue = Math.max(newValue, scrollBar.getMinimum()); scrollBar.setValue(newValue); }
From source file:Main.java
public static String[] copyOf(String[] source, int newSize) { String[] result = new String[newSize]; newSize = Math.min(source.length, newSize); System.arraycopy(source, 0, result, 0, newSize); return result; }
From source file:Main.java
public static Bitmap scaleBitmapToFitInView(View view, String imagePath) { // Get the dimensions of the View int targetW = view.getWidth(); int targetH = view.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(imagePath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / targetW, photoH / targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true;/* w w w .ja v a2 s. com*/ Bitmap bitmap = BitmapFactory.decodeFile(imagePath, bmOptions); return bitmap; }
From source file:Main.java
public static float min(float value1, float value2) { return Math.min(value1, value2); }
From source file:Main.java
/** * Gets a sublist of a list, truncated at the end of the list if too many elements are selected. * This behaves exactly like List.subList, including all notes in its Javadoc concerning * structural modification of the backing List, etc. with one difference: if the end index is * beyond the end of the list, instead of throwing an exception, the sublist simply stops at the * end of the list. After the fifth or so time writing this idiom, it seems worth having a * function for. :-)//from w ww .j a v a 2s. c o m */ public static <T> List<T> truncatedSubList(List<T> inList, int start, int end) { // List.sublist will do our error checking for us final int limit = Math.min(end, inList.size()); return inList.subList(start, limit); }