Example usage for java.lang Short Short

List of usage examples for java.lang Short Short

Introduction

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

Prototype

@Deprecated(since = "9")
public Short(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Short object that represents the short value indicated by the String parameter.

Usage

From source file:adams.data.statistics.StatUtils.java

/**
 * Turns the short array into a Short array.
 *
 * @param array   the array to convert/*from   w  ww.  j  a  va  2  s .  c  om*/
 * @return      the converted array
 */
public static Number[] toNumberArray(short[] array) {
    Short[] result;
    int i;

    result = new Short[array.length];
    for (i = 0; i < array.length; i++)
        result[i] = new Short(array[i]);

    return result;
}

From source file:com.bitranger.parknshop.buyer.controller.CustomerRegister.java

/**
 * @param req//w  ww.  j av a2 s . c  o m
 * @param username
 * @param email
 * @param password
 * @param buyer
 *    Set not null if the person to register is buyer
 * @param seller
 *  Set not null if the person to register is seller
 * @return
 */
@RequestMapping(value = "/register") //, method=RequestMethod.POST)
public String registerCustomer(HttpServletRequest req, String username, String email, String password,
        String role) {
    if (email == null || password == null || role == null)
        return Utility.error("Param Error.");
    if (role.equals("seller")) {
        log.debug("Seller Try to sign up.");
        Timestamp now = new Timestamp(System.currentTimeMillis());
        PsSeller toAdd = new PsSeller(email, password, new Timestamp(System.currentTimeMillis()));
        toAdd.setNickname(username);
        toAdd.setTimeCreated(now);
        psSellerDao.save(toAdd);
        req.getSession().setAttribute("currentSeller", toAdd);
    } else if (role.equals("buyer")) {
        log.debug("Buyer Try to sign up.");
        Timestamp now = new Timestamp(System.currentTimeMillis());
        PsCustomer toAdd = new PsCustomer(username, email, password, new Short((short) 0), now);
        psCustomerDao.save(toAdd);
        req.getSession().setAttribute("currentCustomer", toAdd);
    } else {
        log.debug("Parameter Error.");
    }

    return "redirect:/";
}

From source file:com.igorbaiborodine.example.mybatis.customer.TestCustomerMapper.java

@Test
public void testUpdateByPrimaryKey() {

    Short customerId = new Short("1");
    Customer customer = _customerMapper.selectByPrimaryKey(customerId);
    assertNotNull("test update by primary key failed - customer must not be null", customer);

    boolean isActive = !customer.getActive();
    customer.setActive(isActive);//from   w w  w . j a  v  a2s  . c  o m

    int count = _customerMapper.updateByPrimaryKey(customer);
    assertEquals("test update by primary key failed - update count must be equal to 1", 1, count);

    customer = _customerMapper.selectByPrimaryKey(customerId);
    assertEquals("test update by primary key failed - active field not updated", isActive,
            customer.getActive());
}

From source file:com.odap.server.audit.ConfigHandler.java

public ConfigMessage registerNewServer(ConfigMessage config) throws TException {
    logger.info("Enter registerNewServer()");
    ConfigMessage msg = new ConfigMessage();

    QueryRunner qRunner = new QueryRunner();

    Integer account_id = null;//from   ww  w. j a  va 2 s .c o m
    Integer server_id = null;
    //Authenticate the user and get the account_id;
    String query = "SELECT * FROM joomla.cloud_users WHERE username = ? AND password = ?";
    {
        String parameters[] = { config.getUsername().replaceAll("[^A-Za-z0-9 ]", ""),
                DigestUtils.md5Hex(config.getPassword().replaceAll("[^A-Za-z0-9 ]", "")) };
        try {
            List<Map<String, Object>> mapList = (List<Map<String, Object>>) qRunner
                    .query(AuditServer.connectionPool.getConnection(), query, new MapListHandler(), parameters);

            if (mapList.size() < 1) {
                logger.warn("Username " + config.getUsername() + " not authenticated");
                return msg;
            }

            account_id = (Integer) mapList.get(0).get("account_id");

        } catch (SQLException e) {
            logger.error("Issue finding user account", e);
            return msg;
        }
    }

    String session_id = nextSessionId();
    {
        try {
            {
                query = "INSERT INTO servers (account_id,server_name,server_software,server_port,server_authentication_token,server_timezone,strip_predicates) VALUES (?,?,?,?,?,?,?)";
                Object parameters[] = { account_id.toString(),
                        config.getServer_name().replaceAll("[^A-Za-z0-9 ]", ""), config.getServer_software(),
                        new Short(config.getPort()), session_id, new Double(config.getTimezone_offset()),
                        config.strip_predicates };
                qRunner.update(AuditServer.connectionPool.getConnection(), query, parameters);
            }
            {
                String parameters[] = { account_id.toString(), config.getServer_name(), session_id };
                query = "SELECT * FROM servers WHERE account_id = ? AND server_name = ? and server_authentication_token = ?";
                List<Map<String, Object>> mapList = (List<Map<String, Object>>) qRunner.query(
                        AuditServer.connectionPool.getConnection(), query, new MapListHandler(), parameters);

                if (mapList.size() < 1) {
                    logger.error("Unable to find server after after registering it");
                    return msg;
                }

                server_id = (Integer) mapList.get(0).get("id");
            }
        } catch (SQLException e) {
            logger.error("Issue registering server", e);
        }
    }

    msg.token = session_id;
    msg.server_id = server_id.shortValue();
    msg.server = "dbauditcloud.com";
    logger.info("Exiting registerNewServer()");
    return msg;
}

From source file:NumberUtil.java

/**
 * Convert an Object to a Short./* ww w. ja v a 2 s .c  o m*/
 */
public static Short toShort(Object value) {
    if (value == null)
        return null;
    if (value instanceof Short)
        return (Short) value;
    if (value instanceof String) {
        if ("".equals((String) value))
            return null;
        return new Short((String) value);
    }
    if (value instanceof Number)
        return new Short(((Number) value).shortValue());

    return new Short(value.toString());
}

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

@Test
public void test2() {
    List<Number> list = new ArrayList<Number>();
    list.add(new Byte((byte) 1));
    list.add(new Short((short) 2));
    list.add(new Integer(3));
    list.add(new Long(4));
    list.add(new Float(5));
    list.add(new Double(6));

    String digest1 = sha1().update(list).digestAsString();

    String digest2 = sha1().update((byte) 1).update((short) 2).update(3).update((long) 4).update((float) 5)
            .update((double) 6).digestAsString();

    assertEquals(digest1, digest2);//from   w ww  .jav a  2s.com
}

From source file:com.judoscript.jamaica.MyUtils.java

public static Object number2object(double val, String typeHint) {
    if (typeHint != null) {
        if (typeHint.equals("double"))
            return new Double(val);
        if (typeHint.equals("float"))
            return new Float((float) val);
        if (typeHint.equals("int"))
            return new Integer((int) val);
        if (typeHint.equals("long"))
            return new Long((long) val);
        if (typeHint.equals("short"))
            return new Short((short) val);
        if (typeHint.equals("char"))
            return new Character((char) val);
        if (typeHint.equals("byte"))
            return new Byte((byte) val);
    }/*from   w  w w  .j  a  v  a 2 s .co m*/
    return new Double(val);
}

From source file:Main.java

/**
 * <p>Converts an array of primitive shorts to objects.</p>
 *
 * <p>This method returns <code>null</code> for a <code>null</code> input array.</p>
 *
 * @param array  a <code>short</code> array
 * @return a <code>Short</code> array, <code>null</code> if null array input
 *///w w w  .j  av  a2  s. c  o  m
public static Short[] toObject(short[] array) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_SHORT_OBJECT_ARRAY;
    }
    final Short[] result = new Short[array.length];
    for (int i = 0; i < array.length; i++) {
        result[i] = new Short(array[i]);
    }
    return result;
}

