List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:org.plasma.sdo.helper.DataConverter.java
public Object fromFloat(Type targetType, float value) { DataType targetDataType = DataType.valueOf(targetType.getName()); switch (targetDataType) { case Float: return Float.valueOf(value); case Byte: return new Byte(Float.valueOf(value).byteValue()); case Double: return new Double(Float.valueOf(value).doubleValue()); case Int:/*w ww .jav a 2 s .c o m*/ return new Integer(Float.valueOf(value).intValue()); case Long: return new Long(Float.valueOf(value).longValue()); case Short: return new Short(Float.valueOf(value).shortValue()); case Decimal: return BigDecimal.valueOf(value); case Integer: return BigInteger.valueOf(Double.valueOf(value).longValue()); case String: // as per spec: Decimal | 'NaN' | '-NaN' | 'Infinity' | '-Infinity' return Float.toString(value); default: throw new InvalidDataConversionException(targetDataType, DataType.Float, value); } }
From source file:org.teiid.rhq.plugin.util.ProfileServiceUtil.java
public static SimpleValue wrap(MetaType type, String value) throws Exception { if (type instanceof SimpleMetaType) { SimpleMetaType st = (SimpleMetaType) type; if (SimpleMetaType.BIGDECIMAL.equals(st)) { return new SimpleValueSupport(st, new BigDecimal(value)); } else if (SimpleMetaType.BIGINTEGER.equals(st)) { return new SimpleValueSupport(st, new BigInteger(value)); } else if (SimpleMetaType.BOOLEAN.equals(st)) { return new SimpleValueSupport(st, Boolean.valueOf(value)); } else if (SimpleMetaType.BOOLEAN_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Boolean.valueOf(value).booleanValue()); } else if (SimpleMetaType.BYTE.equals(st)) { return new SimpleValueSupport(st, new Byte(value.getBytes()[0])); } else if (SimpleMetaType.BYTE_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, value.getBytes()[0]); } else if (SimpleMetaType.CHARACTER.equals(st)) { return new SimpleValueSupport(st, new Character(value.charAt(0))); } else if (SimpleMetaType.CHARACTER_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, value.charAt(0)); } else if (SimpleMetaType.DATE.equals(st)) { try { return new SimpleValueSupport(st, SimpleDateFormat.getInstance().parse(value)); } catch (ParseException e) { throw new Exception("Failed to convert value to SimpleValue", e); //$NON-NLS-1$ }//from ww w .j a v a2s. co m } else if (SimpleMetaType.DOUBLE.equals(st)) { return new SimpleValueSupport(st, Double.valueOf(value)); } else if (SimpleMetaType.DOUBLE_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Double.parseDouble(value)); } else if (SimpleMetaType.FLOAT.equals(st)) { return new SimpleValueSupport(st, Float.parseFloat(value)); } else if (SimpleMetaType.FLOAT_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Float.valueOf(value)); } else if (SimpleMetaType.INTEGER.equals(st)) { return new SimpleValueSupport(st, Integer.valueOf(value)); } else if (SimpleMetaType.INTEGER_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Integer.parseInt(value)); } else if (SimpleMetaType.LONG.equals(st)) { return new SimpleValueSupport(st, Long.valueOf(value)); } else if (SimpleMetaType.LONG_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Long.parseLong(value)); } else if (SimpleMetaType.SHORT.equals(st)) { return new SimpleValueSupport(st, Short.valueOf(value)); } else if (SimpleMetaType.SHORT_PRIMITIVE.equals(st)) { return new SimpleValueSupport(st, Short.parseShort(value)); } else if (SimpleMetaType.STRING.equals(st)) { return new SimpleValueSupport(st, value); } } throw new Exception("Failed to convert value to SimpleValue"); //$NON-NLS-1$ }
From source file:com.jaspersoft.jasperserver.api.engine.scheduling.quartz.ReportJobsQuartzScheduler.java
protected String getCronExpression(ReportJobCalendarTrigger jobTrigger) { String minutes = jobTrigger.getMinutes(); String hours = jobTrigger.getHours(); String weekDays;/*from www . j ava 2 s.c o m*/ String monthDays; switch (jobTrigger.getDaysType()) { case ReportJobCalendarTrigger.DAYS_TYPE_ALL: weekDays = "?"; monthDays = "*"; break; case ReportJobCalendarTrigger.DAYS_TYPE_WEEK: weekDays = enumerateCronVals(jobTrigger.getWeekDays(), COUNT_WEEKDAYS); monthDays = "?"; break; case ReportJobCalendarTrigger.DAYS_TYPE_MONTH: weekDays = "?"; monthDays = jobTrigger.getMonthDays(); break; default: throw new JSException("jsexception.job.unknown.calendar.trigger.days.type", new Object[] { new Byte(jobTrigger.getDaysType()) }); } String months = enumerateCronVals(jobTrigger.getMonths(), COUNT_MONTHS); StringBuffer cronExpression = new StringBuffer(); cronExpression.append("0 "); cronExpression.append(minutes); cronExpression.append(' '); cronExpression.append(hours); cronExpression.append(' '); cronExpression.append(monthDays); cronExpression.append(' '); cronExpression.append(months); cronExpression.append(' '); cronExpression.append(weekDays); return cronExpression.toString(); }
From source file:org.acoveo.tools.Reflection.java
/** * Invoke the given setter on the given object. *//*w w w.j a v a 2 s . c o m*/ public static void set(Object target, Method setter, byte value) { set(target, setter, new Byte(value)); }
From source file:net.sourceforge.msscodefactory.cfsecurity.v2_0.CFSecurityXMsgClient.CFSecurityXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/*ww w. j a v a 2 s. com*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFSecurityXMsgClientSchema.class, "getNullableByte", e); } }
From source file:net.sf.json.TestJSONArray.java
public void testFromObject_Byte() { JSONArray expected = JSONArray.fromObject("[1]"); JSONArray actual = JSONArray.fromObject(new Byte((byte) 1)); Assertions.assertEquals(expected, actual); }
From source file:org.apache.catalina.core.NamingContextListener.java
/** * Set the specified environment entries in the naming context. *//*ww w . j a va 2 s.c o m*/ public void addEnvironment(ContextEnvironment env) { Object value = null; // Instantiating a new instance of the correct object type, and // initializing it. String type = env.getType(); try { if (type.equals("java.lang.String")) { value = env.getValue(); } else if (type.equals("java.lang.Byte")) { if (env.getValue() == null) { value = new Byte((byte) 0); } else { value = Byte.decode(env.getValue()); } } else if (type.equals("java.lang.Short")) { if (env.getValue() == null) { value = new Short((short) 0); } else { value = Short.decode(env.getValue()); } } else if (type.equals("java.lang.Integer")) { if (env.getValue() == null) { value = new Integer(0); } else { value = Integer.decode(env.getValue()); } } else if (type.equals("java.lang.Long")) { if (env.getValue() == null) { value = new Long(0); } else { value = Long.decode(env.getValue()); } } else if (type.equals("java.lang.Boolean")) { value = Boolean.valueOf(env.getValue()); } else if (type.equals("java.lang.Double")) { if (env.getValue() == null) { value = new Double(0); } else { value = Double.valueOf(env.getValue()); } } else if (type.equals("java.lang.Float")) { if (env.getValue() == null) { value = new Float(0); } else { value = Float.valueOf(env.getValue()); } } else if (type.equals("java.lang.Character")) { if (env.getValue() == null) { value = new Character((char) 0); } else { if (env.getValue().length() == 1) { value = new Character(env.getValue().charAt(0)); } else { throw new IllegalArgumentException(); } } } else { log(sm.getString("naming.invalidEnvEntryType", env.getName())); } } catch (NumberFormatException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } catch (IllegalArgumentException e) { log(sm.getString("naming.invalidEnvEntryValue", env.getName())); } // Binding the object to the appropriate name if (value != null) { try { if (debug >= 2) log(" Adding environment entry " + env.getName()); createSubcontexts(envCtx, env.getName()); envCtx.bind(env.getName(), value); } catch (NamingException e) { log(sm.getString("naming.invalidEnvEntryValue", e)); } } }
From source file:com.willwinder.universalgcodesender.GrblControllerTest.java
/** * Test of pauseStreaming method, of class GrblController. *///from w w w .j a v a2s. c o m @Test public void testPauseStreaming() throws Exception { System.out.println("pauseStreaming"); GrblController instance = new GrblController(mgc); instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234); assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); instance.pauseStreaming(); assertEquals(1, mgc.numPauseSendCalls); mgc.sentBytes.clear(); instance.rawResponseHandler("Grbl 0.7"); instance.pauseStreaming(); assertEquals(2, mgc.numPauseSendCalls); assertEquals(0, mgc.sentBytes.size()); instance.rawResponseHandler("Grbl 0.8c"); instance.pauseStreaming(); assertEquals(3, mgc.numPauseSendCalls); assertEquals(new Byte(GrblUtils.GRBL_PAUSE_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); }
From source file:org.plasma.sdo.helper.DataConverter.java
public Object fromInt(Type targetType, int value) { DataType targetDataType = DataType.valueOf(targetType.getName()); switch (targetDataType) { case Int:/* w w w . j a va 2 s. co m*/ return Integer.valueOf(value); case Byte: return new Byte(Integer.valueOf(value).byteValue()); case Double: return new Double(Integer.valueOf(value).doubleValue()); case Float: return new Float(Integer.valueOf(value).floatValue()); case Long: return new Long(Integer.valueOf(value).longValue()); case Short: return new Short(Integer.valueOf(value).shortValue()); case Decimal: return BigDecimal.valueOf(value); case Integer: return BigInteger.valueOf(Integer.valueOf(value).longValue()); case String: return Integer.toString(value); default: throw new InvalidDataConversionException(targetDataType, DataType.Int, value); } }
From source file:org.apache.axis2.corba.receivers.CorbaUtil.java
public static Object extractValue(DataType returnType, Any returned) { Object returnValue = null;/*from w ww . j ava2 s. co m*/ TypeCode typeCode = returnType.getTypeCode(); switch (typeCode.kind().value()) { case TCKind._tk_void: returnValue = null; break; case TCKind._tk_long: returnValue = new Integer(returned.extract_long()); break; case TCKind._tk_ulong: returnValue = new Integer(returned.extract_ulong()); break; case TCKind._tk_longlong: returnValue = new Long(returned.extract_longlong()); break; case TCKind._tk_ulonglong: returnValue = new Long(returned.extract_ulonglong()); break; case TCKind._tk_short: returnValue = new Short(returned.extract_short()); break; case TCKind._tk_ushort: returnValue = new Short(returned.extract_ushort()); break; case TCKind._tk_float: returnValue = new Float(returned.extract_float()); break; case TCKind._tk_double: returnValue = new Double(returned.extract_double()); break; case TCKind._tk_char: returnValue = new Character(returned.extract_char()); break; case TCKind._tk_wchar: returnValue = new Character(returned.extract_wchar()); break; case TCKind._tk_boolean: returnValue = Boolean.valueOf(returned.extract_boolean()); break; case TCKind._tk_octet: returnValue = new Byte(returned.extract_octet()); break; case TCKind._tk_string: returnValue = returned.extract_string(); break; case TCKind._tk_wstring: returnValue = returned.extract_wstring(); break; case TCKind._tk_any: returnValue = returned.extract_any(); break; case TCKind._tk_value: returnValue = returned.extract_Value(); break; case TCKind._tk_objref: returnValue = returned.extract_Object(); break; //case TCKind._tk_longdouble : case TCKind._tk_struct: Struct struct = (Struct) returnType; StructValue structValue = new StructValue(struct); org.omg.CORBA_2_3.portable.InputStream inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned .create_input_stream(); structValue.read(inputStream); returnValue = structValue; break; case TCKind._tk_except: ExceptionType exceptionType = (ExceptionType) returnType; ExceptionValue exceptionValue = new ExceptionValue(exceptionType); inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); exceptionValue.read(inputStream); returnValue = exceptionValue; break; case TCKind._tk_enum: EnumType enumType = (EnumType) returnType; EnumValue enumValue = new EnumValue(enumType); inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); enumValue.read(inputStream); returnValue = enumValue; break; case TCKind._tk_union: UnionType unionType = (UnionType) returnType; inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); UnionValue unionValue = new UnionValue(unionType); unionValue.read(inputStream); returnValue = unionValue; break; case TCKind._tk_alias: Typedef typedef = (Typedef) returnType; inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); AliasValue aliasValue = new AliasValue(typedef); aliasValue.read(inputStream); returnValue = aliasValue; break; case TCKind._tk_sequence: SequenceType sequenceType = (SequenceType) returnType; inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); SequenceValue sequenceValue = new SequenceValue(sequenceType); sequenceValue.read(inputStream); returnValue = sequenceValue; break; case TCKind._tk_array: ArrayType arrayType = (ArrayType) returnType; inputStream = (org.omg.CORBA_2_3.portable.InputStream) returned.create_input_stream(); ArrayValue arrayValue = new ArrayValue(arrayType); arrayValue.read(inputStream); returnValue = arrayValue; break; default: log.error("ERROR! Invalid dataType"); break; } return returnValue; }