List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:Util.java
/** * Return a <code>Color</code> object given a string representation of it * * @param color// w w w . ja v a 2 s. com * @return string representation * @throws IllegalArgumentException if string in bad format */ public static Color stringToColor(String s) { try { return new Color(Integer.decode("0x" + s.substring(1, 3)).intValue(), Integer.decode("0x" + s.substring(3, 5)).intValue(), Integer.decode("0x" + s.substring(5, 7)).intValue()); } catch (Exception e) { return null; } }
From source file:edu.cornell.mannlib.vedit.util.OperationUtils.java
public static void beanSetAndValidate(Object newObj, String field, String value, EditProcessObject epo) { Class<?> cls = (epo.getBeanClass() != null) ? epo.getBeanClass() : newObj.getClass(); Class<?>[] paramList = new Class[1]; paramList[0] = String.class; boolean isInt = false; boolean isBoolean = false; Method setterMethod = null;// w ww . ja v a2 s. co m try { setterMethod = cls.getMethod("set" + field, paramList); } catch (NoSuchMethodException e) { // let's try int paramList[0] = int.class; try { setterMethod = cls.getMethod("set" + field, paramList); isInt = true; } catch (NoSuchMethodException f) { // let's try boolean paramList[0] = boolean.class; try { setterMethod = cls.getMethod("set" + field, paramList); isBoolean = true; log.debug("found boolean field " + field); } catch (NoSuchMethodException g) { log.error("beanSet could not find an appropriate String, int, or boolean setter method for " + field); } } } Object[] arglist = new Object[1]; if (isInt) arglist[0] = Integer.decode(value); else if (isBoolean) arglist[0] = (value.equalsIgnoreCase("TRUE")); else arglist[0] = value; try { setterMethod.invoke(newObj, arglist); } catch (Exception e) { log.error("Couldn't invoke method"); log.error(e.getMessage()); log.error(field + " " + arglist[0]); } }
From source file:org.patientview.patientview.patiententry.SysGreaterThanDiaValidator.java
public static boolean sysGreaterThanDia(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) {//ww w.ja v a 2s .co m String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { int intValue = Integer.decode(value); int intValue2 = Integer.decode(value2); if (intValue2 <= intValue) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } return true; }
From source file:com.github.fritaly.graphml4j.Utils.java
/** * Decodes the given hexadecimal string (like "#RRGGBBAA" or "#RRGGBB" * (whether the transparency is set to 0)) into an instance of {@link Color} * ./*from w ww .ja va 2 s. c om*/ * * @param value * a string representing the encoded color.Can't be null. * @return a {@link Color}. */ static Color decode(String value) { Validate.notNull(value, "The given encoded value is null"); if (value.length() == 9) { final int i = Integer.decode(value).intValue(); return new Color((i >> 24) & 0xFF, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF); } return Color.decode(value); }
From source file:org.rti.zcore.dar.transfer.access.IntegerConverter.java
@Override public Object fromString(String str) { /* If empty tag. */ if (str.compareTo("") == 0) { /* Default to zero. */ str = "0"; }/* w w w .j ava2 s .c om*/ Integer value = null; try { value = Integer.decode(str); } catch (NumberFormatException e) { try { Float floatValue = Float.valueOf(str); value = floatValue.intValue(); } catch (NumberFormatException e1) { log.debug(e); } } return value; }
From source file:SystemProperty.java
/** * Returns the value of a system property as an integer. * If such a system property exists it is converted to an integer with * <tt>Integer.decode(String)</tt>. * Returns the specified default value if no such system property exists or * the property value is invalid./*w ww. j a v a2s . c o m*/ * * @return * the integer value of the specified property */ public static int intValue(String propName, int defaultValue) { String prop = System.getProperty(propName); int val; if (prop == null) val = defaultValue; else { try { val = Integer.decode(prop.trim()).intValue(); } catch (NumberFormatException e) { val = defaultValue; } } return val; }
From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.adapters.fields.TextAreaFieldAdapter.java
@Override protected FieldDefinition getFieldDefinition(Field originalField) { TextAreaFieldDefinition fieldDefinition = new TextAreaFieldDefinition(); if (!StringUtils.isEmpty(originalField.getHeight()) && StringUtils.isNumeric(originalField.getHeight())) { fieldDefinition.setRows(Integer.decode(originalField.getHeight())); }// w ww .ja v a 2 s. c o m return fieldDefinition; }
From source file:NumberUtils.java
/** * Parse the given text into a number instance of the given target class, * using the corresponding default <code>decode</code> methods. Trims the * input <code>String</code> before attempting to parse the number. Supports * numbers in hex format (with leading 0x) and in octal format (with leading 0). * @param text the text to convert//from ww w . j ava 2s. c o m * @param targetClass the target class to parse into * @return the parsed number * @throws IllegalArgumentException if the target class is not supported * (i.e. not a standard Number subclass as included in the JDK) * @see java.lang.Byte#decode * @see java.lang.Short#decode * @see java.lang.Integer#decode * @see java.lang.Long#decode * @see #decodeBigInteger(String) * @see java.lang.Float#valueOf * @see java.lang.Double#valueOf * @see java.math.BigDecimal#BigDecimal(String) */ public static Number parseNumber(String text, Class<?> targetClass) { // Assert.notNull(text, "Text must not be null"); //Assert.notNull(targetClass, "Target class must not be null"); String trimmed = text.trim(); if (targetClass.equals(Byte.class)) { return Byte.decode(trimmed); } else if (targetClass.equals(Short.class)) { return Short.decode(trimmed); } else if (targetClass.equals(Integer.class)) { return Integer.decode(trimmed); } else if (targetClass.equals(Long.class)) { return Long.decode(trimmed); } else if (targetClass.equals(BigInteger.class)) { return decodeBigInteger(trimmed); } else if (targetClass.equals(Float.class)) { return Float.valueOf(trimmed); } else if (targetClass.equals(Double.class)) { return Double.valueOf(trimmed); } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) { return new BigDecimal(trimmed); } else { throw new IllegalArgumentException( "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]"); } }
From source file:se.trixon.almond.GraphicsHelper.java
public static int colorToHexInt(Color color) { return Integer.decode("0x" + colorToHex(color)); }
From source file:org.apache.tajo.validation.MaxValidator.java
@Override protected <T> boolean validateInternal(T object) { boolean result = false; if (object != null) { if ((object instanceof Byte) || (object instanceof Short) || (object instanceof Integer)) { Integer objInteger = Integer.decode(object.toString()); Integer maxInteger = Integer.decode(maxValue); result = objInteger.compareTo(maxInteger) <= 0; } else if (object instanceof Long) { Long objLong = Long.decode(object.toString()); Long maxLong = Long.decode(maxValue); result = objLong.compareTo(maxLong) <= 0; } else if ((object instanceof Float) || (object instanceof Double)) { Double objDouble = Double.valueOf(object.toString()); Double maxDouble = Double.valueOf(maxValue); result = objDouble.compareTo(maxDouble) <= 0; } else if (object instanceof BigInteger) { BigInteger objInteger = (BigInteger) object; BigInteger maxInteger = new BigInteger(maxValue); result = objInteger.compareTo(maxInteger) <= 0; } else if (object instanceof BigDecimal) { BigDecimal objDecimal = (BigDecimal) object; BigDecimal maxDecimal = new BigDecimal(maxValue); result = objDecimal.compareTo(maxDecimal) <= 0; }/*from w w w .j av a2s.c o m*/ } else { result = true; } return result; }