Example usage for java.lang Short valueOf

List of usage examples for java.lang Short valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Short valueOf(short s) 

Source Link

Document

Returns a Short instance representing the specified short value.

Usage

From source file:it.unimi.dsi.util.Properties.java

public void setProperty(final Enum<?> key, final short s) {
    super.setProperty(key.name().toLowerCase(), Short.valueOf(s));
}

From source file:com.neovisionaries.security.DigestTest.java

@Test
public void test10() {
    ByteBuffer byteBuffer = ByteBuffer.allocate(10);
    byteBuffer.put(new byte[] { 1, 2, 3, 4, 5 });
    byteBuffer.flip();/*from   ww  w .ja  va  2 s  .  com*/

    // Ensure there is no infinite loop.
    Digest.getInstanceSHA256().update("Hello, world.", new String[] { "Hello", "world" },

            Boolean.TRUE, new boolean[] { true, false }, new Boolean[] { Boolean.TRUE, Boolean.FALSE },

            Byte.valueOf((byte) 0), new byte[] { (byte) 0, (byte) 1 },
            new Byte[] { Byte.valueOf((byte) 0), Byte.valueOf((byte) 1) }, byteBuffer,

            Character.valueOf('b'), new char[] { 'a', 'b' },
            new Character[] { Character.valueOf('a'), Character.valueOf('b') },

            Double.valueOf(0.0), new double[] { 0.0, 1.0 },
            new Double[] { Double.valueOf(0.0), Double.valueOf(1.0) },

            Float.valueOf(0.0F), new float[] { 0.0F, 1.0F },
            new Float[] { Float.valueOf(0.0F), Float.valueOf(1.0F) },

            Integer.valueOf(1), new int[] { 1, 2 }, new Integer[] { Integer.valueOf(0), Integer.valueOf(1) },

            Long.valueOf(0L), new long[] { 0L, 1L }, new Long[] { Long.valueOf(0L), Long.valueOf(1L) },

            Short.valueOf((short) 0), new short[] { (short) 0, (short) 1 },
            new Short[] { Short.valueOf((short) 0), Short.valueOf((short) 1) },

            new Object[] { new boolean[] { true, false }, new byte[] { (byte) 0, (byte) 1 } },
            new Object[] { new Object[] { new char[] { 'a', 'b' }, new short[] { 10, 20 } },
                    new Object[] { new float[] { 1.0F, 2.0F }, new double[] { 3.0, 4.0 } } });

    assertTrue(true);
}

From source file:org.jlgranda.fede.database.SetupService.java

private void validateGroups() {

    Group singleResult = null;//from w w  w .  j  a v  a2s.  co  m
    Map<String, String> props = new HashMap<>();

    //Grupos de arranque del sistema
    props.put("fede", "fede:1");
    props.put("salud", "Salud:2");
    props.put("alimentos", "Alimentos:3");
    props.put("ropa", "Ropa:4");
    props.put("educacion", "Educacin:5");
    props.put("vivienda", "Vivienda:6");

    props.put("favorito", "Favoritos:7");

    String value = null;
    String name = null;
    Short orden = null;
    for (String key : props.keySet()) {
        value = props.get(key);
        try {
            TypedQuery<Group> query = getEntityManager().createQuery("from Group g where g.code='" + key + "'",
                    Group.class);
            singleResult = query.getSingleResult();
        } catch (NoResultException e) {

            java.util.Date now = Dates.now();
            name = value.split(":")[0];
            orden = Short.valueOf(value.split(":")[1]);
            singleResult = new Group(key, name);
            singleResult.setOrden(orden);
            singleResult.setCreatedOn(now);
            singleResult.setLastUpdate(now);
            singleResult.setCodeType(CodeType.TAG);
            singleResult.setStatus(StatusType.ACTIVE.toString());
            getEntityManager().persist(singleResult);
            getEntityManager().flush();
        }

        log.info("Added group code: {} name: [{}]", key, singleResult.getName());
    }
}

From source file:org.mifos.accounts.fees.struts.actionforms.FeeActionForm.java

public boolean isCategoryLoan() {
    return FeeCategory.LOAN.getValue().equals(Short.valueOf(categoryType));
}

From source file:FormatStorage.Head.java

