Example usage for java.lang Short MAX_VALUE

List of usage examples for java.lang Short MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Short MAX_VALUE.

Prototype

short MAX_VALUE

To view the source code for java.lang Short MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value a short can have, 215-1.

Usage

From source file:Main.java

public static Dimension getPreferredSize(JComponent c, String text, Icon icon, int iconTextGap,
        int verticalAlignment, int horizontalAlignment, int verticalTextAlignment, int horizontalTextAlignment,
        Rectangle viewRect, Rectangle iconRect, Rectangle textRect) {
    viewRect.x = viewRect.y = 0;/*from  w ww . ja  va2 s  .c  om*/
    viewRect.width = viewRect.height = Short.MAX_VALUE;

    layoutComponent(c, text, icon, iconTextGap, verticalAlignment, horizontalAlignment, verticalTextAlignment,
            horizontalTextAlignment, viewRect, iconRect, textRect);

    Rectangle size = iconRect.union(textRect);
    if (c.getInsets() != null) {
        addInsets(size, c.getInsets());
    }

    return new Dimension(size.width, size.height);
}

From source file:Main.java

public static short toShort(long l) {
    if (l < Short.MIN_VALUE || l > Short.MAX_VALUE)
        throw new ArithmeticException("Value (" + l + ") cannot fit into short");
    return (short) l;
}

From source file:Main.java

public static void setComponentSize(int width, int height, JComponent l) {
    l.setPreferredSize(new Dimension(width, height));
    l.setMinimumSize(new Dimension(width, height));
    if (l instanceof JTextField || l instanceof JComboBox) {
        l.setMaximumSize(new Dimension(Short.MAX_VALUE, height));
    }/*from   www. ja  va2  s  .co m*/
}

From source file:Main.java

public static void setMaxWidth(JComponent comp, int width) {
    comp.setMaximumSize(new Dimension(width, Short.MAX_VALUE));
}

From source file:Main.java

public static short[] createSoundDataInShortArray(int bufferSamples, final int sampleRate,
        final double frequency, double sweep) {
    final double rad = 2 * Math.PI * frequency / sampleRate;
    short[] vai = new short[bufferSamples];
    sweep = Math.PI * sweep / ((double) sampleRate * vai.length);
    for (int j = 0; j < vai.length; j++) {
        vai[j] = (short) (Math.sin(j * (rad + j * sweep)) * Short.MAX_VALUE);
    }//  www . ja  va 2s.c  om
    return vai;
}

From source file:datamine.storage.idl.generator.RandomValueGenerator.java

public static Object getValueOf(PrimitiveType type) {

    switch (type) {
    case BOOL:/*from  w  ww .j a va  2  s . c  o  m*/
        return rand1.nextBoolean();
    case BYTE:
        return (byte) rand1.nextInt(Byte.MAX_VALUE);
    case INT16:
        return (short) rand1.nextInt(Short.MAX_VALUE);
    case INT32:
        return rand1.nextInt(Integer.MAX_VALUE);
    case INT64:
        return rand1.nextLong();
    case FLOAT:
        return rand1.nextFloat();
    case DOUBLE:
        return rand1.nextDouble();
    case STRING:
        return "abasf_" + System.currentTimeMillis();//rand2.random(256);
    case BINARY:
        byte[] ret = new byte[1000];
        rand1.nextBytes(ret);
        return ret;
    case UNKNOWN:
        return null;
    default:
        throw new IllegalArgumentException("Not support the type: " + type);
    }
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 *
 * @param number      the number to convert
 * @param targetClass the target class to convert to
 * @return the converted number/*  w  ww  . j  ava2s. c o  m*/
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte
 * @see java.lang.Short
 * @see java.lang.Integer
 * @see java.lang.Long
 * @see java.math.BigInteger
 * @see java.lang.Float
 * @see java.lang.Double
 * @see java.math.BigDecimal
 */
public static Number convertNumberToTargetClass(Number number, Class targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return number.byteValue();
    } else if (targetClass.equals(Short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return number.shortValue();
    } else if (targetClass.equals(Integer.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return number.intValue();
    } else if (targetClass.equals(Long.class)) {
        return number.longValue();
    } else if (targetClass.equals(Float.class)) {
        return number.floatValue();
    } else if (targetClass.equals(Double.class)) {
        return number.doubleValue();
    } else if (targetClass.equals(BigInteger.class)) {
        return BigInteger.valueOf(number.longValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return new BigDecimal(number.toString());
    } else {
        throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
                + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]");
    }
}

From source file:Main.java

private Component createStrut() {
    JComponent component = (JComponent) Box.createHorizontalStrut(5);
    component.setMinimumSize(new Dimension(0, 0));
    component.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    return component;
}

From source file:Main.java

public Main() {
    Container pane = getContentPane();
    GroupLayout gl = new GroupLayout(pane);
    pane.setLayout(gl);//w  ww.j av a 2 s  .  c  om

    JLabel avLbl = new JLabel("Available");
    JLabel tagsLbl = new JLabel("Tags");
    JLabel selLbl = new JLabel("Selected");

    JButton newBtn = new JButton("New");
    JButton moveBtn = new JButton(">>");
    JButton remBtn = new JButton("Remove");

    JList leftList = new JList();
    JScrollPane spleft = new JScrollPane(leftList);
    JList rightList = new JList();
    JScrollPane spright = new JScrollPane(rightList);

    gl.setAutoCreateGaps(true);
    gl.setAutoCreateContainerGaps(true);

    gl.setHorizontalGroup(gl.createParallelGroup(CENTER).addComponent(tagsLbl)
            .addGroup(gl.createSequentialGroup()
                    .addGroup(gl.createParallelGroup(CENTER).addComponent(avLbl)
                            .addComponent(spleft, 100, 200, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createParallelGroup(CENTER).addComponent(selLbl)
                            .addComponent(spright, 100, 200, Short.MAX_VALUE).addComponent(remBtn))));
    gl.setVerticalGroup(gl.createSequentialGroup().addComponent(tagsLbl)
            .addGroup(gl.createParallelGroup(CENTER)
                    .addGroup(gl.createSequentialGroup().addComponent(avLbl)
                            .addComponent(spleft, 100, 250, Short.MAX_VALUE).addComponent(newBtn))
                    .addComponent(moveBtn).addGroup(gl.createSequentialGroup().addComponent(selLbl)
                            .addComponent(spright, 100, 250, Short.MAX_VALUE).addComponent(remBtn))));
    pack();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:com.sawyer.advadapters.app.adapters.jsonadapter.UnitTestJSONArrayActivity.java

private static short getShort() {
    return (short) new Random().nextInt(Short.MAX_VALUE);
}