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:org.brekka.stillingar.example.FieldTypesXmlBeansTest.java

/**
 * /*from   www  .jav a  2 s  .c o  m*/
 */
private void verify() throws Exception {
    ConfiguredFieldTypes t = configuredFieldTypes;
    assertEquals(new URI(testing.getAnyURI()), t.getUri());
    assertEquals(testing.getBoolean(), t.isBooleanPrimitive());
    assertEquals(Byte.valueOf(testing.getByte()), t.getByteValue());
    assertEquals(testing.getByte(), t.getBytePrimitive());
    assertEquals(testing.getDate(), t.getDateAsCalendar());
    assertEquals(testing.getDate().getTime(), t.getDateAsDate());
    assertEquals(testing.getDateTime(), t.getDateTimeAsCalendar());
    assertEquals(testing.getDateTime().getTime(), t.getDateTimeAsDate());
    assertEquals(testing.getDecimal(), t.getDecimal());
    assertEquals(Double.valueOf(testing.getDouble()), t.getDoubleValue());
    assertEquals(testing.getDouble(), t.getDoublePrimitive(), 1d);
    assertEquals(testing.getFloat(), t.getFloatPrimitive(), 1f);
    assertEquals(Float.valueOf(testing.getFloat()), t.getFloatValue());
    assertEquals(testing.getInt(), t.getIntPrimitive());
    assertEquals(Integer.valueOf(testing.getInt()), t.getIntValue());
    assertEquals(testing.getLanguage(), t.getLanguage().toString());
    assertEquals(testing.getLong(), t.getLongPrimitive());
    assertEquals(Long.valueOf(testing.getLong()), t.getLongValue());
    assertEquals(testing.getShort(), t.getShortPrimitive());
    assertEquals(Short.valueOf(testing.getShort()), t.getShortValue());
    assertEquals(testing.getString(), t.getString());
    assertEquals(testing.getTime(), t.getTimeAsCalendar());

    assertEquals(testing.getPeriod().toString(), t.getPeriod().toString());
    assertEquals(new DateTime(testing.getDateTime(), ISOChronology.getInstance()), t.getDateTime());
    assertEquals(new LocalDate(testing.getDate(), ISOChronology.getInstance()), t.getLocalDate());
    assertEquals(new LocalTime(testing.getTime(), ISOChronology.getInstance()), t.getLocalTime());

    assertTrue(Arrays.equals(t.getBinary(), testing.getBinary()));
    assertEquals(UUID.fromString(testing.getUUID()), t.getUuid());
    assertTrue(t.getTestingObject() instanceof Testing);
    assertNotNull(t.getTestingElement());
    assertNotNull(t.getRoot());
}

From source file:org.mifos.application.meeting.business.MeetingBO.java

public MeetingBO(final RecurrenceType recurrenceType, final Short recurAfter, final Date startDate,
        final MeetingType meetingType) throws MeetingException {
    this(recurrenceType, Short.valueOf("1"), WeekDay.MONDAY, null, recurAfter, startDate, meetingType,
            "meetingPlace");
}