From source file:com.jeeframework.util.validate.GenericTypeValidator.java

/**
 *  Checks if the value can safely be converted to a short primitive.
 *
 *@param  value   The value validation is being performed on.
 *@param  locale  The locale to use to parse the number (system default if
 *      null)vv/*from w  w  w.j  a va 2 s  .co  m*/
 *@return the converted Short value.
 */
public static Short formatShort(String value, Locale locale) {
    Short result = null;

    if (value != null) {
        NumberFormat formatter = null;
        if (locale != null) {
            formatter = NumberFormat.getNumberInstance(locale);
        } else {
            formatter = NumberFormat.getNumberInstance(Locale.getDefault());
        }
        formatter.setParseIntegerOnly(true);
        ParsePosition pos = new ParsePosition(0);
        Number num = formatter.parse(value, pos);

        // If there was no error      and we used the whole string
        if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) {
            if (num.doubleValue() >= Short.MIN_VALUE && num.doubleValue() <= Short.MAX_VALUE) {
                result = new Short(num.shortValue());
            }
        }
    }

    return result;
}

From source file:edu.utah.further.core.api.collections.ToParameterMapBuilder.java

/**
 * Append a short field value./* ww  w. j  a  v  a 2  s  .  c  o  m*/
 *
 * @param fieldName
 *            the name of the field, usually the member variable name
 * @param value
 *            the field value
 * @return this, to support call-chaining
 */
public ToParameterMapBuilder append(final String fieldName, final short value) {
    return append(fieldName, new Short(value));
}