Example usage for java.lang Short shortValue

List of usage examples for java.lang Short shortValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public short shortValue() 

Source Link

Document

Returns the value of this Short as a short .

Usage

From source file:Main.java

/**
 * <p>Converts an array of object Short to primitives handling {@code null}.</p>
 *
 * <p>This method returns {@code null} for a {@code null} input array.</p>
 *
 * @param array  a {@code Short} array, may be {@code null}
 * @param valueForNull  the value to insert if {@code null} found
 * @return a {@code byte} array, {@code null} if null array input
 *///w  w  w .java  2  s .  c o  m
public static short[] toPrimitive(final Short[] array, final short valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_SHORT_ARRAY;
    }
    final short[] result = new short[array.length];
    for (int i = 0; i < array.length; i++) {
        final Short b = array[i];
        result[i] = (b == null ? valueForNull : b.shortValue());
    }
    return result;
}

From source file:com.borqs.sync.server.contact.MergeUtils.java

/**
 *
 *///from   w ww.jav a 2  s.c o m
public static MergeResult compareShorts(Short shortA, Short shortB) {

    MergeResult result = null;

    if (shortA == null && shortB == null) {
        return new MergeResult(false, false);
    }

    if (shortA != null && shortB == null) {
        result = new MergeResult();
        result.addPropertyB("Short", shortA.shortValue() + ", null");
        return result;
    }

    if (shortA == null && shortB != null) {
        result = new MergeResult();
        result.addPropertyA("Short", "null, " + shortB.shortValue());
        return result;
    }

    if (shortA.compareTo(shortB) != 0) {
        //
        // The values are different so
        // an update on shortB is required
        //
        result = new MergeResult();
        result.addPropertyB("Short", shortA.shortValue() + ", " + shortB.shortValue());
        return result;
    }

    return new MergeResult(false, false);
}

From source file:fr.landel.utils.commons.ObjectUtils.java

/**
 * Get the primitive value of an {@link Short}. If {@code value} is not
 * {@code null}, returns the primitive value of {@code value} otherwise returns
 * {@code defaultValue}//from  w w w.  jav  a 2  s .  com
 * 
 * <pre>
 * Short value0 = new Short((short) 1);
 * short value1 = ObjectUtils.toPrimitive(value0, (short) 0); // =&gt; value1 = 1
 * short value2 = ObjectUtils.toPrimitive((Short) null, (short) 0); // =&gt; value2 = 0
 * </pre>
 * 
 * @param value
 *            the {@link Short} value
 * @param defaultValue
 *            the default value
 * @return a primitive short
 */
