List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.openhab.binding.ihc.ws.IhcResourceInteractionService.java
private WSResourceValue parseResourceValue(Node n, int index) throws XPathExpressionException { // parse resource id String resourceId = getValue(n, "ns1:resourceID"); if (StringUtils.isNotBlank(resourceId)) { int id = Integer.parseInt(resourceId); // Parse floating point value String value = getValue(n, "ns1:value/ns" + index + ":floatingPointValue"); if (StringUtils.isNotBlank(value)) { WSFloatingPointValue val = new WSFloatingPointValue(); val.setResourceID(id); val.setFloatingPointValue(Double.valueOf(value)); value = getValue(n, "ns1:value/ns" + index + ":maximumValue"); if (StringUtils.isNotBlank(value)) { val.setMaximumValue(Double.valueOf(value)); }// w ww.ja va 2 s. c o m value = getValue(n, "ns1:value/ns" + index + ":minimumValue"); if (StringUtils.isNotBlank(value)) { val.setMinimumValue(Double.valueOf(value)); } return val; } // Parse boolean value value = getValue(n, "ns1:value/ns" + index + ":value"); if (StringUtils.isNotBlank(value)) { WSBooleanValue val = new WSBooleanValue(); val.setResourceID(id); val.setValue(Boolean.valueOf(value)); return val; } // Parse integer value value = getValue(n, "ns1:value/ns" + index + ":integer"); if (StringUtils.isNotBlank(value)) { WSIntegerValue val = new WSIntegerValue(); val.setResourceID(id); val.setInteger(Integer.valueOf(value)); value = getValue(n, "ns1:value/ns" + index + ":maximumValue"); if (StringUtils.isNotBlank(value)) { val.setMaximumValue(Integer.valueOf(value)); } value = getValue(n, "ns1:value/ns" + index + ":minimumValue"); if (StringUtils.isNotBlank(value)) { val.setMinimumValue(Integer.valueOf(value)); } return val; } // Parse timer value value = getValue(n, "ns1:value/ns" + index + ":milliseconds"); if (StringUtils.isNotBlank(value)) { WSTimerValue val = new WSTimerValue(); val.setResourceID(id); val.setMilliseconds(Integer.valueOf(value)); return val; } // Parse time value value = getValue(n, "ns1:value/ns" + index + ":hours"); if (StringUtils.isNotBlank(value)) { WSTimeValue val = new WSTimeValue(); val.setResourceID(id); val.setHours(Integer.valueOf(value)); value = getValue(n, "ns1:value/ns" + index + ":minutes"); if (StringUtils.isNotBlank(value)) { val.setMinutes(Integer.valueOf(value)); } value = getValue(n, "ns1:value/ns" + index + ":seconds"); if (StringUtils.isNotBlank(value)) { val.setSeconds(Integer.valueOf(value)); } return val; } // Parse date value value = getValue(n, "ns1:value/ns" + index + ":day"); if (StringUtils.isNotBlank(value)) { WSDateValue val = new WSDateValue(); val.setResourceID(id); val.setDay(Byte.valueOf(value)); value = getValue(n, "ns1:value/ns" + index + ":month"); if (StringUtils.isNotBlank(value)) { val.setMonth(Byte.valueOf(value)); } value = getValue(n, "ns1:value/ns" + index + ":year"); if (StringUtils.isNotBlank(value)) { val.setYear(Short.valueOf(value)); } return val; } // Parse enum value value = getValue(n, "ns1:value/ns" + index + ":definitionTypeID"); if (StringUtils.isNotBlank(value)) { WSEnumValue val = new WSEnumValue(); val.setResourceID(id); val.setDefinitionTypeID(Integer.valueOf(value)); value = getValue(n, "ns1:value/ns" + index + ":enumValueID"); if (StringUtils.isNotBlank(value)) { val.setEnumValueID(Integer.valueOf(value)); } value = getValue(n, "ns1:value/ns" + index + ":enumName"); if (StringUtils.isNotBlank(value)) { val.setEnumName(value); } return val; } // Parse week day value value = getValue(n, "ns1:value/ns" + index + ":weekdayNumber"); if (StringUtils.isNotBlank(value)) { WSWeekdayValue val = new WSWeekdayValue(); val.setResourceID(id); val.setWeekdayNumber(Integer.valueOf(value)); return val; } throw new IllegalArgumentException("Unsupported value type"); } return null; }
From source file:org.romaframework.core.schema.SchemaHelper.java
public static Object assignDefaultValueToLiteral(SchemaClass type) { Object value;//ww w.j av a 2 s. co m if (type.isOfType(Integer.TYPE)) { value = Integer.valueOf(0); } else if (type.isOfType(Long.TYPE)) { value = Long.valueOf(0); } else if (type.isOfType(Short.TYPE)) { value = Short.valueOf((short) 0); } else if (type.isOfType(Byte.TYPE)) { value = Byte.valueOf((byte) 0); } else if (type.isOfType(Float.TYPE)) { value = Float.valueOf(0); } else if (type.isOfType(Double.TYPE)) { value = Double.valueOf(0); } else { value = null; } return value; }
From source file:org.apache.rocketmq.jms.domain.message.JmsBaseMessage.java
@Override public byte getByteProperty(String name) throws JMSException { if (propertyExists(name)) { Object value = getObjectProperty(name); return value instanceof Byte ? (Byte) value : Byte.valueOf(value.toString()); }//from w w w . j a v a 2 s. c o m return 0; }
From source file:de.blizzy.backup.database.Database.java
public void initialize() { try {/*from w w w . j av a2s. c om*/ int sha256Length = DigestUtils.sha256Hex(StringUtils.EMPTY).length(); factory.query("CREATE TABLE IF NOT EXISTS backups (" + //$NON-NLS-1$ "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + //$NON-NLS-1$ "run_time DATETIME NOT NULL, " + //$NON-NLS-1$ "num_entries INT NULL" + //$NON-NLS-1$ ")") //$NON-NLS-1$ .execute(); int sampleBackupPathLength = Utils.createSampleBackupFilePath().length(); factory.query("CREATE TABLE IF NOT EXISTS files (" + //$NON-NLS-1$ "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + //$NON-NLS-1$ "backup_path VARCHAR(" + sampleBackupPathLength + ") NOT NULL, " + //$NON-NLS-1$ //$NON-NLS-2$ "checksum VARCHAR(" + sha256Length + ") NOT NULL, " + //$NON-NLS-1$ //$NON-NLS-2$ "length BIGINT NOT NULL, " + //$NON-NLS-1$ "compression TINYINT NOT NULL" + //$NON-NLS-1$ ")") //$NON-NLS-1$ .execute(); factory.query("CREATE INDEX IF NOT EXISTS idx_old_files ON files " + //$NON-NLS-1$ "(checksum, length)") //$NON-NLS-1$ .execute(); factory.query("CREATE TABLE IF NOT EXISTS entries (" + //$NON-NLS-1$ "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + //$NON-NLS-1$ "parent_id INT NULL, " + //$NON-NLS-1$ "backup_id INT NOT NULL, " + //$NON-NLS-1$ "type TINYINT NOT NULL, " + //$NON-NLS-1$ "creation_time DATETIME NULL, " + //$NON-NLS-1$ "modification_time DATETIME NULL, " + //$NON-NLS-1$ "hidden BOOLEAN NOT NULL, " + //$NON-NLS-1$ "name VARCHAR(1024) NOT NULL, " + //$NON-NLS-1$ "name_lower VARCHAR(1024) NOT NULL, " + //$NON-NLS-1$ "file_id INT NULL" + //$NON-NLS-1$ ")") //$NON-NLS-1$ .execute(); factory.query("CREATE INDEX IF NOT EXISTS idx_entries_files ON entries " + //$NON-NLS-1$ "(file_id)") //$NON-NLS-1$ .execute(); factory.query("CREATE INDEX IF NOT EXISTS idx_folder_entries ON entries " + //$NON-NLS-1$ "(backup_id, parent_id)") //$NON-NLS-1$ .execute(); factory.query("DROP INDEX IF EXISTS idx_entries_names") //$NON-NLS-1$ .execute(); factory.query("CREATE INDEX IF NOT EXISTS idx_entries_names2 ON entries " + //$NON-NLS-1$ "(name, backup_id, parent_id)") //$NON-NLS-1$ .execute(); if (!isTableColumnExistent("FILES", "COMPRESSION")) { //$NON-NLS-1$ //$NON-NLS-2$ factory.query( "ALTER TABLE files ADD compression TINYINT NULL DEFAULT " + Compression.GZIP.getValue()) //$NON-NLS-1$ .execute(); factory.update(Tables.FILES) .set(Tables.FILES.COMPRESSION, Byte.valueOf((byte) Compression.GZIP.getValue())).execute(); factory.query("ALTER TABLE files ALTER COLUMN compression TINYINT NOT NULL") //$NON-NLS-1$ .execute(); } if (getTableColumnSize("FILES", "CHECKSUM") != sha256Length) { //$NON-NLS-1$ //$NON-NLS-2$ factory.query("ALTER TABLE files ALTER COLUMN " + //$NON-NLS-1$ "checksum VARCHAR(" + sha256Length + ") NOT NULL") //$NON-NLS-1$ //$NON-NLS-2$ .execute(); } if (!isTableColumnExistent("ENTRIES", "NAME_LOWER")) { //$NON-NLS-1$ //$NON-NLS-2$ factory.query("ALTER TABLE entries ADD name_lower VARCHAR(1024) NULL") //$NON-NLS-1$ .execute(); factory.update(Tables.ENTRIES).set(Tables.ENTRIES.NAME_LOWER, Tables.ENTRIES.NAME.lower()) .execute(); factory.query("ALTER TABLE entries ALTER COLUMN name_lower VARCHAR(1024) NOT NULL") //$NON-NLS-1$ .execute(); } factory.query("CREATE INDEX IF NOT EXISTS idx_entries_search ON entries " + //$NON-NLS-1$ "(backup_id, name_lower)") //$NON-NLS-1$ .execute(); if (getTableColumnSize("FILES", "BACKUP_PATH") != sampleBackupPathLength) { //$NON-NLS-1$ //$NON-NLS-2$ Cursor<Record> cursor = null; try { cursor = factory.select(Tables.FILES.ID, Tables.FILES.BACKUP_PATH).from(Tables.FILES) .fetchLazy(); while (cursor.hasNext()) { Record record = cursor.fetchOne(); String backupPath = record.getValue(Tables.FILES.BACKUP_PATH); String backupFileName = StringUtils.substringAfterLast(backupPath, "/"); //$NON-NLS-1$ if (backupFileName.indexOf('-') > 0) { Integer id = record.getValue(Tables.FILES.ID); File backupFile = Utils.toBackupFile(backupPath, outputFolder); File folder = backupFile.getParentFile(); int maxIdx = Utils.getMaxBackupFileIndex(folder); int newIdx = maxIdx + 1; String newBackupFileName = Utils.toBackupFileName(newIdx); File newBackupFile = new File(folder, newBackupFileName); FileUtils.moveFile(backupFile, newBackupFile); String newBackupPath = StringUtils.substringBeforeLast(backupPath, "/") + "/" //$NON-NLS-1$//$NON-NLS-2$ + newBackupFileName; factory.update(Tables.FILES).set(Tables.FILES.BACKUP_PATH, newBackupPath) .where(Tables.FILES.ID.equal(id)).execute(); } } factory.query("ALTER TABLE files ALTER COLUMN backup_path VARCHAR(" + sampleBackupPathLength //$NON-NLS-1$ + ") NOT NULL") //$NON-NLS-1$ .execute(); } finally { closeQuietly(cursor); } } factory.query("ANALYZE") //$NON-NLS-1$ .execute(); } catch (SQLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.red5.server.service.ConversionUtils.java
/** * Convert number to primitive wrapper like Boolean or Float * @param num Number to conver * @param wrapper Primitive wrapper type * @return Converted object *//*from w ww .j a v a 2 s . c o m*/ public static Object convertNumberToWrapper(Number num, Class<?> wrapper) { //XXX Paul: Using valueOf will reduce object creation if (wrapper.equals(String.class)) { return num.toString(); } else if (wrapper.equals(Boolean.class)) { return Boolean.valueOf(num.intValue() == 1); } else if (wrapper.equals(Double.class)) { return Double.valueOf(num.doubleValue()); } else if (wrapper.equals(Long.class)) { return Long.valueOf(num.longValue()); } else if (wrapper.equals(Float.class)) { return Float.valueOf(num.floatValue()); } else if (wrapper.equals(Integer.class)) { return Integer.valueOf(num.intValue()); } else if (wrapper.equals(Short.class)) { return Short.valueOf(num.shortValue()); } else if (wrapper.equals(Byte.class)) { return Byte.valueOf(num.byteValue()); } throw new ConversionException("Unable to convert number to: " + wrapper); }
From source file:org.evosuite.testcase.ValueMinimizer.java
@SuppressWarnings("unchecked") private <N extends Number> N getZero(N n) { if (n instanceof Double) { return (N) (Double.valueOf(0.0)); } else if (n instanceof Float) { return (N) (Float.valueOf(0F)); } else if (n instanceof Integer) { return (N) (Integer.valueOf(0)); } else if (n instanceof Long) { return (N) Long.valueOf(0L); } else if (n instanceof Short) { return (N) Short.valueOf((short) 0); } else if (n instanceof Byte) { return (N) Byte.valueOf((byte) 0); } else if (n == null) { throw new NullPointerException(); } else {//from w w w . j a v a 2 s .c o m throw new IllegalArgumentException("Unexpected number type: " + n.getClass()); } }
From source file:org.jbuilt.utils.ValueClosure.java
public Object getConvertedValue(Object newValue, UIComponent component) { // Closure converterClosure = converterClosureMap.get(propertyType); // if(converterClosure != null){ // return converterClosure.execute(newValue); // }/*w w w .ja v a2s .c o m*/ // return newValue; // if(newValue == ""){ // newValue = "0"; // } if (propertyType.isAssignableFrom(Integer.class)) { if ("".equals(newValue)) { newValue = 0; } else { newValue = Integer.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Double.class)) { if ("".equals(newValue)) { newValue = 0.0; } else { newValue = Double.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(int.class)) { if ("".equals(newValue)) { newValue = 0; } else { newValue = Integer.parseInt((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(double.class)) { if ("".equals(newValue)) { newValue = 0.0; } else { newValue = Double.parseDouble((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Float.class)) { if ("".equals(newValue)) { newValue = 0.0; } else { newValue = Float.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Short.class)) { if ("".equals(newValue)) { newValue = 0; } else { newValue = Short.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Long.class)) { if ("".equals(newValue)) { newValue = 0; } else { newValue = Long.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Byte.class)) { if ("".equals(newValue)) { newValue = 0; } else { newValue = Byte.valueOf((String) newValue); } return newValue; } else if (propertyType.isAssignableFrom(Date.class)) { DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); Date date = null; try { date = df.parse((String) newValue); // System.out.println("Today = " + df.format(today)); } catch (ParseException e) { e.printStackTrace(); } newValue = date; return newValue; } else { // if no renderer don't need component argument } return newValue; }
From source file:com.itemanalysis.psychometrics.irt.estimation.StartingValues.java
/** * Creates a histogram of the latent values (theta) computed from the PROX procedure. The number of histogram * bins is computed by the Sturges method by default. This method counts the number of examinees in each bin to * get the nk values and it also computes the number of correct responses for examinees in each bin to get * pjk. The actual counts and actual number of correct responses at each theta level are the "E step" estimates * used by the optimizer to compute starting values. * * This method assumes that each examinee completes at least one binary item. * *//*from w w w . j a v a 2 s. c o m*/ private void computeEstepEstimates() { //create histogram hist = new Histogram(HistogramType.FREQUENCY); for (int l = 0; l < theta.length; l++) { //weighted analysis hist.increment(theta[l], responseVector[l].getFrequency()); } double[] freq = hist.evaluate(); int nBins = hist.getNumberOfBins(); estepEstimates = new EstepEstimates(nItems, ncat, nBins); //compute number of examinees at each theta level for (int t = 0; t < nBins; t++) { estepEstimates.incrementNt(t, freq[t]); } int x = 0; int value = 0; //count number correct at each theta level for each binary item for (int l = 0; l < nResponseVectors; l++) { for (int w = 0; w < responseVector[l].getFrequency(); w++) { for (int t = 0; t < nBins; t++) { if (hist.getBinAt(t).inBin(theta[l])) { for (int j = 0; j < nItems; j++) { x = Byte.valueOf(responseVector[l].getResponseAt(j)).intValue(); if (x != -1) { if (irm[j].getType() == IrmType.L3 || irm[j].getType() == IrmType.L4) { for (int k = 0; k < ncat[j]; k++) { value = 0; if (x == k) value = 1; estepEstimates.incrementRjkt(j, k, t, value); } } } } } } } } //For debugging //System.out.println(estepEstimates.toString()); }
From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java
@Test public void testConvertValue() throws Exception { Class[] classes = new Class[] { Object.class, Class.class }; // Null value assertThat(invoke("convertValue", classes, null, Long.TYPE)).isEqualTo(0l); assertThat(invoke("convertValue", classes, null, String.class)).isNull(); // Primitive// w w w . ja v a 2s.c om assertThat(invoke("convertValue", classes, "42", Integer.class)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Integer.TYPE)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Byte.class)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Byte.TYPE)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.class)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.TYPE)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.class)).isEqualTo('c'); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.TYPE)).isEqualTo('c'); assertThat(invoke("convertValue", classes, "42", Long.class)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "42", Long.TYPE)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "true", Boolean.class)).isEqualTo(true); assertThat(invoke("convertValue", classes, "true", Boolean.TYPE)).isEqualTo(true); assertThat(invoke("convertValue", classes, "42", Double.class)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Double.TYPE)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Float.class)).isEqualTo(42.0f); assertThat(invoke("convertValue", classes, "42", Float.TYPE)).isEqualTo(42.0f); // BigInteger, BigDecimal and String assertThat(invoke("convertValue", classes, "42", BigDecimal.class)).isEqualTo(new BigDecimal("42")); assertThat(invoke("convertValue", classes, "42", BigInteger.class)).isEqualTo(new BigInteger("42")); assertThat(invoke("convertValue", classes, "42", String.class)).isEqualTo("42"); //Array assertThat(invoke("convertValue", classes, new Object[] { 1, 2, 3 }, (new int[0]).getClass())).isNotNull(); }
From source file:org.red5.io.utils.ConversionUtils.java
/** * Convert string to primitive wrapper like Boolean or Float * /* ww w . j a va2 s . c o m*/ * @param str * String to convert * @param wrapper * Primitive wrapper type * @return Converted object */ public static Object convertStringToWrapper(String str, Class<?> wrapper) { log.trace("String: {} to wrapper: {}", str, wrapper); if (wrapper.equals(String.class)) { return str; } else if (wrapper.equals(Boolean.class)) { return Boolean.valueOf(str); } else if (wrapper.equals(Double.class)) { return Double.valueOf(str); } else if (wrapper.equals(Long.class)) { return Long.valueOf(str); } else if (wrapper.equals(Float.class)) { return Float.valueOf(str); } else if (wrapper.equals(Integer.class)) { return Integer.valueOf(str); } else if (wrapper.equals(Short.class)) { return Short.valueOf(str); } else if (wrapper.equals(Byte.class)) { return Byte.valueOf(str); } throw new ConversionException(String.format("Unable to convert string to: %s", wrapper)); }