From source file:me.huzorro.gateway.telnet.TelnetServerHandler.java

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {

    // Cast to a String first.
    // We know it is a String because we put some codec in TelnetPipelineFactory.
    String request = (String) e.getMessage();

    // Generate and write a response.
    String response;/*w  w  w. j  a v  a2 s  . c om*/
    boolean close = false;
    if (request.length() == 0) {
        response = "Please type something.\r\n";
    } else if (request.toLowerCase().equals("bye")) {
        response = "Have a good day!\r\n";
        close = true;
    } else {
        response = "Did you say '" + request + "'?\r\n";
    }
    if (!loggedin) {
        ++trylogin;
        if (trylogin > 3) {
            response = "login failed\r\n";
            close = true;
        } else {
            String[] auth = request.split("@");
            if (auth.length != 3)
                response = "login:";
            if (auth.length == 3) {
                SessionConfig config = sessionConfigFactory.setHost(
                        ((InetSocketAddress) ctx.getChannel().getRemoteAddress()).getAddress().getHostAddress())
                        .setUser(auth[0]).setVersion(Short.valueOf(auth[2])).create();

                if (config == null || !config.getPasswd().equals(auth[1])) {
                    response = "login:";
                } else {

                    sessionFactory.setChannel(ctx.getChannel());
                    sessionFactory.setConfig(config);

                    Session session = sessionFactory.create();
                    if (session != null) {
                        ctx.getChannel().setAttachment(session);
                        session.getLoginFuture().setSuccess();
                        response = "login success\r\n";
                        loggedin = true;
                    } else {
                        response = "out of the max number of connections";
                        close = true;
                    }
                }
            }
        }

    } else {
        List<String> list = new ArrayList<String>(Arrays.asList(StringUtils.split(request)));
        List<String> result = null;
        if (list.remove("help"))
            result = DefaultCommandService.help((String[]) list.toArray(new String[list.size()]));
        if (list.remove("start"))
            result = DefaultCommandService.start((String[]) list.toArray(new String[list.size()]));
        if (list.remove("stop"))
            result = DefaultCommandService.stop((String[]) list.toArray(new String[list.size()]));
        if (list.remove("status"))
            result = DefaultCommandService.status((String[]) list.toArray(new String[list.size()]));
        if (list.remove("kick"))
            result = DefaultCommandService.kick((String[]) list.toArray(new String[list.size()]));
        if (list.remove("clear"))
            result = DefaultCommandService.clear((String[]) list.toArray(new String[list.size()]));
        if (list.remove("bye"))
            result = DefaultCommandService.bye((String[]) list.toArray(new String[list.size()]));
        if (list.remove("shutdown"))
            result = DefaultCommandService.shutdown((String[]) list.toArray(new String[list.size()]));
        if (result != null) {
            for (String info : result) {
                response += info;
                response += "\r\n";
            }
        } else {
            response = "command not found\r\n";
        }

    }
    // We do not need to write a ChannelBuffer here.
    // We know the encoder inserted at TelnetPipelineFactory will do the conversion.
    ChannelFuture future = e.getChannel().write(response);

    // Close the connection after sending 'Have a good day!'
    // if the client has sent 'bye'.
    if (close) {
        future.addListener(ChannelFutureListener.CLOSE);
    }
}

From source file:org.datacleaner.util.convert.StandardTypeConverter.java