public static short toPrimitive(final Short value, final short defaultValue) {
    if (value == null) {
        return defaultValue;
    } else {
        return value.shortValue();
    }
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ShortCalculator.java

public Object add(Object obj1, Object obj2) {
    Short shortData1 = (Short) obj1;
    Short shortData2 = (Short) obj2;

    return (Object) (new Short((short) (shortData1.shortValue() + shortData2.shortValue())));
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ShortCalculator.java

public Object div(Object obj1, Object obj2) {
    Short shortData1 = (Short) obj1;
    Short shortData2 = (Short) obj2;

    return (Object) (new Short((short) (shortData1.shortValue() / shortData2.shortValue())));
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ShortCalculator.java

public Object mul(Object obj1, Object obj2) {
    Short shortData1 = (Short) obj1;
    Short shortData2 = (Short) obj2;

    return (Object) (new Short((short) (shortData1.shortValue() * shortData2.shortValue())));
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.ShortCalculator.java

public Object sub(Object obj1, Object obj2) {
    Short shortData1 = (Short) obj1;
    Short shortData2 = (Short) obj2;

    return (Object) (new Short((short) (shortData1.shortValue() - shortData2.shortValue())));
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Set the Statement column so that the results are mapped correctly.
 *
 * @param statement the prepared statement
 * @param position the position of the column
 * @param value the value of the column/*from  w w w  . j ava 2 s . co m*/
 */
public static void setColumn(PreparedStatement statement, int position, Object value, Integer typeObject)
        throws Exception {
    if (value instanceof String) {
        value = ((String) value).trim();
    }
    if (typeObject == null) {
        throw new SQLException("Can't set column because the type is unrecognized");
    }
    if (value == null) {
        /** If the value is null, set the column value null and return **/
        statement.setNull(position, typeObject.intValue());
        return;
    }
    if ("".equals(value)) {
        switch (typeObject.intValue()) {
        case Types.CHAR:
        case Types.CLOB:
        case Types.VARCHAR:
            /** If the value is an empty string and the column is
            a string type, we can continue **/
            break;
        default:
            /** If the value is an empty string and the column
            is something else, we treat it as a null value **/
            statement.setNull(position, typeObject.intValue());
            return;
        }
    }

    File file = null;
    int length = -1;
    InputStream asciiStream = null;

    //System.out.println("========================================================================");
    //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue());
    switch (typeObject.intValue()) {
    case Types.CLOB:
        //System.out.println("CLOB");
        Clob clob = null;
        if (value instanceof Clob) {
            clob = (Clob) value;
        } else if (value instanceof File) {
            File asciiFile = (File) value;
            asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
            length = (int) asciiFile.length();
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof Part) {
            Part anyFile = (Part) value;
            asciiStream = new BufferedInputStream(anyFile.getInputStream());
            length = anyFile.getSize();
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof JDBCxlobHelper) {
            asciiStream = ((JDBCxlobHelper) value).inputStream;
            length = ((JDBCxlobHelper) value).length;
            clob = new ClobHelper(asciiStream, length);
        } else if (value instanceof Source) {
            asciiStream = ((Source) value).getInputStream();
            length = (int) ((Source) value).getContentLength();
            clob = new ClobHelper(asciiStream, length);
        } else {
            String asciiText = value.toString();
            asciiStream = new ByteArrayInputStream(asciiText.getBytes());
            length = asciiText.length();
            clob = new ClobHelper(asciiStream, length);
        }

        statement.setClob(position, clob);
        break;
    case Types.CHAR:
        // simple large object, e.g. Informix's TEXT
        //System.out.println("CHAR");

        if (value instanceof File) {
            File asciiFile = (File) value;
            asciiStream = new BufferedInputStream(new FileInputStream(asciiFile));
            length = (int) asciiFile.length();
        } else if (value instanceof JDBCxlobHelper) {
            asciiStream = ((JDBCxlobHelper) value).inputStream;
            length = ((JDBCxlobHelper) value).length;
        } else if (value instanceof Source) {
            asciiStream = ((Source) value).getInputStream();
            length = (int) ((Source) value).getContentLength();
        } else if (value instanceof Part) {
            Part anyFile = (Part) value;
            asciiStream = new BufferedInputStream(anyFile.getInputStream());
            length = anyFile.getSize();
            clob = new ClobHelper(asciiStream, length);
        } else {
            String asciiText = value.toString();
            asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes()));
            length = asciiText.length();
        }

        statement.setAsciiStream(position, asciiStream, length);
        break;
    case Types.BIGINT:
        //System.out.println("BIGINT");
        BigDecimal bd = null;

        if (value instanceof BigDecimal) {
            bd = (BigDecimal) value;
        } else if (value instanceof Number) {
            bd = BigDecimal.valueOf(((Number) value).longValue());
        } else {
            bd = new BigDecimal(value.toString());
        }

        statement.setBigDecimal(position, bd);
        break;
    case Types.TINYINT:
        //System.out.println("TINYINT");
        Byte b = null;

        if (value instanceof Byte) {
            b = (Byte) value;
        } else if (value instanceof Number) {
            b = new Byte(((Number) value).byteValue());
        } else {
            b = new Byte(value.toString());
        }

        statement.setByte(position, b.byteValue());
        break;
    case Types.DATE:
        //System.out.println("DATE");
        Date d = null;

        if (value instanceof Date) {
            d = (Date) value;
        } else if (value instanceof java.util.Date) {
            d = new Date(((java.util.Date) value).getTime());
        } else if (value instanceof Calendar) {
            d = new Date(((Calendar) value).getTime().getTime());
        } else {
            d = Date.valueOf(value.toString());
        }

        statement.setDate(position, d);
        break;
    case Types.DOUBLE:
        //System.out.println("DOUBLE");
        double db;

        if (value instanceof Number) {
            db = (((Number) value).doubleValue());
        } else {
            db = Double.parseDouble(value.toString());
        }
        statement.setDouble(position, db);
        break;
    case Types.FLOAT:
        //System.out.println("FLOAT");
        float f;

        if (value instanceof Number) {
            f = (((Number) value).floatValue());
        } else {
            f = Float.parseFloat(value.toString());
        }
        statement.setFloat(position, f);
        break;
    case Types.NUMERIC:
        //System.out.println("NUMERIC");
        long l;

        if (value instanceof Number) {
            l = (((Number) value).longValue());
        } else {
            l = Long.parseLong(value.toString());
        }

        statement.setLong(position, l);
        break;
    case Types.SMALLINT:
        //System.out.println("SMALLINT");
        Short s = null;

        if (value instanceof Short) {
            s = (Short) value;
        } else if (value instanceof Number) {
            s = new Short(((Number) value).shortValue());
        } else {
            s = new Short(value.toString());
        }

        statement.setShort(position, s.shortValue());
        break;
    case Types.TIME:
        //System.out.println("TIME");
        Time t = null;

        if (value instanceof Time) {
            t = (Time) value;
        } else if (value instanceof java.util.Date) {
            t = new Time(((java.util.Date) value).getTime());
        } else {
            t = Time.valueOf(value.toString());
        }

        statement.setTime(position, t);
        break;
    case Types.TIMESTAMP:
        //System.out.println("TIMESTAMP");
        Timestamp ts = null;

        if (value instanceof Time) {
            ts = (Timestamp) value;
        } else if (value instanceof java.util.Date) {
            ts = new Timestamp(((java.util.Date) value).getTime());
        } else {
            ts = Timestamp.valueOf(value.toString());
        }

        statement.setTimestamp(position, ts);
        break;
    case Types.ARRAY:
        //System.out.println("ARRAY");
        statement.setArray(position, (Array) value); // no way to convert string to array
        break;
    case Types.STRUCT:
        //System.out.println("STRUCT");
    case Types.OTHER:
        //System.out.println("OTHER");
        statement.setObject(position, value);
        break;
    case Types.LONGVARBINARY:
        //System.out.println("LONGVARBINARY");
        statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime()));
        break;
    case Types.VARCHAR:
        //System.out.println("VARCHAR");
        statement.setString(position, value.toString());
        break;
    case Types.BLOB:
        //System.out.println("BLOB");
        if (value instanceof JDBCxlobHelper) {
            statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream,
                    ((JDBCxlobHelper) value).length);
        } else if (value instanceof Source) {
            statement.setBinaryStream(position, ((Source) value).getInputStream(),
                    (int) ((Source) value).getContentLength());
        } else {
            Blob blob = null;
            if (value instanceof Blob) {
                blob = (Blob) value;
            } else if (value instanceof File) {
                file = (File) value;
                blob = new BlobHelper(new FileInputStream(file), (int) file.length());
            } else if (value instanceof String) {
                file = new File((String) value);
                blob = new BlobHelper(new FileInputStream(file), (int) file.length());
            } else if (value instanceof Part) {
                Part anyFile = (Part) value;
                blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize());
            } else {
                throw new SQLException("Invalid type for blob: " + value.getClass().getName());
            }
            //InputStream input = new BufferedInputStream(new FileInputStream(file));
            statement.setBlob(position, blob);
        }
        break;
    case Types.VARBINARY:
        //System.out.println("VARBINARY");
        if (value instanceof JDBCxlobHelper) {
            statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream,
                    ((JDBCxlobHelper) value).length);
        } else if (value instanceof Source) {
            statement.setBinaryStream(position, ((Source) value).getInputStream(),
                    (int) ((Source) value).getContentLength());
        } else if (value instanceof Part) {
            statement.setBinaryStream(position, ((Part) value).getInputStream(), ((Part) value).getSize());
        } else {
            if (value instanceof File) {
                file = (File) value;
            } else if (value instanceof String) {
                file = new File((String) value);
            } else {
                throw new SQLException("Invalid type for blob: " + value.getClass().getName());
            }
            //InputStream input = new BufferedInputStream(new FileInputStream(file));
            FileInputStream input = new FileInputStream(file);
            statement.setBinaryStream(position, input, (int) file.length());
        }
        break;
    case Types.INTEGER:
        //System.out.println("INTEGER");
        Integer i = null;
        if (value instanceof Integer) {
            i = (Integer) value;
        } else if (value instanceof Number) {
            i = new Integer(((Number) value).intValue());
        } else {
            i = new Integer(value.toString());
        }
        statement.setInt(position, i.intValue());
        break;
    case Types.BIT:
        //System.out.println("BIT");
        Boolean bo = null;
        if (value instanceof Boolean) {
            bo = (Boolean) value;
        } else if (value instanceof Number) {
            bo = BooleanUtils.toBooleanObject(((Number) value).intValue() == 1);
        } else {
            bo = BooleanUtils.toBooleanObject(value.toString());
        }
        statement.setBoolean(position, bo.booleanValue());
        break;

    default:
        //System.out.println("default");
        throw new SQLException("Impossible exception - invalid type ");
    }
    //System.out.println("========================================================================");
}

