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:net.jofm.format.NumberFormat.java

private Object convert(Number result, Class<?> destinationClazz) {
    if (destinationClazz.equals(BigDecimal.class)) {
        return new BigDecimal(result.doubleValue());
    }/* ww w.ja v a2s . c o  m*/
    if (destinationClazz.equals(Short.class) || destinationClazz.equals(short.class)) {
        return new Short(result.shortValue());
    }
    if (destinationClazz.equals(Integer.class) || destinationClazz.equals(int.class)) {
        return new Integer(result.intValue());
    }
    if (destinationClazz.equals(Long.class) || destinationClazz.equals(long.class)) {
        return new Long(result.longValue());
    }
    if (destinationClazz.equals(Float.class) || destinationClazz.equals(float.class)) {
        return new Float(result.floatValue());
    }
    if (destinationClazz.equals(Double.class) || destinationClazz.equals(double.class)) {
        return new Double(result.doubleValue());
    }

    throw new FixedMappingException("Unable to parse the data to type " + destinationClazz.getName() + " using "
            + this.getClass().getName());
}

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

@Test
public void testFindCustomer() throws ServiceException {

    // 1, 1, MARY, SMITH, MARY.SMITH@sakilacustomer.org, 5, 0, 2006-02-14 22:04:36, 2011-09-21 18:52:54
    Customer customer = _customerService.findCustomer(new Short("1"));
    assertNotNull("test find customer failed - customer must not be null", customer);
    assertEquals("test find customer failed - first name must not be different from MARY", "MARY",
            customer.getFirstName());/*  ww w  . ja  v  a2s  . co m*/
    assertEquals("test find customer failed - first name must not be different from SMITH", "SMITH",
            customer.getLastName());

    customer = _customerService.findCustomer(new Short("-1"));
    assertNull("test find customer failed - customer must be null", customer);
}

From source file:MutableShort.java

/**
 * Gets the value as a Short instance./*from   w w  w.  j  a v a 2s .  c  o  m*/
 * 
 * @return the value as a Short
 */
public Object getValue() {
    return new Short(this.value);
}

From source file:com.nfwork.dbfound.json.JSONDynaBean.java

public Object get(String name) {
    Object value = dynaValues.get(name);
    if (value != null) {
        return value;
    }//from   w  w w. j  a  v a 2s . com

    Class type = getDynaProperty(name).getType();
    if (type == null) {
        throw new NullPointerException("Unspecified property type for " + name);
    }
    if (!type.isPrimitive()) {
        return value;
    }

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Byte.TYPE) {
        return new Byte((byte) 0);
    } else if (type == Character.TYPE) {
        return new Character((char) 0);
    } else if (type == Short.TYPE) {
        return new Short((short) 0);
    } else if (type == Integer.TYPE) {
        return new Integer(0);
    } else if (type == Long.TYPE) {
        return new Long(0);
    } else if (type == Float.TYPE) {
        return new Float(0.0);
    } else if (type == Double.TYPE) {
        return new Double(0);
    }

    return null;
}

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.
 *@return the converted Short value./*  w  w  w  .  j a  va  2 s .  co  m*/
 */
public static Short formatShort(String value) {
    if (value == null) {
        return null;
    }

    try {
        return new Short(value);
    } catch (NumberFormatException e) {
        return null;
    }

}

From source file:com.appleframework.jmx.core.util.CoreUtils.java

public static Number valueOf(String value, String dataType) {
    if (dataType.equals("java.lang.Integer") || dataType.equals("int")) {
        return new Integer(value);
    }/* ww  w  . j a  v a  2s  .c  om*/
    if (dataType.equals("java.lang.Double") || dataType.equals("double")) {
        return new Double(value);
    }
    if (dataType.equals("java.lang.Long") || dataType.equals("long")) {
        return new Long(value);
    }
    if (dataType.equals("java.lang.Float") || dataType.equals("float")) {
        return new Double(value);
    }
    if (dataType.equals("java.lang.Short") || dataType.equals("short")) {
        return new Short(value);
    }
    if (dataType.equals("java.lang.Byte") || dataType.equals("byte")) {
        return new Byte(value);
    }
    if (dataType.equals("java.math.BigInteger")) {
        return new BigInteger(value);
    }
    if (dataType.equals("java.math.BigDecimal")) {
        return new BigDecimal(value);
    }
    return null;
}

From source file:org.crazydog.util.spring.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//from ww  w .ja  v a2 s .c  om
 * @throws IllegalArgumentException if the target class is not supported
 *                                  (i.e. not a standard Number subclass as included in the JDK)
 * @see Byte
 * @see Short
 * @see Integer
 * @see Long
 * @see BigInteger
 * @see Float
 * @see Double
 * @see BigDecimal
 */
