List of usage examples for java.lang Short TYPE
Class TYPE
To view the source code for java.lang Short TYPE.
Click Source Link
From source file:com.github.gekoh.yagen.util.FieldInfo.java
private static List<FieldInfo> convertFields(List<FieldInfo> fields, Class baseEntity) { for (Field field : baseEntity.getDeclaredFields()) { FieldInfo fi;/*from w w w.ja v a 2 s . c o m*/ Class type = field.getType(); String name = field.getName(); Column column = field.getAnnotation(Column.class); if (field.isAnnotationPresent(Embedded.class)) { if (field.isAnnotationPresent(AttributeOverride.class)) { fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverride.class)); } else { fi = new FieldInfo(type, name, field.getAnnotation(AttributeOverrides.class)); } } else if (field.isAnnotationPresent(Enumerated.class)) { fi = new FieldInfo(type, name, true, column); } else if (column != null && !field.isAnnotationPresent(CollectionTable.class)) { if (type.isPrimitive()) { if (type.equals(Boolean.TYPE)) { type = Boolean.class; } else if (type.equals(Long.TYPE)) { type = Long.class; } else if (type.equals(Integer.TYPE)) { type = Integer.class; } else if (type.equals(Short.TYPE)) { type = Short.class; } else if (type.equals(Byte.TYPE)) { type = Byte.class; } else if (type.equals(Double.TYPE)) { type = Double.class; } else if (type.equals(Float.TYPE)) { type = Float.class; } else if (type.equals(Character.TYPE)) { type = Character.class; } } fi = new FieldInfo(type, name, false, column); } else if ((field.isAnnotationPresent(ManyToOne.class) && !field.isAnnotationPresent(JoinTable.class)) || (field.isAnnotationPresent(OneToOne.class) && StringUtils.isEmpty(field.getAnnotation(OneToOne.class).mappedBy()))) { String columnName = field.isAnnotationPresent(JoinColumn.class) ? field.getAnnotation(JoinColumn.class).name() : field.getName(); fi = getIdFieldInfo(type, name, columnName); } else if (!field.isAnnotationPresent(Transient.class) && (Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)) && (field.isAnnotationPresent(JoinColumn.class) || field.isAnnotationPresent(JoinTable.class) || field.isAnnotationPresent(CollectionTable.class))) { fi = new FieldInfo(type, name); } else { continue; } if (field.isAnnotationPresent(Type.class)) { fi.addAnnotation(field.getAnnotation(Type.class)); } fi.setField(field); fields.add(fi); } return fields; }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!//from w w w .j av a2s .co m * * @param clazz DOCUMENT ME! * * @return DOCUMENT ME! */ private boolean isShort(Class clazz) { return Short.class.isAssignableFrom(clazz) || (clazz == Short.TYPE); }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Returns true if the given class is Byte, Short, Integer, Long, * Float, Double, BigInteger, or BigDecimal *///w w w . j av a2 s . co m static boolean isNumberClass(Class pClass) { return pClass == Byte.class || pClass == Byte.TYPE || pClass == Short.class || pClass == Short.TYPE || pClass == Integer.class || pClass == Integer.TYPE || pClass == Long.class || pClass == Long.TYPE || pClass == Float.class || pClass == Float.TYPE || pClass == Double.class || pClass == Double.TYPE || pClass == BigInteger.class || pClass == BigDecimal.class; }
From source file:com.nonninz.robomodel.RoboModel.java
void saveField(Field field, TypedContentValues cv) { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); field.setAccessible(true);//from w w w. j a v a 2 s. co m try { if (type == String.class) { cv.put(field.getName(), (String) field.get(this)); } else if (type == Boolean.TYPE) { cv.put(field.getName(), field.getBoolean(this)); } else if (type == Byte.TYPE) { cv.put(field.getName(), field.getByte(this)); } else if (type == Double.TYPE) { cv.put(field.getName(), field.getDouble(this)); } else if (type == Float.TYPE) { cv.put(field.getName(), field.getFloat(this)); } else if (type == Integer.TYPE) { cv.put(field.getName(), field.getInt(this)); } else if (type == Long.TYPE) { cv.put(field.getName(), field.getLong(this)); } else if (type == Short.TYPE) { cv.put(field.getName(), field.getShort(this)); } else if (type.isEnum()) { final Object value = field.get(this); if (value != null) { final Method method = type.getMethod("name"); final String str = (String) method.invoke(value); cv.put(field.getName(), str); } } else { // Try to JSONify it (db column must be of type text) final String json = mMapper.writeValueAsString(field.get(this)); cv.put(field.getName(), json); } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final JsonProcessingException e) { Ln.w(e, "Error while dumping %s of type %s to Json", field.getName(), type); final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java
/** * Returns a new value that is not equal to oldVal. If oldVal is immutable, the * returned object will be a new instance compatible with oldVal. If oldVal is * mutable, it will be modified in some way so it is no longer equal to its original * value. {@link #getNewDifferentValue(MatchMakerObject, PropertyDescriptor, Object)} * is a similar method that does not take mutability into account and always returns * a new value./*from w w w . ja v a 2s. co m*/ * * @param mmo The object to which the property belongs. You might need this * if you have a special case for certain types of objects. * @param property The property that should be modified. It belongs to mmo. * @param oldVal The existing value of the property to modify. The returned value * will not equal this one at the time this method was first called, although it may * be the same instance as this one, but modified in some way. */ private Object modifyObject(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal) throws IOException { if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { return ((Integer) oldVal) + 1; } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) { return ((Short) oldVal) + 1; } else if (property.getPropertyType() == String.class) { if (oldVal == null) { return "new"; } else { return "new " + oldVal; } } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) { return new Boolean(!((Boolean) oldVal).booleanValue()); } else if (property.getPropertyType() == Long.class) { return new Long(((Long) oldVal).longValue() + 1L); } else if (property.getPropertyType() == BigDecimal.class) { return new BigDecimal(((BigDecimal) oldVal).longValue() + 1L); } else if (property.getPropertyType() == MungeSettings.class) { Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount(); processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1); ((MatchMakerSettings) oldVal).setProcessCount(processCount); return oldVal; } else if (property.getPropertyType() == MergeSettings.class) { Integer processCount = ((MatchMakerSettings) oldVal).getProcessCount(); processCount = new Integer((processCount == null) ? new Integer(0) : processCount + 1); ((MatchMakerSettings) oldVal).setProcessCount(processCount); return oldVal; } else if (property.getPropertyType() == SQLTable.class) { ((SQLTable) oldVal).setRemarks("Testing Remarks"); return oldVal; } else if (property.getPropertyType() == ViewSpec.class) { ((ViewSpec) oldVal).setName("Testing New Name"); return oldVal; } else if (property.getPropertyType() == File.class) { oldVal = File.createTempFile("mmTest2", ".tmp"); ((File) oldVal).deleteOnExit(); return oldVal; } else if (property.getPropertyType() == ProjectMode.class) { if (oldVal == ProjectMode.BUILD_XREF) { return ProjectMode.FIND_DUPES; } else { return ProjectMode.BUILD_XREF; } } else if (property.getPropertyType() == MergeActionType.class) { if (oldVal == MergeActionType.AUGMENT) { return MergeActionType.SUM; } else { return MergeActionType.AUGMENT; } } else if (property.getPropertyType() == MatchMakerObject.class) { ((MatchMakerObject) oldVal).setName("Testing New Name"); return oldVal; } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) { ((MatchMakerObject) oldVal).setName("Testing New Name2"); return oldVal; } else if (property.getPropertyType() == SQLColumn.class) { ((SQLColumn) oldVal).setRemarks("Testing Remarks"); return oldVal; } else if (property.getPropertyType() == Date.class) { ((Date) oldVal).setTime(((Date) oldVal).getTime() + 10000); return oldVal; } else if (property.getPropertyType() == List.class) { if (property.getName().equals("children")) { if (mmo instanceof TableMergeRules) { ((List) oldVal).add(new ColumnMergeRules()); } else { ((List) oldVal).add(new StubMatchMakerObject()); } } else { ((List) oldVal).add("Test"); } return oldVal; } else if (property.getPropertyType() == SQLIndex.class) { ((SQLIndex) oldVal).setName("modified index"); return oldVal; } else if (property.getPropertyType() == Color.class) { if (oldVal == null) { return new Color(0xFAC157); } else { Color oldColor = (Color) oldVal; return new Color((oldColor.getRGB() + 0xF00) % 0x1000000); } } else if (property.getPropertyType() == ChildMergeActionType.class) { if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) { return ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT; } else { return ChildMergeActionType.DELETE_ALL_DUP_CHILD; } } else if (property.getPropertyType() == TableMergeRules.class) { if (oldVal == null) { return mmo; } else { return null; } } else if (property.getPropertyType() == PoolFilterSetting.class) { if (oldVal != PoolFilterSetting.EVERYTHING) { return PoolFilterSetting.EVERYTHING; } else { return PoolFilterSetting.INVALID_ONLY; } } else if (property.getPropertyType() == AutoValidateSetting.class) { if (oldVal != AutoValidateSetting.NOTHING) { return AutoValidateSetting.NOTHING; } else { return AutoValidateSetting.SERP_CORRECTABLE; } } else if (property.getPropertyType() == TableIndex.class) { CachableTable cachableTable = new CachableTable("newValue"); TableIndex tableIndex = new TableIndex(cachableTable, "newValueIndex"); if (tableIndex.getTableIndex() == null) { tableIndex.setTableIndex(new SQLIndex()); } else { tableIndex.setTableIndex(null); } return tableIndex; } else if (property.getPropertyType() == CachableTable.class) { CachableTable cachableTable = new CachableTable("newValue"); return cachableTable; } else { throw new RuntimeException("This test case lacks the ability to modify values for " + property.getName() + " (type " + property.getPropertyType().getName() + ")"); } }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Creates a java array from a JSONArray.<br> *///from w w w.ja va 2 s.c o m public static Object toArray(JSONArray jsonArray, JsonConfig jsonConfig) { Class objectClass = jsonConfig.getRootClass(); Map classMap = jsonConfig.getClassMap(); if (jsonArray.size() == 0) { return Array.newInstance(objectClass == null ? Object.class : objectClass, 0); } int[] dimensions = JSONArray.getDimensions(jsonArray); Object array = Array.newInstance(objectClass == null ? Object.class : objectClass, dimensions); int size = jsonArray.size(); for (int i = 0; i < size; i++) { Object value = jsonArray.get(i); if (JSONUtils.isNull(value)) { Array.set(array, i, null); } else { Class type = value.getClass(); if (JSONArray.class.isAssignableFrom(type)) { Array.set(array, i, toArray((JSONArray) value, objectClass, classMap)); } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type) || Character.class.isAssignableFrom(type) || JSONFunction.class.isAssignableFrom(type)) { if (objectClass != null && !objectClass.isAssignableFrom(type)) { value = JSONUtils.getMorpherRegistry().morph(objectClass, value); } Array.set(array, i, value); } else if (JSONUtils.isNumber(type)) { if (objectClass != null && (Byte.class.isAssignableFrom(objectClass) || Byte.TYPE.isAssignableFrom(objectClass))) { Array.set(array, i, Byte.valueOf(String.valueOf(value))); } else if (objectClass != null && (Short.class.isAssignableFrom(objectClass) || Short.TYPE.isAssignableFrom(objectClass))) { Array.set(array, i, Short.valueOf(String.valueOf(value))); } else { Array.set(array, i, value); } } else { if (objectClass != null) { JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(objectClass); jsc.setClassMap(classMap); Array.set(array, i, JSONObject.toBean((JSONObject) value, jsc)); } else { Array.set(array, i, JSONObject.toBean((JSONObject) value)); } } } } return array; }
From source file:org.liveSense.api.beanprocessors.DbStandardBeanProcessor.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int.//from ww w . j a va 2 s . co m * * @param value The value to be passed into the setter method. * @param type The setter's parameter type. * @return boolean True if the value is compatible. */ private boolean isCompatibleType(Object value, Class<?> type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else { return false; } }
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 av a2 s . c om*/ * @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:net.sf.jrf.domain.PersistentObjectDynaProperty.java
/** Gets default value. * @return default value.//from w w w . java 2 s . c o 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; }