From source file:org.red5.io.mock.Input.java

/** {@inheritDoc} */
public Object readReference() {
    final Short num = (Short) getNext();
    return getReference(num.shortValue());
}

From source file:net.sourceforge.subsonic.controller.VideoPlayerController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    LOG.debug("got request " + request.getParameter("id"));

    Map<String, Object> map = new HashMap<String, Object>();
    Uri mediaFileUri = URIUtil.parseURI(removeEnd(removeStart(request.getParameter("id"), "["), "]"));

    LOG.debug("ask for id " + mediaFileUri);

    MediaFile file = mediaFileService.getMediaFile(mediaFileUri);

    int timeOffset = ServletRequestUtils.getIntParameter(request, "timeOffset", 0);
    timeOffset = Math.max(0, timeOffset);
    Short duration = file.getMetaData().getDuration();
    short durationSeconds = 0;
    if (duration != null) {
        durationSeconds = duration.shortValue();
        map.put("skipOffsets", createSkipOffsets(duration));
        timeOffset = Math.min(duration, timeOffset);
        durationSeconds -= timeOffset;//from  w ww .j  a v a 2s . c o m
    }

    map.put("video", file);
    map.put("player", playerService.getPlayer(request, response).getId());
    map.put("maxBitRate", ServletRequestUtils.getIntParameter(request, "maxBitRate", DEFAULT_BIT_RATE));
    map.put("popout", ServletRequestUtils.getBooleanParameter(request, "popout", false));
    map.put("duration", durationSeconds);
    map.put("timeOffset", timeOffset);
    map.put("bitRates", BIT_RATES);

    ModelAndView result = super.handleRequestInternal(request, response);
    result.addObject("model", map);
    return result;
}