List of usage examples for java.lang Short valueOf
@HotSpotIntrinsicCandidate public static Short valueOf(short s)
From source file:framework.GlobalHelpers.java
public static void setValueOfFieldOrProperty(Object object, String name, Object value) { Field field;/*w w w.j av a 2 s.co m*/ try { field = findInheritedField(object.getClass(), name); if (field != null) { field.setAccessible(true); Class<?> type = field.getType(); if (value != null && !type.equals(value.getClass())) { // TODO conversion if (type.equals(String.class)) { value = String.valueOf(value); } else if (type.equals(short.class) || type.equals(Short.class)) { value = Short.valueOf(String.valueOf(value)); } else if (type.equals(int.class) || type.equals(Integer.class)) { value = Integer.valueOf(String.valueOf(value)); } else if (type.equals(long.class) || type.equals(Long.class)) { value = Long.valueOf(String.valueOf(value)); } else if (type.equals(boolean.class) || type.equals(Boolean.class)) { value = Boolean.valueOf(String.valueOf(value)); } else if (type.equals(float.class) || type.equals(Float.class)) { value = Float.valueOf(String.valueOf(value)); } else if (type.equals(double.class) || type.equals(Double.class)) { value = Double.valueOf(String.valueOf(value)); } else if (type.equals(BigDecimal.class)) { value = new BigDecimal(String.valueOf(value)); } } field.set(object, value); } else { BeanUtils.setProperty(object, name, value); } } catch (Exception e) { // do nth, just skip not existing field (maybe log sth?) } }
From source file:org.apache.flink.table.dataformat.BinaryStringTest.java
@Test public void testToNumeric() { // Test to integer. assertEquals(Byte.valueOf("123"), fromString("123").toByte()); assertEquals(Byte.valueOf("123"), fromString("+123").toByte()); assertEquals(Byte.valueOf("-123"), fromString("-123").toByte()); assertEquals(Short.valueOf("123"), fromString("123").toShort()); assertEquals(Short.valueOf("123"), fromString("+123").toShort()); assertEquals(Short.valueOf("-123"), fromString("-123").toShort()); assertEquals(Integer.valueOf("123"), fromString("123").toInt()); assertEquals(Integer.valueOf("123"), fromString("+123").toInt()); assertEquals(Integer.valueOf("-123"), fromString("-123").toInt()); assertEquals(Long.valueOf("1234567890"), fromString("1234567890").toLong()); assertEquals(Long.valueOf("+1234567890"), fromString("+1234567890").toLong()); assertEquals(Long.valueOf("-1234567890"), fromString("-1234567890").toLong()); // Test decimal string to integer. assertEquals(Integer.valueOf("123"), fromString("123.456789").toInt()); assertEquals(Long.valueOf("123"), fromString("123.456789").toLong()); // Test negative cases. assertNull(fromString("1a3.456789").toInt()); assertNull(fromString("123.a56789").toInt()); // Test composite in BinaryRow. BinaryRow row = new BinaryRow(20); BinaryRowWriter writer = new BinaryRowWriter(row); writer.writeString(0, BinaryString.fromString("1")); writer.writeString(1, BinaryString.fromString("123")); writer.writeString(2, BinaryString.fromString("12345")); writer.writeString(3, BinaryString.fromString("123456789")); writer.complete();/*from ww w . j a v a2 s. co m*/ assertEquals(Byte.valueOf("1"), row.getString(0).toByte()); assertEquals(Short.valueOf("123"), row.getString(1).toShort()); assertEquals(Integer.valueOf("12345"), row.getString(2).toInt()); assertEquals(Long.valueOf("123456789"), row.getString(3).toLong()); }
From source file:cn.wangsy.fast4j.util.IdcardUtils.java
/** * ???/*from w ww . j a v a 2s.com*/ * * @param idCard * ? * @return (dd) */ public static Short getDateByIdCard(String idCard) { Integer len = idCard.length(); if (len < CHINA_ID_MIN_LENGTH) { return null; } else if (len == CHINA_ID_MIN_LENGTH) { idCard = conver15CardTo18(idCard); } return Short.valueOf(idCard.substring(12, 14)); }
From source file:org.executequery.databasemediators.spi.DefaultStatementExecutor.java
/** <p>Executes the specified procedure. * * @param the SQL procedure to execute * @return the query result//from w w w. j a v a2 s. c o m */ public SqlStatementResult execute(DatabaseExecutable databaseExecutable) throws SQLException { if (!prepared()) { return statementResult; } ProcedureParameter[] param = databaseExecutable.getParametersArray(); Arrays.sort(param, new ProcedureParameterSorter()); String procQuery = null; boolean hasOut = false; boolean hasParameters = (param != null && param.length > 0); List<ProcedureParameter> outs = null; List<ProcedureParameter> ins = null; if (hasParameters) { // split the params into ins and outs outs = new ArrayList<ProcedureParameter>(); ins = new ArrayList<ProcedureParameter>(); int type = -1; for (int i = 0; i < param.length; i++) { type = param[i].getType(); if (type == DatabaseMetaData.procedureColumnIn || type == DatabaseMetaData.procedureColumnInOut) { // add to the ins list ins.add(param[i]); } else if (type == DatabaseMetaData.procedureColumnOut || type == DatabaseMetaData.procedureColumnResult || type == DatabaseMetaData.procedureColumnReturn || type == DatabaseMetaData.procedureColumnUnknown || type == DatabaseMetaData.procedureColumnInOut) { // add to the outs list outs.add(param[i]); } } char QUESTION_MARK = '?'; String COMMA = ", "; // init the string buffer StringBuilder sb = new StringBuilder("{ "); if (!outs.isEmpty()) { // build the out params place holders for (int i = 0, n = outs.size(); i < n; i++) { sb.append(QUESTION_MARK); if (i < n - 1) { sb.append(COMMA); } } sb.append(" = "); } sb.append(" call "); if (databaseExecutable.supportCatalogOrSchemaInFunctionOrProcedureCalls()) { String namePrefix = null; if (databaseExecutable.supportCatalogInFunctionOrProcedureCalls()) { namePrefix = databaseExecutable.getCatalogName(); } if (databaseExecutable.supportSchemaInFunctionOrProcedureCalls()) { namePrefix = databaseExecutable.getSchemaName(); } if (namePrefix != null) { sb.append(namePrefix).append('.'); } } sb.append(databaseExecutable.getName()).append("( "); // build the ins params place holders for (int i = 0, n = ins.size(); i < n; i++) { sb.append(QUESTION_MARK); if (i < n - 1) { sb.append(COMMA); } } sb.append(" ) }"); // determine if we have out params hasOut = !(outs.isEmpty()); procQuery = sb.toString(); } else { StringBuilder sb = new StringBuilder(); sb.append("{ call "); if (databaseExecutable.getSchemaName() != null) { sb.append(databaseExecutable.getSchemaName()).append('.'); } sb.append(databaseExecutable.getName()).append("( ) }"); procQuery = sb.toString(); } //Log.debug(procQuery); // null value literal String NULL = "null"; // clear any warnings conn.clearWarnings(); Log.info("Executing: " + procQuery); CallableStatement cstmnt = null; try { // prepare the statement cstmnt = conn.prepareCall(procQuery); stmnt = cstmnt; } catch (SQLException e) { handleException(e); statementResult.setSqlException(e); return statementResult; } // check if we are passing parameters if (hasParameters) { // the parameter index counter int index = 1; // the java.sql.Type value int dataType = -1; // the parameter input value String value = null; // register the out params for (int i = 0, n = outs.size(); i < n; i++) { //Log.debug("setting out at index: " + index); cstmnt.registerOutParameter(index, outs.get(i).getDataType()); index++; } try { // register the in params for (int i = 0, n = ins.size(); i < n; i++) { ProcedureParameter procedureParameter = ins.get(i); value = procedureParameter.getValue(); dataType = procedureParameter.getDataType(); // try infer a type if OTHER if (dataType == Types.OTHER) { // checking only for bit/bool for now if (isTrueFalse(value)) { dataType = Types.BOOLEAN; } else if (isBit(value)) { dataType = Types.BIT; value = value.substring(2, value.length() - 1); } } if (MiscUtils.isNull(value) || value.equalsIgnoreCase(NULL)) { cstmnt.setNull(index, dataType); } else { switch (dataType) { case Types.TINYINT: byte _byte = Byte.valueOf(value).byteValue(); cstmnt.setShort(index, _byte); break; case Types.SMALLINT: short _short = Short.valueOf(value).shortValue(); cstmnt.setShort(index, _short); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: cstmnt.setString(index, value); break; case Types.BIT: case Types.BOOLEAN: boolean _boolean = false; if (NumberUtils.isNumber(value)) { int number = Integer.valueOf(value); if (number > 0) { _boolean = true; } } else { _boolean = Boolean.valueOf(value).booleanValue(); } cstmnt.setBoolean(index, _boolean); break; case Types.BIGINT: long _long = Long.valueOf(value).longValue(); cstmnt.setLong(index, _long); break; case Types.INTEGER: int _int = Integer.valueOf(value).intValue(); cstmnt.setInt(index, _int); break; case Types.REAL: float _float = Float.valueOf(value).floatValue(); cstmnt.setFloat(index, _float); break; case Types.NUMERIC: case Types.DECIMAL: cstmnt.setBigDecimal(index, new BigDecimal(value)); break; /* case Types.DATE: case Types.TIMESTAMP: case Types.TIME: cstmnt.setTimestamp(index, new Timestamp( BigDecimal(value)); */ case Types.FLOAT: case Types.DOUBLE: double _double = Double.valueOf(value).doubleValue(); cstmnt.setDouble(index, _double); break; default: cstmnt.setObject(index, value); } } // increment the index index++; } } catch (Exception e) { statementResult.setOtherErrorMessage(e.getClass().getName() + ": " + e.getMessage()); return statementResult; } } /* test creating function for postgres: CREATE FUNCTION concat_lower_or_upper(a text, b text, uppercase boolean DEFAULT false) RETURNS text AS $$ SELECT CASE WHEN $3 THEN UPPER($1 || ' ' || $2) ELSE LOWER($1 || ' ' || $2) END; $$ LANGUAGE SQL IMMUTABLE STRICT; */ try { cstmnt.clearWarnings(); boolean hasResultSet = cstmnt.execute(); Map<String, Object> results = new HashMap<String, Object>(); if (hasOut) { // incrementing index int index = 1; // return value from each registered out String returnValue = null; for (int i = 0; i < param.length; i++) { int type = param[i].getType(); int dataType = param[i].getDataType(); if (type == DatabaseMetaData.procedureColumnOut || type == DatabaseMetaData.procedureColumnResult || type == DatabaseMetaData.procedureColumnReturn || type == DatabaseMetaData.procedureColumnUnknown || type == DatabaseMetaData.procedureColumnInOut) { switch (dataType) { case Types.TINYINT: returnValue = Byte.toString(cstmnt.getByte(index)); break; case Types.SMALLINT: returnValue = Short.toString(cstmnt.getShort(index)); break; case Types.LONGVARCHAR: case Types.CHAR: case Types.VARCHAR: returnValue = cstmnt.getString(index); break; case Types.BIT: case Types.BOOLEAN: returnValue = Boolean.toString(cstmnt.getBoolean(index)); break; case Types.INTEGER: returnValue = Integer.toString(cstmnt.getInt(index)); break; case Types.BIGINT: returnValue = Long.toString(cstmnt.getLong(index)); break; case Types.REAL: returnValue = Float.toString(cstmnt.getFloat(index)); break; case Types.NUMERIC: case Types.DECIMAL: returnValue = cstmnt.getBigDecimal(index).toString(); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: returnValue = cstmnt.getDate(index).toString(); break; case Types.FLOAT: case Types.DOUBLE: returnValue = Double.toString(cstmnt.getDouble(index)); break; } if (returnValue == null) { returnValue = "NULL"; } results.put(param[i].getName(), returnValue); index++; } } } if (!hasResultSet) { statementResult.setUpdateCount(cstmnt.getUpdateCount()); } else { statementResult.setResultSet(cstmnt.getResultSet()); } useCount++; statementResult.setOtherResult(results); } catch (SQLException e) { statementResult.setSqlException(e); } catch (Exception e) { statementResult.setMessage(e.getMessage()); } return statementResult; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.CswFilterDelegate.java
@Override public FilterType propertyIsGreaterThanOrEqualTo(String propertyName, short literal) { isComparisonOperationSupported(ComparisonOperatorType.GREATER_THAN_EQUAL_TO); propertyName = mapPropertyName(propertyName); if (isPropertyQueryable(propertyName)) { return cswFilterFactory.buildPropertyIsGreaterThanOrEqualToFilter(propertyName, Short.valueOf(literal)); } else {/* w ww .j a v a2 s . c o m*/ return new FilterType(); } }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*from ww w . j a v a2 s . c om*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] * ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static short[] add(short[] array, int index, short element) { return (short[]) add(array, index, Short.valueOf(element), Short.TYPE); }
From source file:org.codice.ddf.spatial.ogc.wfs.transformer.handlebars.HandlebarsWfsFeatureTransformer.java
private Serializable getValueForAttributeFormat(AttributeType.AttributeFormat attributeFormat, final String value) { Serializable serializable = null; switch (attributeFormat) { case BOOLEAN: serializable = Boolean.valueOf(value); break;/*from w w w . ja va2 s . c o m*/ case DOUBLE: serializable = Double.valueOf(value); break; case FLOAT: serializable = Float.valueOf(value); break; case INTEGER: serializable = Integer.valueOf(value); break; case LONG: serializable = Long.valueOf(value); break; case SHORT: serializable = Short.valueOf(value); break; case XML: case STRING: serializable = value; break; case GEOMETRY: LOGGER.trace("Unescape the geometry: {}", value); String newValue = StringEscapeUtils.unescapeXml(value); LOGGER.debug("Geometry value after it has been xml unescaped: {}", newValue); String wkt = getWktFromGeometry(newValue); LOGGER.debug("String wkt value: {}", wkt); serializable = wkt; break; case BINARY: serializable = value.getBytes(StandardCharsets.UTF_8); break; case DATE: try { serializable = DatatypeConverter.parseDate(value).getTime(); } catch (IllegalArgumentException e) { LOGGER.debug("Error converting value to a date. value: '{}'", value, e); } break; default: break; } return serializable; }
From source file:org.mifos.accounts.loan.business.LoanBORedoDisbursalIntegrationTest.java
@Ignore @Test//from ww w . java2 s.c o m public void testRedoLoanApplyFractionalMiscPenaltyAfterFullPayment() throws Exception { try { LoanBO loan = redoLoanWithMondayMeetingAndVerify(userContext, 14, new ArrayList<AccountFeesEntity>()); disburseLoanAndVerify(userContext, loan, 14); LoanTestUtils.assertInstallmentDetails(loan, 1, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.5, 0.5, 0.0, 0.0, 0.0); // make one full repayment applyAndVerifyPayment(userContext, loan, 7, new Money(getCurrency(), "51")); LoanTestUtils.assertInstallmentDetails(loan, 1, 0.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.5, 0.5, 0.0, 0.0, 0.0); // Should throw AccountException applyCharge(loan, Short.valueOf(AccountConstants.MISC_PENALTY), new Double("33.7")); LoanTestUtils.assertInstallmentDetails(loan, 1, 0.0, 0.0, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 2, 51.2, 0.1, 0.0, 0.0, 33.7); LoanTestUtils.assertInstallmentDetails(loan, 3, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 4, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 5, 50.9, 0.1, 0.0, 0.0, 0.0); LoanTestUtils.assertInstallmentDetails(loan, 6, 45.2, 0.8, 0.0, 0.0, 0.0); Assert.fail("Expected AccountException !!"); } catch (AccountException e) { } }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/*w w w. j a v a 2 s . c om*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] * ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static short[] add(final short[] array, final int index, final short element) { return (short[]) add(array, index, Short.valueOf(element), Short.TYPE); }
From source file:com.kylinolap.rest.service.QueryService.java
/** * @param preparedState//from ww w.j av a 2 s. c om * @param param * @throws SQLException */ private void setParam(PreparedStatement preparedState, int index, StateParam param) throws SQLException { boolean isNull = (null == param.getValue()); Class<?> clazz = Object.class; try { clazz = Class.forName(param.getClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } Rep rep = Rep.of(clazz); switch (rep) { case PRIMITIVE_CHAR: case CHARACTER: case STRING: preparedState.setString(index, isNull ? null : String.valueOf(param.getValue())); break; case PRIMITIVE_INT: case INTEGER: preparedState.setInt(index, isNull ? null : Integer.valueOf(param.getValue())); break; case PRIMITIVE_SHORT: case SHORT: preparedState.setShort(index, isNull ? null : Short.valueOf(param.getValue())); break; case PRIMITIVE_LONG: case LONG: preparedState.setLong(index, isNull ? null : Long.valueOf(param.getValue())); break; case PRIMITIVE_FLOAT: case FLOAT: preparedState.setFloat(index, isNull ? null : Float.valueOf(param.getValue())); break; case PRIMITIVE_DOUBLE: case DOUBLE: preparedState.setDouble(index, isNull ? null : Double.valueOf(param.getValue())); break; case PRIMITIVE_BOOLEAN: case BOOLEAN: preparedState.setBoolean(index, isNull ? null : Boolean.parseBoolean(param.getValue())); break; case PRIMITIVE_BYTE: case BYTE: preparedState.setByte(index, isNull ? null : Byte.valueOf(param.getValue())); break; case JAVA_UTIL_DATE: case JAVA_SQL_DATE: preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue())); break; case JAVA_SQL_TIME: preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue())); break; case JAVA_SQL_TIMESTAMP: preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue())); break; default: preparedState.setObject(index, isNull ? null : param.getValue()); } }