public void fromJobConf(JobConf job) throws Exception {
    byte var = (byte) job.getInt(ConstVar.HD_var, 0);
    byte compress = (byte) job.getInt(ConstVar.HD_compress, 0);
    byte compressStyle = (byte) job.getInt(ConstVar.HD_compressStyle, 0);
    short primaryIndex = (short) job.getInt(ConstVar.HD_primaryIndex, -1);
    byte encode = (byte) job.getInt(ConstVar.HD_encode, 0);
    byte encodeStyle = (byte) job.getInt(ConstVar.HD_encodeStyle, 0);
    String keyString = job.get(ConstVar.HD_key);
    String[] fieldStrings = job.getStrings(ConstVar.HD_fieldMap);

    LOG.info("in fromJobConf, compressed:" + compress + ",compressStyle:" + compressStyle);

    setVar(var);//from   w  w  w. j  ava2 s .  com
    setCompress(compress);
    setCompressStyle(compressStyle);

    setEncode(encode);
    setEncodeStyle(encodeStyle);
    if (keyString != null && keyString.length() != 0) {
        setKey(keyString);
    }

    short fieldNum = 0;
    if (fieldStrings != null) {
        fieldNum = (short) fieldStrings.length;
    }

    FieldMap fieldMap = new FieldMap();
    for (short i = 0; i < fieldNum; i++) {
        String[] def = fieldStrings[i].split(ConstVar.RecordSplit);
        byte type = Byte.valueOf(def[0]);
        int len = Integer.valueOf(def[1]);
        short index = Short.valueOf(def[2]);

        fieldMap.addField(new Field(type, len, index));
    }

    setFieldMap(fieldMap);
    setPrimaryIndex(primaryIndex);
}

From source file:com.liferay.portal.search.elasticsearch.internal.document.DefaultElasticsearchDocumentFactory.java

protected Object translateValue(Field field, String value) {
    if (!field.isNumeric()) {
        return value;
    }//from w w  w.  java 2s .  c om

    Class<? extends Number> clazz = field.getNumericClass();

    if (clazz.equals(Float.class)) {
        return Float.valueOf(value);
    } else if (clazz.equals(Integer.class)) {
        return Integer.valueOf(value);
    } else if (clazz.equals(Long.class)) {
        return Long.valueOf(value);
    } else if (clazz.equals(Short.class)) {
        return Short.valueOf(value);
    }

    return Double.valueOf(value);
}

From source file:com.pandich.dropwizard.curator.refresh.Refresher.java

protected final Object getValue(final A element, final NodeValue nodeValue) {
    final String rawValue = nodeValue.getValue();

    final Class<?> clazz = getType(element);

    final CuratorMapper<?> mapper = this.mappers.get(clazz);
    if (mapper != null) {
        return mapper.readValueFroMString(rawValue);
    }/*from w  ww.j  a  va  2 s  . c  o  m*/

    if (isAssignable(clazz, String.class)) {
        return rawValue;
    }

    if (isAssignable(clazz, Boolean.class)) {
        return Boolean.valueOf(rawValue);
    }

    if (isAssignable(clazz, Character.class)) {
        return CharUtils.toChar(rawValue);
    }

    if (isAssignable(clazz, Byte.class)) {
        return Byte.valueOf(rawValue);
    }

    if (isAssignable(clazz, Short.class)) {
        return Short.valueOf(rawValue);
    }

    if (isAssignable(clazz, Integer.class)) {
        return Integer.valueOf(rawValue);
    }

    if (isAssignable(clazz, Long.class)) {
        return Long.valueOf(rawValue);
    }

    if (isAssignable(clazz, Float.class)) {
        return Float.valueOf(rawValue);
    }

    if (isAssignable(clazz, Double.class)) {
        return Double.valueOf(rawValue);
    }

    if (isAssignable(clazz, BigInteger.class)) {
        return new BigInteger(rawValue);
    }

    if (isAssignable(clazz, BigDecimal.class)) {
        return new BigDecimal(rawValue);
    }

    try {
        return objectMapper.readValue(rawValue, clazz);
    } catch (IOException e) {
        throw new RuntimeException("type '" + clazz.getName() + "' is not supported", e);
    }
}

From source file:org.mifos.customers.struts.actionforms.CustomerActionForm.java

public CustomerStatus getStatusValue() {
    return StringUtils.isNotBlank(status) ? CustomerStatus.fromInt(Short.valueOf(status)) : null;
}

From source file:org.kuali.rice.krad.data.jpa.Filter.java

/**
 * Coerces the {@code attributeValue} using the given {@code type}.
 *
 * @param type the type to use to coerce the value.
 * @param attributeName the attribute name of the field to coerce.
 * @param attributeValue the value to coerce.
 * @return the coerced value./* w ww  .  jav a2 s  .c  o  m*/
 */
