List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.unitime.timetable.backup.SessionRestore.java
protected Object get(Class clazz, String id) { if (clazz.equals(String.class) || clazz.equals(StringType.class)) return id; if (clazz.equals(Character.class) || clazz.equals(CharacterType.class)) return (id == null || id.isEmpty() ? null : id.charAt(0)); if (clazz.equals(Byte.class) || clazz.equals(ByteType.class)) return Byte.valueOf(id); if (clazz.equals(Short.class) || clazz.equals(ShortType.class)) return Short.valueOf(id); if (clazz.equals(Integer.class) || clazz.equals(IntegerType.class)) return Integer.valueOf(id); if (clazz.equals(Long.class) || clazz.equals(LongType.class)) return Long.valueOf(id); if (clazz.equals(Float.class) || clazz.equals(FloatType.class)) return Float.valueOf(id); if (clazz.equals(Double.class) || clazz.equals(DoubleType.class)) return Double.valueOf(id); if (clazz.equals(Boolean.class) || clazz.equals(BooleanType.class)) return Boolean.valueOf(id); Map<String, Entity> entities = iEntities.get(clazz.getName()); if (entities != null) { Entity entity = entities.get(id); if (entity != null) return entity.getObject(); }/*from ww w . jav a 2 s. co m*/ for (Map.Entry<String, Map<String, Entity>> entry : iEntities.entrySet()) { Entity o = entry.getValue().get(id); if (o != null && clazz.isInstance(o.getObject())) return o.getObject(); } if (clazz.equals(Session.class)) return ((Entity) iEntities.get(Session.class.getName()).values().iterator().next()).getObject(); if (clazz.equals(Student.class)) return checkUnknown(clazz, id, iStudents.get(id)); if (iIsClone) return checkUnknown(clazz, id, iHibSession.get(clazz, clazz.equals(ItypeDesc.class) ? (Serializable) Integer.valueOf(id) : (Serializable) Long.valueOf(id))); return checkUnknown(clazz, id, null); }
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 w w w .j a v a 2s.com*/ * * <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, 3) = [2, 6, 3] * ArrayUtils.add([2, 6], 0, 1) = [1, 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 byte[] add(final byte[] array, final int index, final byte element) { return (byte[]) add(array, index, Byte.valueOf(element), Byte.TYPE); }
From source file:org.apache.nifi.avro.AvroTypeUtil.java
public static Object[] convertByteArray(final byte[] bytes) { final Object[] array = new Object[bytes.length]; for (int i = 0; i < bytes.length; i++) { array[i] = Byte.valueOf(bytes[i]); }// w w w. j ava 2s . com return array; }
From source file:de.blizzy.backup.backup.BackupRun.java
private int findOldFileViaTimestamp(IFile file) throws IOException { FileTime lastModificationTime = file.getLastModificationTime(); long length = file.getLength(); Cursor<Record> cursor = null; try {/*from ww w. j a va 2s .co m*/ cursor = database.factory().select(Tables.BACKUPS.ID).from(Tables.BACKUPS) .where(Tables.BACKUPS.ID.notEqual(Integer.valueOf(backupId))) .orderBy(Tables.BACKUPS.RUN_TIME.desc()).fetchLazy(); while (cursor.hasNext()) { int backupId = cursor.fetchOne().getValue(Tables.BACKUPS.ID).intValue(); int entryId = findFileOrFolderEntryInBackup(file, backupId); if (entryId > 0) { Record record = database.factory() .select(Tables.ENTRIES.MODIFICATION_TIME, Tables.FILES.ID, Tables.FILES.LENGTH) .from(Tables.ENTRIES).join(Tables.FILES) .on(Tables.FILES.ID.equal(Tables.ENTRIES.FILE_ID)) .where(Tables.ENTRIES.ID.equal(Integer.valueOf(entryId)), Tables.ENTRIES.TYPE.equal(Byte.valueOf((byte) EntryType.FILE.getValue()))) .fetchAny(); if (record != null) { Timestamp entryModTime = record.getValue(Tables.ENTRIES.MODIFICATION_TIME); long entryModificationTime = (entryModTime != null) ? entryModTime.getTime() : -1; long entryLength = record.getValue(Tables.FILES.LENGTH).longValue(); if ((entryModificationTime > 0) && (lastModificationTime != null) && (entryModificationTime == lastModificationTime.toMillis()) && (entryLength == length)) { return record.getValue(Tables.FILES.ID).intValue(); } } } } } finally { database.closeQuietly(cursor); } return -1; }
From source file:org.apache.hadoop.hive.ql.optimizer.MapJoinProcessor.java
/** * convert a sortmerge join to a a map-side join. * * @param opParseCtxMap/*from ww w. j a v a2 s. c o m*/ * @param smbJoinOp * join operator * @param joinTree * qb join tree * @param bigTablePos * position of the source to be read as part of map-reduce framework. All other sources * are cached in memory * @param noCheckOuterJoin */ public static MapJoinOperator convertSMBJoinToMapJoin(HiveConf hconf, SMBMapJoinOperator smbJoinOp, int bigTablePos, boolean noCheckOuterJoin) throws SemanticException { // Create a new map join operator SMBJoinDesc smbJoinDesc = smbJoinOp.getConf(); List<ExprNodeDesc> keyCols = smbJoinDesc.getKeys().get(Byte.valueOf((byte) 0)); TableDesc keyTableDesc = PlanUtils.getMapJoinKeyTableDesc(hconf, PlanUtils.getFieldSchemasFromColumnList(keyCols, MAPJOINKEY_FIELDPREFIX)); MapJoinDesc mapJoinDesc = new MapJoinDesc(smbJoinDesc.getKeys(), keyTableDesc, smbJoinDesc.getExprs(), smbJoinDesc.getValueTblDescs(), smbJoinDesc.getValueTblDescs(), smbJoinDesc.getOutputColumnNames(), bigTablePos, smbJoinDesc.getConds(), smbJoinDesc.getFilters(), smbJoinDesc.isNoOuterJoin(), smbJoinDesc.getDumpFilePrefix()); mapJoinDesc.setStatistics(smbJoinDesc.getStatistics()); RowSchema joinRS = smbJoinOp.getSchema(); // The mapjoin has the same schema as the join operator MapJoinOperator mapJoinOp = (MapJoinOperator) OperatorFactory.getAndMakeChild(mapJoinDesc, joinRS, new ArrayList<Operator<? extends OperatorDesc>>()); // change the children of the original join operator to point to the map // join operator List<Operator<? extends OperatorDesc>> childOps = smbJoinOp.getChildOperators(); for (Operator<? extends OperatorDesc> childOp : childOps) { childOp.replaceParent(smbJoinOp, mapJoinOp); } mapJoinOp.setChildOperators(childOps); smbJoinOp.setChildOperators(null); // change the parent of the original SMBjoin operator to point to the map // join operator List<Operator<? extends OperatorDesc>> parentOps = smbJoinOp.getParentOperators(); for (Operator<? extends OperatorDesc> parentOp : parentOps) { parentOp.replaceChild(smbJoinOp, mapJoinOp); } mapJoinOp.setParentOperators(parentOps); smbJoinOp.setParentOperators(null); return mapJoinOp; }
From source file:com.streamsets.pipeline.stage.processor.fieldvaluereplacer.FieldValueReplacerProcessor.java
private Object convertToType(String stringValue, Field.Type fieldType, String matchingField) throws ParseException { switch (fieldType) { case BOOLEAN: return Boolean.valueOf(stringValue); case BYTE:/*from w w w .j a v a 2s. co m*/ return Byte.valueOf(stringValue); case BYTE_ARRAY: return stringValue.getBytes(StandardCharsets.UTF_8); case CHAR: return stringValue.charAt(0); case DATE: DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); return dateFormat.parse(stringValue); case TIME: DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH); return timeFormat.parse(stringValue); case DATETIME: DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.ENGLISH); return dateTimeFormat.parse(stringValue); case DECIMAL: return new BigDecimal(stringValue); case DOUBLE: return Double.valueOf(stringValue); case FLOAT: return Float.valueOf(stringValue); case INTEGER: return Integer.valueOf(stringValue); case LONG: return Long.valueOf(stringValue); case SHORT: return Short.valueOf(stringValue); case FILE_REF: throw new IllegalArgumentException( Utils.format(Errors.VALUE_REPLACER_03.getMessage(), fieldType, matchingField)); case LIST_MAP: case LIST: case MAP: default: return stringValue; } }
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 w w w .jav a2 s.c o 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:org.op4j.functions.FnObject.java
/** * <p>//from w w w. java 2 s.com * Determines whether the target object and the specified object are NOT equal * in value, this is, whether <tt>target.compareTo(object) != 0</tt>. Both * the target and the specified object have to implement {@link Comparable}. * </p> * * @param object the object to compare to the target * @return false if both objects are equal according to "compareTo", true if not. */ public static final Function<Object, Boolean> notEqValue(final byte object) { return new NotEqualValue(Byte.valueOf(object)); }
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 va 2s . co 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:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>// ww w .j ava 2 s . co m * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }