List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
/** * Returns the index of the largest value in an array that is less than (or optionally equal to) * a specified key./* ww w . ja va2 s .c o m*/ * <p> * The search is performed using a binary search algorithm, and so the array must be sorted. * * @param a The array to search. * @param key The key being searched for. * @param inclusive If the key is present in the array, whether to return the corresponding index. * If false then the returned index corresponds to the largest value in the array that is * strictly less than the key. * @param stayInBounds If true, then 0 will be returned in the case that the key is smaller than * the smallest value in the array. If false then -1 will be returned. */ public static int binarySearchFloor(long[] a, long key, boolean inclusive, boolean stayInBounds) { int index = Arrays.binarySearch(a, key); index = index < 0 ? -(index + 2) : (inclusive ? index : (index - 1)); return stayInBounds ? Math.max(0, index) : index; }
From source file:org.jfree.chart.demo.DeviationRendererDemo3.java
private static XYDataset createDataset() { YIntervalSeries series1 = new YIntervalSeries("Band A"); YIntervalSeries series2 = new YIntervalSeries("Band B"); YIntervalSeries series3 = new YIntervalSeries("Band C"); Object obj = new Quarter(1, 2005); double d = 0.0D; for (int i = 0; i <= 12; i++) { d += (Math.random() - 0.5D) * 15D; series1.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d + 10D, Math.max(50D, d + 30D)); series2.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d - 10D, d + 10D); series3.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, Math.min(-50D, d - 30D), d - 10D); obj = ((RegularTimePeriod) (obj)).next(); }/* www .j av a2s.c o m*/ YIntervalSeriesCollection dataset = new YIntervalSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); return dataset; }
From source file:Main.java
/** * Determine the proper initial size for a new collection in order for it to hold the given a number of elements. * Specifically we want to account for load size and load factor to prevent immediate resizing. * * @param numberOfElements The number of elements to be stored. * * @return The proper size.//from w w w. ja v a 2s . com */ public static int determineProperSizing(int numberOfElements) { int actual = ((int) (numberOfElements / LOAD_FACTOR)) + 1; return Math.max(actual, MINIMUM_INITIAL_CAPACITY); }
From source file:Main.java
/** * Encodes an ImageView into a base-64 byte array representation. Encoding compression depends * on the quality parameter passed. 0 is the most compressed (lowest quality) and 100 is the * least compressed (highest quality).//from www.ja v a 2 s . c o m * * @param context * @param res the resource id of an ImageView * @param quality The amount of compression, where 0 is the lowest quality and 100 is the * highest * @return the raw base-64 image data compressed accordingly */ public static byte[] encodeBase64Image(Context context, int res, int quality) { // ensure quality is between 0 and 100 (inclusive) quality = Math.max(LOWEST_QUALITY, Math.min(HIGHEST_QUALITY, quality)); Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), res); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, quality, stream); return stream.toByteArray(); }
From source file:Main.java
public static int getMaxTextureSize() { // Safe minimum default size final int IMAGE_MAX_BITMAP_DIMENSION = 2048; // Get EGL Display EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); // Initialise int[] version = new int[2]; egl.eglInitialize(display, version); // Query total number of configurations int[] totalConfigurations = new int[1]; egl.eglGetConfigs(display, null, 0, totalConfigurations); // Query actual list configurations EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]]; egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations); int[] textureSize = new int[1]; int maximumTextureSize = 0; // Iterate through all the configurations to located the maximum texture size for (int i = 0; i < totalConfigurations[0]; i++) { // Only need to check for width since opengl textures are always squared egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize); // Keep track of the maximum texture size if (maximumTextureSize < textureSize[0]) maximumTextureSize = textureSize[0]; }/*w ww . j a va2s . c o m*/ // Release egl.eglTerminate(display); // Return largest texture size found, or default return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION); }
From source file:Main.java
/** * Positions the specified frame at a relative position in the screen, where 50% is considered to be the center of the * screen.// w ww . ja v a 2s . co m * * @param frame the frame. * @param horizontalPercent the relative horizontal position of the frame (0.0 to 1.0, where 0.5 is the center of the * screen). * @param verticalPercent the relative vertical position of the frame (0.0 to 1.0, where 0.5 is the center of the * screen). */ public static void positionFrameOnScreen(final Window frame, final double horizontalPercent, final double verticalPercent) { final Rectangle s = frame.getGraphicsConfiguration().getBounds(); final Dimension f = frame.getSize(); final int spaceOnX = Math.max(s.width - f.width, 0); final int spaceOnY = Math.max(s.height - f.height, 0); final int x = (int) (horizontalPercent * spaceOnX) + s.x; final int y = (int) (verticalPercent * spaceOnY) + s.y; frame.setBounds(x, y, f.width, f.height); frame.setBounds(s.intersection(frame.getBounds())); }
From source file:Main.java
/** * Computes the lightness value in HSL standard for the given color. *//*from w w w . j a v a 2s. c o m*/ private static float getLightnessForColor(int color) { int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); int largest = Math.max(red, Math.max(green, blue)); int smallest = Math.min(red, Math.min(green, blue)); int average = (largest + smallest) / 2; return average / 255.0f; }
From source file:FastByteArrayOutputStream.java
/** * Ensures that we have a large enough buffer for the given size. *///ww w . j a va 2s . c o m private void verifyBufferSize(int sz) { if (sz > buf.length) { byte[] old = buf; buf = new byte[Math.max(sz, 2 * buf.length)]; System.arraycopy(old, 0, buf, 0, old.length); old = null; } }
From source file:Main.java
public static Bitmap formatBitmap(Bitmap bitmap, int width, int height) { int wh = Math.max(bitmap.getWidth(), bitmap.getHeight()); Bitmap mBitmap = Bitmap.createBitmap(wh, wh, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mBitmap); canvas.drawBitmap(bitmap, -(bitmap.getWidth() - wh) / 2, -(bitmap.getHeight() - wh) / 2, null); bitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true); return bitmap; }
From source file:Main.java
/** * Returns the contrast ratio between {@code foreground} and {@code background}. * {@code background} must be opaque./*ww w.java 2 s.c o m*/ * <p> * Formula defined * <a href="http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef">here</a>. */ public static double calculateContrast(int foreground, int background) { if (Color.alpha(background) != 255) { throw new IllegalArgumentException( "background can not be translucent: #" + Integer.toHexString(background)); } if (Color.alpha(foreground) < 255) { // If the foreground is translucent, composite the foreground over the background foreground = compositeColors(foreground, background); } final double luminance1 = calculateLuminance(foreground) + 0.05; final double luminance2 = calculateLuminance(background) + 0.05; // Now return the lighter luminance divided by the darker luminance return Math.max(luminance1, luminance2) / Math.min(luminance1, luminance2); }