@SuppressWarnings("unchecked")
public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)
        throws IllegalArgumentException {

    org.springframework.util.Assert.notNull(number, "Number must not be null");
    org.springframework.util.Assert.notNull(targetClass, "Target class must not be null");

    if (targetClass.isInstance(number)) {
        return (T) number;
    } else if (Byte.class == targetClass) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Byte(number.byteValue());
    } else if (Short.class == targetClass) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Short(number.shortValue());
    } else if (Integer.class == targetClass) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Integer(number.intValue());
    } else if (Long.class == targetClass) {
        BigInteger bigInt = null;
        if (number instanceof BigInteger) {
            bigInt = (BigInteger) number;
        } else if (number instanceof BigDecimal) {
            bigInt = ((BigDecimal) number).toBigInteger();
        }
        // Effectively analogous to JDK 8's BigInteger.longValueExact()
        if (bigInt != null && (bigInt.compareTo(LONG_MIN) < 0 || bigInt.compareTo(LONG_MAX) > 0)) {
            raiseOverflowException(number, targetClass);
        }
        return (T) new Long(number.longValue());
    } else if (BigInteger.class == targetClass) {
        if (number instanceof BigDecimal) {
            // do not lose precision - use BigDecimal's own conversion
            return (T) ((BigDecimal) number).toBigInteger();
        } else {
            // original value is not a Big* number - use standard long conversion
            return (T) BigInteger.valueOf(number.longValue());
        }
    } else if (Float.class == targetClass) {
        return (T) new Float(number.floatValue());
    } else if (Double.class == targetClass) {
        return (T) new Double(number.doubleValue());
    } else if (BigDecimal.class == targetClass) {
        // always use BigDecimal(String) here to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return (T) 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:com.judoscript.jamaica.MyUtils.java

public static Object number2object(long val, String typeHint) {
    if (typeHint != null) {
        if (typeHint.equals("int"))
            return new Integer((int) val);
        if (typeHint.equals("long"))
            return new 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);
        if (typeHint.equals("double"))
            return new Double(val);
        if (typeHint.equals("float"))
            return new Float(val);
    }/*w  ww  .  ja  va  2 s .c o m*/
    return new Long(val);
}

From source file:gov.nih.nci.cacisweb.user.CacisUserService.java

@Override
public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException {
    try {//  ww w .j av  a  2 s . c o m
        log.debug("Loading User..");
        String userProperty = CaCISUtil.getProperty(arg0);
        if (userProperty == null) {
            log.error("User Not Found");
            throw new UsernameNotFoundException("User Not Found");
        }

        String[] userDetails = StringUtils.splitPreserveAllTokens(userProperty, ',');
        if (userDetails.length > 0 && userDetails.length < 5) {
            log.error("User Not Configured Properly");
            throw new UsernameNotFoundException("User Not Configured Properly");
        }
        Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        int i = 4;
        while (i < userDetails.length) {
            authorities.add(new SimpleGrantedAuthority(userDetails[i]));
            i++;
        }
        SimpleDateFormat sDateFormat = new SimpleDateFormat(CaCISWebConstants.COM_DATE_FORMAT);
        if (!StringUtils.isBlank(userDetails[3])) {
            Calendar lockOutTimeCalendar = Calendar.getInstance();
            lockOutTimeCalendar.setTime(sDateFormat.parse(userDetails[3]));
            long lockoutTimeMillis = lockOutTimeCalendar.getTimeInMillis();
            long currentTimeMillis = Calendar.getInstance().getTimeInMillis();
            long diffMinutes = (currentTimeMillis - lockoutTimeMillis) / (1000 * 60);
            if (diffMinutes > 60) {
                log.debug("Lockout Time greater than restricted time. Hence unlocking");
                return new CacisUser(arg0, userDetails[0], true, new Short("0").shortValue(), "", authorities);
            }
        }

        return new CacisUser(arg0, userDetails[0], new Boolean(userDetails[1]).booleanValue(),
                new Short(userDetails[2]).shortValue(), userDetails[3], authorities);

    } catch (CaCISWebException e) {
        log.error("User Not Found... " + e.getMessage());
        throw new UsernameNotFoundException("User Not Found. " + e.getMessage());
    } catch (ParseException e) {
        log.error("Lockout time not configured properly. " + e.getMessage());
        throw new UsernameNotFoundException("Lockout time not configured properly. " + e.getMessage());
    }
}

From source file:co.sip.dmesmobile.bs.ScStopDao.java

@Override
@Transactional//  w  w  w.  j  a  v  a 2  s.com
public int addNotificationAndStopMachine(Long idMachine, Long idGroup, String password, String reason)
        throws Exception {
    entityManager = Factory.getEntityManagerFactory().createEntityManager();
    int result = -1;
    try {
        entityManager.getTransaction().begin();
        ScStopMachine stopMachine = new ScStopMachine();
        stopMachine.setCreationDate(new Date());
        stopMachine.setPassword(password);
        stopMachine.setReason(reason);
        stopMachine.setState(new Short("1"));
        entityManager.persist(stopMachine);
        ScNotification notification = new ScNotification();
        notification.setIdGroup(new ScGroup(idGroup));
        notification.setIdStopMachine(stopMachine.getIdStopMachine());
        notification.setPassword(password);
        notification.setIdMachine(idMachine);
        entityManager.persist(notification);
        entityManager.getTransaction().commit();
        result = Integer.parseInt(notification.getIdNotification().toString());
    } catch (Exception e) {
        entityManager.getTransaction().rollback();
        log.error("Error intentando insertar una nueva notificacin", e);
        throw e;
    }
    return result;
}