List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:tiemens.util.instancer.antlr.InstancerCode.java
@SuppressWarnings("unused") private Constructor<?> getConstructorByFind(Class<?> dclz, Class<?>[] parameterTypes) throws NoSuchMethodException { Constructor<?> ret = null; try {/*from w w w . j a v a2 s . co m*/ ret = dclz.getConstructor(parameterTypes); } catch (SecurityException e) { throw e; } catch (NoSuchMethodException e) { // // try to correct java.lang.Long into java.lang.Type.long // i.e. Long to long // for (int i = 0, n = parameterTypes.length; i < n; i++) { Class<?> c = parameterTypes[i]; if (c.equals(Long.class)) { c = java.lang.Long.TYPE; } else if (c.equals(Integer.class)) { c = java.lang.Integer.TYPE; } else if (c.equals(Double.class)) { c = java.lang.Double.TYPE; } else if (c.equals(java.lang.Float.class)) { c = java.lang.Float.TYPE; } parameterTypes[i] = c; } ret = dclz.getConstructor(parameterTypes); } finally { } return ret; }
From source file:net.dmulloy2.ultimatearena.types.ArenaConfig.java
@Override public Map<String, Object> serialize() { Map<String, Object> data = new LinkedHashMap<>(); for (Field field : ArenaConfig.class.getDeclaredFields()) { try {/* ww w .ja va2s.co m*/ if (Modifier.isTransient(field.getModifiers())) continue; boolean accessible = field.isAccessible(); field.setAccessible(true); if (field.getType().equals(Integer.TYPE)) { if (field.getInt(this) != 0) data.put(field.getName(), field.getInt(this)); } else if (field.getType().equals(Long.TYPE)) { if (field.getLong(this) != 0) data.put(field.getName(), field.getLong(this)); } else if (field.getType().equals(Boolean.TYPE)) { if (field.getBoolean(this)) data.put(field.getName(), field.getBoolean(this)); } else if (field.getType().isAssignableFrom(Collection.class)) { if (!((Collection<?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(String.class)) { if ((String) field.get(this) != null) data.put(field.getName(), field.get(this)); } else if (field.getType().isAssignableFrom(Map.class)) { if (!((Map<?, ?>) field.get(this)).isEmpty()) data.put(field.getName(), field.get(this)); } else { if (field.get(this) != null) data.put(field.getName(), field.get(this)); } field.setAccessible(accessible); } catch (Throwable ex) { } } serializeCustomOptions(data); return data; }
From source file:javadz.beanutils.ConvertUtilsBean.java
/** * Sets the default value for Long conversions. * @param newDefaultLong The default Long value * @deprecated Register replacement converters for Long.TYPE and * Long.class instead//from w ww . j ava 2s . c om */ public void setDefaultLong(long newDefaultLong) { defaultLong = new Long(newDefaultLong); register(new LongConverter(defaultLong), Long.TYPE); register(new LongConverter(defaultLong), Long.class); }
From source file:com.qmetry.qaf.automation.data.BaseDataBean.java
/** * This will fill random data except those properties which has skip=true in * {@link Randomizer} annotation. Use {@link Randomizer} annotation to * specify data value to be generated for specific property. * //from w w w .j a v a2 s . com * @see Randomizer */ public void fillRandomData() { Field[] fields = getFields(); for (Field field : fields) { logger.debug("NAME :: " + field.getName()); if (!(Modifier.isFinal(field.getModifiers()))) { RandomizerTypes type = RandomizerTypes.MIXED; int len = 10; long min = 0, max = 0; String prefix = "", suffix = ""; String format = ""; String[] list = {}; Randomizer randomizer = field.getAnnotation(Randomizer.class); if (randomizer != null) { if (randomizer.skip()) { continue; } type = field.getType() == Date.class ? RandomizerTypes.DIGITS_ONLY : randomizer.type(); len = randomizer.length(); prefix = randomizer.prefix(); suffix = randomizer.suffix(); min = randomizer.minval(); max = min > randomizer.maxval() ? min : randomizer.maxval(); format = randomizer.format(); list = randomizer.dataset(); } else { // @Since 2.1.2 randomizer annotation is must for random // value // generation continue; } String str = ""; if ((list == null) || (list.length == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = getRandomValue(list); } try { // deal with IllegalAccessException field.setAccessible(true); Method setter = null; try { setter = this.getClass().getMethod("set" + StringUtil.getTitleCase(field.getName()), String.class); } catch (Exception e) { } if ((field.getType() == String.class) || (null != setter)) { if ((list == null) || (list.length == 0)) { if ((min == max) && (min == 0)) { str = StringUtil.isBlank(format) ? RandomStringUtils.random(len, !type.equals(RandomizerTypes.DIGITS_ONLY), !type.equals(RandomizerTypes.LETTERS_ONLY)) : StringUtil.getRandomString(format); } else { str = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } } String rStr = prefix + str + suffix; if (null != setter) { setter.setAccessible(true); setter.invoke(this, rStr); } else { field.set(this, rStr); } } else { String rStr = ""; if ((min == max) && (min == 0)) { rStr = RandomStringUtils.random(len, false, true); } else { rStr = String.valueOf((int) (Math.random() * ((max - min) + 1)) + min); } if (field.getType() == Integer.TYPE) { field.setInt(this, Integer.parseInt(rStr)); } else if (field.getType() == Float.TYPE) { field.setFloat(this, Float.parseFloat(rStr)); } else if (field.getType() == Double.TYPE) { field.setDouble(this, Double.parseDouble(rStr)); } else if (field.getType() == Long.TYPE) { field.setLong(this, Long.parseLong(rStr)); } else if (field.getType() == Short.TYPE) { field.setShort(this, Short.parseShort(rStr)); } else if (field.getType() == Date.class) { logger.info("filling date " + rStr); int days = Integer.parseInt(rStr); field.set(this, DateUtil.getDate(days)); } else if (field.getType() == Boolean.TYPE) { field.setBoolean(this, RandomUtils.nextBoolean()); } } } catch (IllegalArgumentException e) { logger.error("Unable to fill random data in field " + field.getName(), e); } catch (IllegalAccessException e) { logger.error("Unable to Access " + field.getName(), e); } catch (InvocationTargetException e) { logger.error("Unable to Access setter for " + field.getName(), e); } } } }
From source file:org.enerj.apache.commons.beanutils.locale.LocaleConvertUtilsBean.java
/** * Create all {@link LocaleConverter} types for specified locale. * * @param locale The Locale//from ww w .j av a 2 s. c o m * @return The FastHashMap instance contains the all {@link LocaleConverter} types * for the specified locale. */ protected FastHashMap create(Locale locale) { FastHashMap converter = new FastHashMap(); converter.setFast(false); converter.put(BigDecimal.class, new BigDecimalLocaleConverter(locale, applyLocalized)); converter.put(BigInteger.class, new BigIntegerLocaleConverter(locale, applyLocalized)); converter.put(Byte.class, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Byte.TYPE, new ByteLocaleConverter(locale, applyLocalized)); converter.put(Double.class, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Double.TYPE, new DoubleLocaleConverter(locale, applyLocalized)); converter.put(Float.class, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Float.TYPE, new FloatLocaleConverter(locale, applyLocalized)); converter.put(Integer.class, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Integer.TYPE, new IntegerLocaleConverter(locale, applyLocalized)); converter.put(Long.class, new LongLocaleConverter(locale, applyLocalized)); converter.put(Long.TYPE, new LongLocaleConverter(locale, applyLocalized)); converter.put(Short.class, new ShortLocaleConverter(locale, applyLocalized)); converter.put(Short.TYPE, new ShortLocaleConverter(locale, applyLocalized)); converter.put(String.class, new StringLocaleConverter(locale, applyLocalized)); // conversion format patterns of java.sql.* types should correspond to default // behaviour of toString and valueOf methods of these classes converter.put(java.sql.Date.class, new SqlDateLocaleConverter(locale, "yyyy-MM-dd")); converter.put(java.sql.Time.class, new SqlTimeLocaleConverter(locale, "HH:mm:ss")); converter.put(java.sql.Timestamp.class, new SqlTimestampLocaleConverter(locale, "yyyy-MM-dd HH:mm:ss.S")); converter.setFast(true); return converter; }
From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Gets default value. * @return default value.// ww w. ja va2 s.co m */ public Object getDefaultValue() { if (defaultValue != null) return this.defaultValue; Class cls = getType(); if (primitiveWrapperClass != null) { if (cls.equals(Boolean.TYPE)) return new Boolean(false); else if (cls.equals(Byte.TYPE)) return new Byte((byte) 0); else if (cls.equals(Character.TYPE)) return new Character((char) 0); else if (cls.equals(Double.TYPE)) return new Double((double) 0); else if (cls.equals(Float.TYPE)) return new Float((float) 0); else if (cls.equals(Integer.TYPE)) return new Integer((int) 0); else if (cls.equals(Long.TYPE)) return new Long((long) 0); else if (cls.equals(Short.TYPE)) return new Short((short) 0); else return null; } else return null; }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * /*from w ww . j av a 2 s. co m*/ * @param json * @param key * @param toField * @return * @throws JSONException */ public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException { final Object o = json.get(key); final Class<?> fieldType = toField.getType(); if (o != JSONObject.NULL) { if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) { return json.getInt(key); } else if (fieldType.equals(String.class)) { return o; } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) { return json.getLong(key); } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) { return json.getBoolean(key); } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) { return (float) json.getDouble(key); } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) { return json.getDouble(key); } else { return o; } } return JSONObject.NULL; }
From source file:com.netflix.governator.lifecycle.LifecycleManager.java
private void assignConfiguration(Object obj, Field field) throws Exception { Configuration configuration = field.getAnnotation(Configuration.class); String configurationName = configuration.value(); ConfigurationKey key = new ConfigurationKey(configurationName, KeyParser.parse(configurationName)); Object value = null;//from w w w .jav a 2s .c o m boolean has = configurationProvider.has(key); if (has) { try { if (String.class.isAssignableFrom(field.getType())) { value = configurationProvider.getString(key); } else if (Boolean.class.isAssignableFrom(field.getType()) || Boolean.TYPE.isAssignableFrom(field.getType())) { value = configurationProvider.getBoolean(key); } else if (Integer.class.isAssignableFrom(field.getType()) || Integer.TYPE.isAssignableFrom(field.getType())) { value = configurationProvider.getInteger(key); } else if (Long.class.isAssignableFrom(field.getType()) || Long.TYPE.isAssignableFrom(field.getType())) { value = configurationProvider.getLong(key); } else if (Double.class.isAssignableFrom(field.getType()) || Double.TYPE.isAssignableFrom(field.getType())) { value = configurationProvider.getDouble(key); } else if (Date.class.isAssignableFrom(field.getType())) { value = parseDate(configurationName, configurationProvider.getString(key), configuration); if (null == value) { field = null; } } else { log.error("Field type not supported: " + field.getType()); field = null; } } catch (IllegalArgumentException e) { if (!Date.class.isAssignableFrom(field.getType())) { ignoreTypeMismtachIfConfigured(configuration, configurationName, e); field = null; } } catch (ConversionException e) { if (!Date.class.isAssignableFrom(field.getType())) { ignoreTypeMismtachIfConfigured(configuration, configurationName, e); field = null; } } } if (field != null) { String defaultValue = String.valueOf(field.get(obj)); String documentationValue; if (has) { field.set(obj, value); documentationValue = String.valueOf(value); } else { documentationValue = ""; } configurationDocumentation.registerConfiguration(field, configurationName, has, defaultValue, documentationValue, configuration.documentation()); } }
From source file:org.ocelotds.dashboard.services.ServiceToolsTest.java
/** * Test of getInstanceOfClass method, of class ServiceTools. * * @throws com.fasterxml.jackson.core.JsonProcessingException *//* w ww . j a va2s.co m*/ @Test public void testGetInstanceOfClass() throws JsonProcessingException { System.out.println("getTemplateOfClass"); ObjectMapper om = new ObjectMapper(); Result r = new Result(); String expResult = om.writeValueAsString(r); Class cls = Boolean.class; Object result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Boolean.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(false); cls = Integer.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Integer.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0); cls = Long.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0L); cls = Long.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0l); cls = Float.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Float.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1f); cls = Double.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Double.TYPE; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(0.1d); cls = Float[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualTo(new Float[] { 0.1f, 0.1f }); cls = Result.class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(r); cls = Result[].class; result = instance.getInstanceOfClass(cls); assertThat(result).isEqualToComparingFieldByField(new Result[] { r, r }); cls = Locale.class; result = instance.getInstanceOfClass(cls); assertThat(result).isInstanceOf(Locale.class); cls = Serializable.class; result = instance.getInstanceOfClass(cls); assertThat(result).isNull(); }