List of usage examples for java.lang Math max
@HotSpotIntrinsicCandidate public static double max(double a, double b)
From source file:Main.java
private static long calculateDiskCacheSize(final File dir) { long size = MIN_DISK_CACHE_SIZE; try {//from w ww . jav a 2s . com // Target 2% of the total space. size = getAvailable(dir) / 50; } catch (final IllegalArgumentException ignored) { } return Math.max(Math.min(size, MAX_DISK_CACHE_SIZE), MIN_DISK_CACHE_SIZE); }
From source file:Main.java
public static Bitmap rotateBitmap(String path, int orientation, int screenWidth, int screenHeight) { Bitmap bitmap = null;/*from www. ja v a 2 s . co m*/ final int maxWidth = screenWidth / 2; final int maxHeight = screenHeight / 2; try { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); int sourceWidth, sourceHeight; if (orientation == 90 || orientation == 270) { sourceWidth = options.outHeight; sourceHeight = options.outWidth; } else { sourceWidth = options.outWidth; sourceHeight = options.outHeight; } boolean compress = false; if (sourceWidth > maxWidth || sourceHeight > maxHeight) { float widthRatio = (float) sourceWidth / (float) maxWidth; float heightRatio = (float) sourceHeight / (float) maxHeight; options.inJustDecodeBounds = false; if (new File(path).length() > 512000) { float maxRatio = Math.max(widthRatio, heightRatio); options.inSampleSize = (int) maxRatio; compress = true; } bitmap = BitmapFactory.decodeFile(path, options); } else { bitmap = BitmapFactory.decodeFile(path); } if (orientation > 0) { Matrix matrix = new Matrix(); //matrix.postScale(sourceWidth, sourceHeight); matrix.postRotate(orientation); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } sourceWidth = bitmap.getWidth(); sourceHeight = bitmap.getHeight(); if ((sourceWidth > maxWidth || sourceHeight > maxHeight) && compress) { float widthRatio = (float) sourceWidth / (float) maxWidth; float heightRatio = (float) sourceHeight / (float) maxHeight; float maxRatio = Math.max(widthRatio, heightRatio); sourceWidth = (int) ((float) sourceWidth / maxRatio); sourceHeight = (int) ((float) sourceHeight / maxRatio); Bitmap bm = Bitmap.createScaledBitmap(bitmap, sourceWidth, sourceHeight, true); bitmap.recycle(); return bm; } } catch (Exception e) { } return bitmap; }
From source file:IK.G.java
public static double max(double a, double b) { return Math.max(a, b); }
From source file:com.t3.util.math.CappedInteger.java
public void setValue(int value) { this.value = Math.max(Math.min(value, max), min); }
From source file:com.martinkampjensen.thesis.barriers.neighborhood.AbstractNeighborhood.java
public static final int[][] calculateNeighbors(List<Model> models, Neighborhood neighborhood, double maxDistance, boolean allowDebugPrints) { final int nModels = models.size(); final IntList[] lists = new ArrayIntList[nModels]; final int[][] arrays = new int[nModels][]; for (int i = 0; i < nModels; i++) { lists[i] = new ArrayIntList(); }/*from w w w . j a v a2 s . co m*/ // For status. final long calculationsTotal = (long) nModels * (nModels - 1) / 2; final boolean performStatus = (calculationsTotal >= 2500000); final long calculationsTwentieth = Math.max(1, (long) Math.floor(calculationsTotal / 20d)); long calculationsMilestone = calculationsTwentieth; long calculationsDone = 0; if (performStatus) System.err.print("Neighbors calculated: [0%"); for (int i = 0; i < nModels; i++) { final IntList list = lists[i]; final Model first = models.get(i); for (int j = i + 1; j < nModels; j++) { final Model second = models.get(j); if (neighborhood.isNeighbors(first, second, maxDistance)) { list.add(j); lists[j].add(i); } } arrays[i] = list.toArray(); lists[i] = null; // For garbage collection. // For status. if (performStatus) { calculationsDone += nModels - 1 - i; if (calculationsDone >= calculationsMilestone && i != nModels - 1) { System.err.print("..." + (int) (100 * calculationsDone / (double) calculationsTotal) + "%"); if (calculationsDone == calculationsTotal) System.err.println("]"); while (calculationsDone >= calculationsMilestone) calculationsMilestone += calculationsTwentieth; calculationsMilestone = Math.min(calculationsMilestone, calculationsTotal); } } } if (allowDebugPrints) calculateNeighborMeasures(arrays); return arrays; }
From source file:Main.java
/** * Returns a {@link Collection} containing the exclusive disjunction * (symmetric difference) of the given {@link Collection}s. * <p>//www .j a v a 2 s . c o m * The cardinality of each element <i>e</i> in the returned * {@link Collection} will be equal to * <tt>max(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>)) - min(cardinality(<i>e</i>,<i>a</i>),cardinality(<i>e</i>,<i>b</i>))</tt>. * <p> * This is equivalent to * <tt>{@link #subtract subtract}({@link #union union(a,b)},{@link #intersection intersection(a,b)})</tt> * or * <tt>{@link #union union}({@link #subtract subtract(a,b)},{@link #subtract subtract(b,a)})</tt>. */ public static Collection disjunction(final Collection a, final Collection b) { ArrayList list = new ArrayList(); Map mapa = getCardinalityMap(a); Map mapb = getCardinalityMap(b); Set elts = new HashSet(a); elts.addAll(b); Iterator it = elts.iterator(); while (it.hasNext()) { Object obj = it.next(); for (int i = 0, m = ((Math.max(getFreq(obj, mapa), getFreq(obj, mapb))) - (Math.min(getFreq(obj, mapa), getFreq(obj, mapb)))); i < m; i++) { list.add(obj); } } return list; }
From source file:edu.purdue.cc.bionet.ui.CustomTickUnit.java
@Override public String valueToString(double value) { if (Math.round(value) > units.size() - 1) { return ""; }/*from ww w . j av a2 s . c om*/ return this.units.get(Math.max(0, (int) Math.round(value))).toString(); }
From source file:UriUtils.java
/** * Returns the filename for the specified URI. * <p/>// w w w .jav a 2 s . c o m * For example, applyign this method to the URI "<tt>http://www.site.com/articles/article.html</tt>" will * return "<tt>article.html</tt>". * * @param uri The URI for which to return the filename. * @return The filename of the resource represented by the specified URI. * @throws IllegalArgumentException <ul><li>The URI cannot be null.</li><li>A separator character could not be found * in the specified URI.</li><li>The specified URI does not point to a file * resource.</li></ul> */ public static String getFilename(final URI uri) throws IllegalArgumentException { if (uri == null) throw new IllegalArgumentException("The URI cannot be null."); final String path = uri.getRawPath(); final int finalSeparator = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\')); if (finalSeparator == -1) throw new IllegalArgumentException("A separator character could not found in the specified URI."); if (finalSeparator == path.length() - 1) throw new IllegalArgumentException("The specified URI does not point to a file resource."); return path.substring(finalSeparator + 1); }
From source file:Main.java
/** * Transform source Bitmap to targeted width and height. */// w w w. j av a 2 s . c om private static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, int options) { boolean scaleUp = (options & OPTIONS_SCALE_UP) != 0; boolean recycle = (options & OPTIONS_RECYCLE_INPUT) != 0; int deltaX = source.getWidth() - targetWidth; int deltaY = source.getHeight() - targetHeight; if (!scaleUp && (deltaX < 0 || deltaY < 0)) { /* * In this case the bitmap is smaller, at least in one dimension, * than the target. Transform it by placing as much of the image * as possible into the target and leaving the top/bottom or * left/right (or both) black. */ Bitmap b2 = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b2); int deltaXHalf = Math.max(0, deltaX / 2); int deltaYHalf = Math.max(0, deltaY / 2); Rect src = new Rect(deltaXHalf, deltaYHalf, deltaXHalf + Math.min(targetWidth, source.getWidth()), deltaYHalf + Math.min(targetHeight, source.getHeight())); int dstX = (targetWidth - src.width()) / 2; int dstY = (targetHeight - src.height()) / 2; Rect dst = new Rect(dstX, dstY, targetWidth - dstX, targetHeight - dstY); c.drawBitmap(source, src, dst, null); if (recycle) { source.recycle(); } return b2; } float bitmapWidthF = source.getWidth(); float bitmapHeightF = source.getHeight(); float bitmapAspect = bitmapWidthF / bitmapHeightF; float viewAspect = (float) targetWidth / targetHeight; if (bitmapAspect > viewAspect) { float scale = targetHeight / bitmapHeightF; if (scale < .9F || scale > 1F) { scaler.setScale(scale, scale); } else { scaler = null; } } else { float scale = targetWidth / bitmapWidthF; if (scale < .9F || scale > 1F) { scaler.setScale(scale, scale); } else { scaler = null; } } Bitmap b1; if (scaler != null) { // this is used for minithumb and crop, so we want to filter here. b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true); } else { b1 = source; } if (recycle && b1 != source) { source.recycle(); } int dx1 = Math.max(0, b1.getWidth() - targetWidth); // int dy1 = Math.max(0, b1.getHeight() - targetHeight); Bitmap b2 = Bitmap.createBitmap(b1, dx1 / 2, 0, //dy1 / 2, targetWidth, targetHeight); if (b2 != b1) { if (recycle || b1 != source) { b1.recycle(); } } return b2; }
From source file:mzmatch.ipeak.align.CowCoda.java
/** * /* w w w . j a v a 2 s. c o m*/ * @param peak * @return * @throws RuntimeException */ @SuppressWarnings("unchecked") public static double maxRT(IPeak peak) throws RuntimeException { if (peak.getClass().equals(IPeakSet.class)) { IPeakSet<IPeak> peakset = (IPeakSet<IPeak>) peak; double maxrt = Double.MIN_VALUE; for (IPeak p : peakset) maxrt = Math.max(maxrt, maxRT(p)); return maxrt; } else if (peak.getClass().equals(MassChromatogram.class)) return ((MassChromatogram<Peak>) peak).getMaxRetentionTime(); throw new RuntimeException("Only type MassChromatogram or PeakSet are supported"); }