Example usage for java.lang Math min

List of usage examples for java.lang Math min

Introduction

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

Prototype

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

Source Link

Document

Returns the smaller of two double values.

Usage

From source file:Main.java

public static float getAnimatedFraction(ValueAnimator animator) {
    float fraction = animator.getDuration() > 0L
            ? (float) animator.getCurrentPlayTime() / (float) animator.getDuration()
            : 0.0F;/*  ww w.  j a v  a 2 s .  co  m*/
    fraction = Math.min(fraction, 1.0F);
    fraction = animator.getInterpolator().getInterpolation(fraction);
    return fraction;
}

From source file:Main.java

public static String[] getContextWindow(String[] a, int index, int windowSize) {
    ArrayList<String> toReturnAL = new ArrayList<String>();

    int begin = Math.max(0, index - windowSize);
    int end = Math.min(a.length, index + windowSize + 1);

    for (int i = begin; i < end; i++) {
        if (i == index)
            toReturnAL.add("[h]" + a[i] + "[/h]");
        else//from w ww . j  a v a 2  s.co m
            toReturnAL.add(a[i]);
    }

    return toReturnAL.toArray(new String[0]);
}

From source file:Main.java

public static String substring(String s, int start, int length) {
    return s.substring(start, Math.min(start + length, s.length()));
}

From source file:Main.java

public static float calculateShrinkScale(int originalWidth, int originalHeight, int expectWidth,
        int expectHeight) {
    float hScale = expectWidth / (float) originalWidth;
    float vScale = expectHeight / (float) originalHeight;
    return Math.min(hScale, vScale);
}

From source file:Main.java

/**
 * whether the value in the all-close range [minValue, MaxValue].
 * //from  www  . j  a v a 2s .c  o  m
 * @param minValue
 * @param MaxValue
 * @param value
 * @return
 */
public static boolean isInRange(int minValue, int MaxValue, int value) {
    boolean inRange = false;
    int min = Math.min(minValue, MaxValue);
    int max = Math.max(minValue, MaxValue);
    if (value >= min && (value <= max)) {
        inRange = true;
    }
    return inRange;
}

From source file:Main.java

private static int compareToGBK(String s1, String s2) {
    int ret = 0;//from  ww w.j  a  v a2 s . com
    try {
        byte[] bytes1 = s1.getBytes("gbk");
        byte[] bytes2 = s2.getBytes("gbk");

        int len = Math.min(bytes1.length, bytes2.length);
        for (int i = 0; i < len; i++) {

            if (bytes1[i] > 0 && bytes2[i] > 0) {
                ret = Character.toLowerCase(bytes1[i]) - Character.toLowerCase(bytes2[i]);
                if (ret == 0)
                    ret = bytes1[i] - bytes2[i];
            } else {
                int b1 = (bytes1[i] + 256) % 256;
                int b2 = (bytes2[i] + 256) % 256;
                ret = b1 - b2;
            }

            if (ret != 0) {
                break;
            }

        }
        if (ret == 0) {
            ret = bytes1.length - bytes2.length;
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return ret;
}

From source file:Main.java

/**
 * Sub the list without exception/*from  w ww.j  a  va 2  s .  co m*/
 */
public static <T> List<T> safeSubList(List<T> list, int start, int end) {
    if (start >= list.size()) {
        return Collections.emptyList();
    }
    return list.subList(start, Math.min(end, list.size()));
}

From source file:Main.java

public static final float bringToBounds(final float pMinValue, final float pMaxValue, final float pValue) {
    return Math.max(pMinValue, Math.min(pMaxValue, pValue));
}

From source file:Main.java

public static void interpolate(float hsl1[], float hsl2[], float amount, float hslOut[]) {
    int size = Math.min(hsl1.length, hsl2.length);
    for (int i = 0; i < size; i++)
        hslOut[i] = hsl1[i] + amount * (hsl2[i] - hsl1[i]);
}

From source file:Main.java

/**
 * Calculates the angle A given length a and circle radius r, according to
 * the law of sines ([a/sin(A) = 2R], thus [A = arcsin(a/2r)])
 * //from  w  w  w. j  a  v a  2 s .  c o  m
 * @param a
 * @param r
 * @return angle A in radians
 */
public static float calcAngleClamp(float a, float r) {
    return (float) Math.asin(Math.min(1, Math.max(-1, a / (2 * r))));
}