Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

In this page you can find the example usage for java.lang Math max.

Prototype

@HotSpotIntrinsicCandidate
public static double max(double a, double b) 

Source Link

Document

Returns the greater of two double values.

Usage

From source file:Main.java

private static double boundaryRestrict(double f, double e, double d) {
    return Math.max(Math.min(f, d), e);
}

From source file:Main.java

public static Animator createInAnimator(View view) {
    // get the center for the clipping circle
    int cx = view.getWidth() / 2;
    int cy = view.getHeight() / 2;

    // get the final radius for the clipping circle
    int finalRadius = Math.max(view.getWidth(), view.getHeight());

    // create the animator for this view (the start radius is zero)
    return ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius).setDuration(300);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Animator toCenterReveal(View view) {
    int width = view.getWidth();
    int height = view.getHeight();
    return ViewAnimationUtils.createCircularReveal(view, width / 2, height / 2, 0, Math.max(width, height));
}

From source file:Main.java

public static Bitmap scaleBitmap(Bitmap bitmap, int reW, int reH) {
    if (bitmap == null) {
        return null;
    }//from  w  w w  .j  a v  a 2 s .  co m
    int bmpW = bitmap.getWidth();
    int bmpH = bitmap.getHeight();
    float wScale = reW * 1.0f / bmpW;
    float hScale = reH * 1.0f / bmpH;
    float scale = Math.max(wScale, hScale);
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    return Bitmap.createBitmap(bitmap, 0, 0, bmpW, bmpH, matrix, true);
}

From source file:Main.java

public static <T, C extends Collection<T>> C getElements(C c, int offset, int size) {
    if (c == null) {
        return null;

    } else if (c.isEmpty() || offset >= c.size() || size <= 0) {
        return newCollection(c);
    }/*from w  ww.  ja  v a2s. c  om*/

    if (offset < 0) {
        offset = Math.max(0, c.size() + offset);
    }

    if (offset + size > c.size()) {
        size = c.size() - offset;
    }

    C result = newCollection(c);
    if (c instanceof List) {
        result.addAll(((List<T>) c).subList(offset, offset + size));

    } else {
        for (int i = offset; i < offset + size; i++) {
            result.add(getElement(c, i));
        }
    }

    return result;
}

From source file:Main.java

/**
 * Extract highest value out of pcm data unfortunately this:
 * http://stackoverflow.com/a/8766420 doesn't work.
 * //from   w  ww  .j  av  a  2  s .c om
 * @param pcmData
 *            the raw audio buffer
 * @return a sound level 0..Short.MAX_VALUE
 */
public static double pcmToSoundLevel(short[] pcmData) {

    double max = 0;

    for (short s : pcmData) {
        max = Math.max(s, max);
    }

    return max;
}

From source file:Main.java

public static void center(Component c) {
    Dimension screenSize = c.getToolkit().getScreenSize();
    screenSize.width -= BORDER_SIZE;//  w  ww. ja v  a2 s  .c  om
    screenSize.height -= BORDER_SIZE;
    Dimension componentSize = c.getSize();
    int xPos = (screenSize.width - componentSize.width) / 2;
    xPos = Math.max(xPos, 0);
    int yPos = (screenSize.height - componentSize.height) / 2;
    yPos = Math.max(yPos, 0);
    c.setLocation(new Point(xPos, yPos));
}

From source file:Main.java

public static Collection<Integer> seq(int start, int stop) {
    List<Integer> l = new ArrayList<Integer>(Math.abs(stop - start));
    for (int i = Math.min(start, stop); i <= Math.max(start, stop); i++) {
        l.add(i);//from  w  w  w  .java 2s .c o  m
    }
    if (stop < start)
        Collections.reverse(l);
    return l;

}

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/*w w w. ja v a 2  s .  c  o  m*/
 * @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 double clamp(double value, double min, double max) {
    return Math.max(min, Math.min(max, value));
}

From source file:Main.java

public static void showRevealEffect(final View v, int centerX, int centerY,
        @Nullable Animator.AnimatorListener lis) {

    v.setVisibility(View.VISIBLE);

    int finalRadius = Math.max(v.getWidth(), v.getHeight());

    Animator anim = ViewAnimationUtils.createCircularReveal(v, centerX, centerY, 0, finalRadius);

    anim.setDuration(REVEAL_DURATION);//from   w ww. j av  a  2  s  .  co  m

    if (lis != null)
        anim.addListener(lis);

    anim.start();
}