List of usage examples for java.lang Number intValue
public abstract int intValue();
From source file:com.fengduo.bee.commons.core.lang.Argument.java
public static boolean isPositive(Number argument) { if (null == argument) { return false; }/*from ww w . ja v a 2 s. c o m*/ return argument.floatValue() > 0f || argument.intValue() > 0; }
From source file:com.mmj.app.common.core.lang.Argument.java
public static boolean isPositive(Number argument) { if (argument == null) { return false; }//from w w w . j a v a2 s . c o m return argument.floatValue() > 0f || argument.intValue() > 0; }
From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java
public static int[] convertToIntArray(final Object array) { if (array == null) { return null; }//from ww w . j av a 2 s .c o m if (array instanceof int[]) { return (int[]) array; } if (array instanceof Integer[]) { return ArrayUtils.toPrimitive((Integer[]) array); } final int[] newArray = new int[Array.getLength(array)]; for (int i = 0; i < newArray.length; i++) { final Number val = (Number) Array.get(array, i); newArray[i] = val.intValue(); } return newArray; }
From source file:org.ambraproject.wombat.controller.WombatController.java
protected static int getFeedLength(Site site) throws IOException { Map<String, Object> feedConfig = site.getTheme().getConfigMap("feed"); Number length = (Number) feedConfig.get("length"); return length.intValue(); }
From source file:net.dontdrinkandroot.utils.lang.math.NumberUtils.java
/** * Get the null safe intValue of a Number. Defaults to 0. * /*w ww . j a v a 2s . c o m*/ * @param number * The Number to convert. * @return The null safe intValue. Defaults to 0. */ public static int intValue(final Number number) { if (number == null) { return 0; } return number.intValue(); }
From source file:Main.java
static Object convert(Object[] objects, Object var) { Object newVar = getObject(objects); if (newVar instanceof Number) { Number newNum = (Number) var; if (newVar instanceof Integer) { return new Integer(newNum.intValue()); } else if (newVar instanceof Long) { return new Long(newNum.longValue()); } else if (newVar instanceof Float) { return new Float(newNum.floatValue()); } else if (newVar instanceof Double) { return new Double(newNum.doubleValue()); } else {/*from w w w.j a v a2 s .c om*/ return null; } } else if (newVar instanceof String) { return new String((String) newVar); } else { //TODO: add other classes return null; } }
From source file:Main.java
/** * Casts an object to the specified type * * @param var/* w ww .ja v a 2 s . c om*/ * @param type * */ static Object convert(Object var, Class type) { if (var instanceof Number) { //use number conversion Number newNum = (Number) var; if (type == Integer.class) { return new Integer(newNum.intValue()); } else if (type == Long.class) { return new Long(newNum.longValue()); } else if (type == Float.class) { return new Float(newNum.floatValue()); } else if (type == Double.class) { return new Double(newNum.doubleValue()); } else if (type == String.class) { return new String(newNum.toString()); } } else { //direct cast if (type == Integer.class) { return new Integer(((Integer) var).intValue()); } else if (type == Long.class) { return new Long(((Long) var).longValue()); } else if (type == Float.class) { return new Float(((Float) var).floatValue()); } else if (type == Double.class) { return new Double(((Double) var).doubleValue()); } else if (type == String.class) { return new String(var.toString()); } } return null; }
From source file:Main.java
/** * This method converts a given number into a target class. This method does not change the value (except when * explicitly casting to a more general type, e.g. from double to int), just the internal type representation. While * this is unnecessary while using normal java code, reflection based access to method parameters is a bit more * difficult. As far as possible, this method will prevent the ArgumentMismatch error when passing numbers as * parameters./*w w w . j av a2s. com*/ * <p/> * If the value can not be converted to the given target class, it will be returned unchanged. * * @param targetClass Class to which the number should be converted, if possible. * @param value Number value to convert. * @return 'value' converted to an instance of 'targetClass'. */ public static Object convertNumber(final Class targetClass, final Number value) { if (targetClass.equals(Double.class) || targetClass.equals(Double.TYPE)) return value.doubleValue(); if (targetClass.equals(Integer.class) || targetClass.equals(Integer.TYPE)) return value.intValue(); if (targetClass.equals(Long.class) || targetClass.equals(Long.TYPE)) return value.longValue(); if (targetClass.equals(Short.class) || targetClass.equals(Short.TYPE)) return value.shortValue(); if (targetClass.equals(Byte.class) || targetClass.equals(Byte.TYPE)) return value.byteValue(); if (targetClass.equals(Character.class) || targetClass.equals(Character.TYPE)) return value.intValue(); if (targetClass.equals(Float.class) || targetClass.equals(Float.TYPE)) return value.floatValue(); return value; }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n// ww w .j a va 2s . c om * @return */ public static int intValueExact(Number n) { if (n instanceof Integer || n instanceof Short || n instanceof Byte) return n.intValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) return (int) l; } throw new NumberFormatException(); }
From source file:lanchon.dexpatcher.Parser.java
public static Configuration parseCommandLine(String[] args) throws ParseException { Configuration config = new Configuration(); Options options = getOptions();/*from w w w . j a v a2 s.c om*/ CommandLine cl = new PosixParser().parse(options, args); if (cl.hasOption("help")) { printUsage(); return null; } if (cl.hasOption("version")) { System.out.println(Main.getVersion()); return null; } @SuppressWarnings("unchecked") List<String> files = cl.getArgList(); if (files.isEmpty()) throw new ParseException("Missing argument: <source-dex-apk-or-dir>"); config.sourceFile = files.remove(0); config.patchFiles = files; config.patchedFile = cl.getOptionValue("output"); Number apiLevel = (Number) cl.getParsedOptionValue("api-level"); if (apiLevel != null) config.apiLevel = apiLevel.intValue(); config.multiDex = cl.hasOption("multi-dex"); if (cl.hasOption("multi-dex-threaded")) { config.multiDex = true; config.multiDexJobs = 0; } Number multiDexJobs = (Number) cl.getParsedOptionValue("multi-dex-jobs"); if (multiDexJobs != null) { config.multiDex = true; config.multiDexJobs = multiDexJobs.intValue(); } Number maxDexPoolSize = (Number) cl.getParsedOptionValue("max-dex-pool-size"); if (maxDexPoolSize != null) config.maxDexPoolSize = maxDexPoolSize.intValue(); config.annotationPackage = cl.getOptionValue("annotations", Context.DEFAULT_ANNOTATION_PACKAGE); config.dexTagSupported = cl.hasOption("compat-dextag"); config.logLevel = WARN; if (cl.hasOption("quiet")) config.logLevel = ERROR; if (cl.hasOption("verbose")) config.logLevel = INFO; if (cl.hasOption("debug")) config.logLevel = DEBUG; if (cl.hasOption("path")) config.sourceCodeRoot = ""; config.sourceCodeRoot = cl.getOptionValue("path-root", config.sourceCodeRoot); config.timingStats = cl.hasOption("stats"); config.dryRun = cl.hasOption("dry-run"); return config; }