@Override
public Object fromString(Class<?> type, String str) {
    if (ReflectionUtils.isString(type)) {
        return str;
    }//from  w ww. j a v a  2 s  .  c  om
    if (ReflectionUtils.isBoolean(type)) {
        return Boolean.valueOf(str);
    }
    if (ReflectionUtils.isCharacter(type)) {
        return Character.valueOf(str.charAt(0));
    }
    if (ReflectionUtils.isInteger(type)) {
        return Integer.valueOf(str);
    }
    if (ReflectionUtils.isLong(type)) {
        return Long.valueOf(str);
    }
    if (ReflectionUtils.isByte(type)) {
        return Byte.valueOf(str);
    }
    if (ReflectionUtils.isShort(type)) {
        return Short.valueOf(str);
    }
    if (ReflectionUtils.isDouble(type)) {
        return Double.valueOf(str);
    }
    if (ReflectionUtils.isFloat(type)) {
        return Float.valueOf(str);
    }
    if (ReflectionUtils.is(type, Class.class)) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Class not found: " + str, e);
        }
    }
    if (ReflectionUtils.is(type, EnumerationValue.class)) {
        return new EnumerationValue(str);
    }
    if (type.isEnum()) {
        try {
            Object[] enumConstants = type.getEnumConstants();

            // first look for enum constant matches
            Method nameMethod = Enum.class.getMethod("name");
            for (Object e : enumConstants) {
                String name = (String) nameMethod.invoke(e);
                if (name.equals(str)) {
                    return e;
                }
            }

            // check for aliased enums
            for (Object e : enumConstants) {
                String name = (String) nameMethod.invoke(e);
                Field field = type.getField(name);
                Alias alias = ReflectionUtils.getAnnotation(field, Alias.class);
                if (alias != null) {
                    String[] aliasValues = alias.value();
                    for (String aliasValue : aliasValues) {
                        if (aliasValue.equals(str)) {
                            return e;
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new IllegalStateException("Unexpected error occurred while examining enum", e);
        }
        throw new IllegalArgumentException("No such enum '" + str + "' in enum class: " + type.getName());
    }
    if (ReflectionUtils.isDate(type)) {
        return toDate(str);
    }
    if (ReflectionUtils.is(type, File.class)) {
        final FileResolver fileResolver = new FileResolver(_configuration);
        return fileResolver.toFile(str);
    }
    if (ReflectionUtils.is(type, Calendar.class)) {
        Date date = toDate(str);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
    if (ReflectionUtils.is(type, Pattern.class)) {
        try {
            return Pattern.compile(str);
        } catch (PatternSyntaxException e) {
            throw new IllegalArgumentException("Invalid regular expression syntax in '" + str + "'.", e);
        }
    }
    if (ReflectionUtils.is(type, java.sql.Date.class)) {
        Date date = toDate(str);
        return new java.sql.Date(date.getTime());
    }
    if (ReflectionUtils.isNumber(type)) {
        return ConvertToNumberTransformer.transformValue(str);
    }
    if (ReflectionUtils.is(type, Serializable.class)) {
        logger.warn("fromString(...): No built-in handling of type: {}, using deserialization", type.getName());
        byte[] bytes = (byte[]) _parentConverter.fromString(byte[].class, str);
        ChangeAwareObjectInputStream objectInputStream = null;
        try {
            objectInputStream = new ChangeAwareObjectInputStream(new ByteArrayInputStream(bytes));
            objectInputStream.addClassLoader(type.getClassLoader());
            Object obj = objectInputStream.readObject();
            return obj;
        } catch (Exception e) {
            throw new IllegalStateException("Could not deserialize to " + type + ".", e);
        } finally {
            FileHelper.safeClose(objectInputStream);
        }
    }

    throw new IllegalArgumentException("Could not convert to type: " + type.getName());
}

From source file:org.codice.ddf.spatial.kml.transformer.KmlStyleMapEntryImpl.java

private boolean attributeValueMatch(Attribute attribute, AttributeDescriptor descriptor) {

    switch (descriptor.getType().getAttributeFormat()) {
    case STRING:// w w  w .java  2s.c o  m
    case XML:
    case GEOMETRY:
        return attributeValue.equals(attribute.getValue());
    case BOOLEAN:
        return Boolean.valueOf(attributeValue).equals(attribute.getValue());
    case DATE:
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
            String mappedDate = dateFormat.format(dateFormat.parse(attributeValue));
            String metacardDate = dateFormat.format((Date) attribute.getValue());
            return mappedDate.equals(metacardDate);
        } catch (ParseException e) {
            LOGGER.debug("Unable to parse date and perform comparison.", e);
            return false;
        }
    case SHORT:
        return Short.valueOf(attributeValue).equals(attribute.getValue());
    case INTEGER:
        return Integer.valueOf(attributeValue).equals(attribute.getValue());
    case LONG:
        return Long.valueOf(attributeValue).equals(attribute.getValue());
    case FLOAT:
        return Precision.equals(Float.valueOf(attributeValue), (Float) attribute.getValue(), .0000001);
    case DOUBLE:
        return Precision.equals(Double.valueOf(attributeValue), (Double) attribute.getValue(), .0000000001);
    case BINARY:
    case OBJECT:
    default:
        LOGGER.debug("Unsupported Attribute Format was attempted for KML Style Mapping.");
        return false;
    }
}

From source file:org.lingcloud.molva.ocl.util.GenericTypeValidator.java

/**
 * Checks if the value can safely be converted to a short primitive.
 * /* w w w .  j  av  a  2 s. co m*/
 * @param value
 *            The value validation is being performed on.
 * @param locale
 *            The locale to use to parse the number (system default if
 *            null)vv
 * @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 = Short.valueOf(num.shortValue());
            }
        }
    }

    return result;
}