private static Object coerceValue(Class<?> type, String attributeName, String attributeValue) {
    try {
        if (Character.TYPE.equals(type) || Character.class.isAssignableFrom(type)) {
            return Character.valueOf(attributeValue.charAt(0));
        } else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
            return Boolean.valueOf(attributeValue);
        } else if (Short.TYPE.equals(type) || Short.class.isAssignableFrom(type)) {
            return Short.valueOf(attributeValue);
        } else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
            return Integer.valueOf(attributeValue);
        } else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
            return Long.valueOf(attributeValue);
        } else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
            return Double.valueOf(attributeValue);
        } else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
            return Float.valueOf(attributeValue);
        }
    } catch (NumberFormatException nfe) {
        LOG.error("Could not coerce the value " + attributeValue + " for the field " + attributeName, nfe);
    }

    return attributeValue;
}

From source file:com.envirover.spl.Config.java

public boolean init(String[] args) throws IOException, ParseException {
    Options options = new Options();
    options.addOption(CLI_OPTION_HELP, false, "help");
    options.addOption(CLI_OPTION_IMEI, true, "IMEI of RockBLOCK");
    options.addOption(CLI_OPTION_USERNAME, true, "Rock 7 Core username");
    options.addOption(CLI_OPTION_PASSWORD, true, "Rock 7 Core password");
    options.addOption(CLI_OPTION_AUTOPILOT, true, "Autopilot code");
    options.addOption(CLI_OPTION_MAV_TYPE, true, "MAV type");
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption(CLI_OPTION_HELP)) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("spl", options);
    }/*from   w w w  .j  a va2  s. c  om*/

    Properties props = new Properties();

    InputStream in = null;
    try {
        ClassLoader loader = Config.class.getClassLoader();
        in = loader.getResourceAsStream(CONFIG_PROPERTIES_FILE);
        if (in != null)
            props.load(in);
    } finally {
        if (in != null) {
            in.close();
        }
    }

    if (props.getProperty(PROP_ROCKBLOCK_PORT) != null)
        rockblockPort = Integer.valueOf(props.getProperty(PROP_ROCKBLOCK_PORT));

    if (props.getProperty(PROP_MAVLINK_PORT) != null)
        mavlinkPort = Integer.valueOf(props.getProperty(PROP_MAVLINK_PORT));

    if (props.getProperty(PROP_WS_PORT) != null)
        wsPort = Integer.valueOf(props.getProperty(PROP_WS_PORT));

    if (props.getProperty(PROP_QUEUE_SIZE) != null)
        queueSize = Integer.valueOf(props.getProperty(PROP_QUEUE_SIZE));

    if (props.getProperty(PROP_HEARTBEAT_INTERVAL) != null)
        heartbeatInterval = Integer.valueOf(props.getProperty(PROP_HEARTBEAT_INTERVAL));

    if (props.getProperty(PROP_ROCKBLOCK_URL) != null)
        rockblockUrl = props.getProperty(PROP_ROCKBLOCK_URL);

    imei = cmd.getOptionValue(CLI_OPTION_IMEI, props.getProperty(PROP_ROCKBLOCK_IMEI));

    if (imei == null || imei.isEmpty()) {
        System.out.println(MessageFormat.format("Required configuration property ''{0}'' is not set.",
                PROP_ROCKBLOCK_IMEI));
        return false;
    }

    username = cmd.getOptionValue(CLI_OPTION_USERNAME, props.getProperty(PROP_ROCKBLOCK_USERNAME));

    if (username == null || username.isEmpty()) {
        System.out.println(MessageFormat.format("Required configuration property ''{0}'' is not set.",
                PROP_ROCKBLOCK_USERNAME));
        return false;
    }

    password = cmd.getOptionValue(CLI_OPTION_PASSWORD, props.getProperty(PROP_ROCKBLOCK_PASSWORD));

    if (password == null || password.isEmpty()) {
        System.out.println(MessageFormat.format("Required configuration property ''{0}'' is not set.",
                PROP_ROCKBLOCK_PASSWORD));
        return false;
    }

    autopilot = Short.valueOf(cmd.getOptionValue(CLI_OPTION_AUTOPILOT,
            props.getProperty(PROP_MAV_AUTOPILOT, DEFAULT_AUTOPILOT.toString())));

    mavType = Short.valueOf(cmd.getOptionValue(CLI_OPTION_MAV_TYPE,
            props.getProperty(PROP_MAV_TYPE, DEFAULT_MAV_TYPE.toString())));

    return true;
}