From source file:org.mifos.customers.checklist.business.CheckListBO.java

private void setCheckListDetails(List<String> details, Short locale) {
    checklistDetails = new HashSet<CheckListDetailEntity>();
    for (String detail : details) {
        CheckListDetailEntity checkListDetailEntity = new CheckListDetailEntity(detail, Short.valueOf("1"),
                this, locale);
        checklistDetails.add(checkListDetailEntity);
    }//from  w ww. j a va  2 s .  c o m
}

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

public FeeFormula getFeeFormulaValue() throws PropertyNotFoundException {
    return StringUtils.isNotBlank(feeFormula) ? FeeFormula.getFeeFormula(Short.valueOf(feeFormula)) : null;
}

From source file:org.mifos.application.meeting.struts.actionforms.MeetingActionForm.java

public CustomerLevel getCustomerLevelValue() {
    return CustomerLevel.getLevel(Short.valueOf(getCustomerLevel()));
}

From source file:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java

@SuppressWarnings("unchecked")
public static <T> T toJavaValue(String stringContent, Class<T> type, boolean exceptionOnUnknown) {
    if (type.equals(String.class)) {
        return (T) stringContent;
    } else if (type.equals(char.class)) {
        return (T) (new Character(stringContent.charAt(0)));
    } else if (type.equals(File.class)) {
        return (T) new File(stringContent);
    } else if (type.equals(Integer.class)) {
        return (T) Integer.valueOf(stringContent);
    } else if (type.equals(int.class)) {
        return (T) Integer.valueOf(stringContent);
    } else if (type.equals(Short.class) || type.equals(short.class)) {
        return (T) Short.valueOf(stringContent);
    } else if (type.equals(Long.class)) {
        return (T) Long.valueOf(stringContent);
    } else if (type.equals(long.class)) {
        return (T) Long.valueOf(stringContent);
    } else if (type.equals(Byte.class)) {
        return (T) Byte.valueOf(stringContent);
    } else if (type.equals(byte.class)) {
        return (T) Byte.valueOf(stringContent);
    } else if (type.equals(float.class)) {
        return (T) Float.valueOf(stringContent);
    } else if (type.equals(Float.class)) {
        return (T) Float.valueOf(stringContent);
    } else if (type.equals(double.class)) {
        return (T) Double.valueOf(stringContent);
    } else if (type.equals(Double.class)) {
        return (T) Double.valueOf(stringContent);
    } else if (type.equals(BigInteger.class)) {
        return (T) new BigInteger(stringContent);
    } else if (type.equals(BigDecimal.class)) {
        return (T) new BigDecimal(stringContent);
    } else if (type.equals(byte[].class)) {
        byte[] decodedData = Base64.decodeBase64(stringContent);
        return (T) decodedData;
    } else if (type.equals(boolean.class) || Boolean.class.isAssignableFrom(type)) {
        // TODO: maybe we will need more inteligent conversion, e.g. to trim spaces, case insensitive, etc.
        return (T) Boolean.valueOf(stringContent);
    } else if (type.equals(GregorianCalendar.class)) {
        return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent).toGregorianCalendar();
    } else if (XMLGregorianCalendar.class.isAssignableFrom(type)) {
        return (T) getDatatypeFactory().newXMLGregorianCalendar(stringContent);
    } else if (Duration.class.isAssignableFrom(type)) {
        return (T) getDatatypeFactory().newDuration(stringContent);
    } else if (type.equals(PolyString.class)) {
        return (T) new PolyString(stringContent);
    } else if (type.equals(ItemPath.class)) {
        throw new UnsupportedOperationException("Path conversion not supported yet");
    } else {/*from   ww w  . ja  v a 2  s.c  o  m*/
        if (exceptionOnUnknown) {
            throw new IllegalArgumentException("Unknown conversion type " + type);
        } else {
            return null;
        }
    }
}