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:net.dmulloy2.ultimatearena.types.ArenaZone.java
/** * {@inheritDoc}/*from w ww . j ava 2 s. c o m*/ */ @Override public Map<String, Object> serialize() { Map<String, Object> data = new LinkedHashMap<>(); for (java.lang.reflect.Field field : ArenaZone.class.getDeclaredFields()) { if (Modifier.isTransient(field.getModifiers())) continue; try { 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) { } } data.put("version", CURRENT_VERSION); return data; }
From source file:com.liferay.tool.datamanipulator.handler.BaseHandler.java
private Object[] _getArgs(String[] argNames, Class<?>[] argClazzs, RequestContext requestContext, Map<String, Object> entrySpecifiedArgs) throws Exception { long companyId = requestContext.getCompanyId(); long groupId = requestContext.getGroupId(); long userId = requestContext.getUserId(); Date now = new Date(); ServiceContext serviceContext = HandlerUtil.getServiceContext(groupId, userId); Map<String, Calendar> dateMap = new HashMap<String, Calendar>(entryDateFields.size()); for (String entryDateField : entryDateFields) { String dateVarName = entryDateField + "Date"; String dateKeyName = entryDateField + "-date"; Date serviceContextDate = (Date) BeanUtil.getPropertySilently(serviceContext, dateVarName); Calendar dateVarValue;//from w ww .j a va 2s .c o m if (requestContext.contains(dateKeyName + "-from") && requestContext.contains(dateKeyName + "-to")) { dateVarValue = requestContext.getBetweenCalendar(dateKeyName); } else if (Validator.isNotNull(serviceContextDate)) { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(serviceContextDate); } else { dateVarValue = Calendar.getInstance(); dateVarValue.setTime(now); } dateMap.put(dateVarName, dateVarValue); } StringBuilder sb = new StringBuilder(); sb.append(_entryName); sb.append(requestContext.getString("entryCount")); sb.append(" ${fieldName} "); if (requestContext.contains("editCount")) { sb.append("Edited "); sb.append(requestContext.getString("editCount")); sb.append(" times "); } sb.append(requestContext.getRandomString()); String entryTemplate = sb.toString(); User user = UserLocalServiceUtil.fetchUser(userId); List<Object> argValues = new ArrayList<Object>(argNames.length); for (int i = 0; i < argNames.length; i++) { String argName = argNames[i]; Class<?> argClazz = argClazzs[i]; if (entrySpecifiedArgs.containsKey(argName)) { argValues.add(entrySpecifiedArgs.get(argName)); } else if (argName.equals(Field.COMPANY_ID)) { argValues.add(companyId); } else if (argName.matches(".*Date.*")) { int x = argName.indexOf("Date") + 4; String dateKey = argName.substring(0, x); Calendar calendar = dateMap.get(dateKey); String calendarFieldName = argName.substring(x).toUpperCase(); if (calendarFieldName.equals("DAY")) { calendarFieldName = "DATE"; } int calendarFieldValue = (Integer) GetterUtil.getFieldValue(Calendar.class.getName(), calendarFieldName); argValues.add(calendar.get(calendarFieldValue)); } else if (entryStringFields.contains(argName)) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(content); } else if (entryMapFields.contains(argName)) { argName = argName.substring(0, (argName.length() - 3)); Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", argName); String content = StringUtil.getStringFieldValue(argName, context, entryTemplate); argValues.add(StringUtil.getLocalizationMap(content)); } else if (argName.equals("friendlyURL")) { Map<String, String> context = new HashMap<String, String>(1); context.put("fieldName", "name"); String friendlyURL = StringUtil.getStringFieldValue(argName, context, entryTemplate); friendlyURL = StringPool.SLASH + FriendlyURLNormalizerUtil.normalize(friendlyURL); argValues.add(friendlyURL); } else if (argName.equals(Field.GROUP_ID)) { argValues.add(groupId); } else if (argName.equals(getParentClassPKName())) { argValues.add(Long.valueOf(_getParentClassPK(requestContext))); } else if (argName.equals("locale")) { argValues.add(LocaleUtil.getDefault()); } else if (argName.equals("serviceContext")) { argValues.add(serviceContext); } else if (argName.equals(Field.USER_ID)) { argValues.add(userId); } else if (argName.equals(Field.USER_NAME)) { argValues.add(user.getFullName()); } else if (requestContext.contains(argName)) { argValues.add(requestContext.get(argName)); } else { Object argValue = null; try { Object object = argClazz.newInstance(); if (object instanceof String) { argValue = StringPool.BLANK; } } catch (InstantiationException e) { Type type = argClazz; if (type.equals(Boolean.TYPE)) { argValue = false; } else if (type.equals(Integer.TYPE)) { argValue = (int) 0; } else if (type.equals(List.class)) { argValue = new ArrayList<Object>(0); } else if (type.equals(Long.TYPE)) { argValue = (long) 0; } } argValues.add(argValue); } } return (Object[]) argValues.toArray(new Object[argValues.size()]); }
From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java
/** * Convert to a primitive type if available. * //from ww w .j a v a 2 s.com * @param type The type to convert. * @return A primitive type, if available, that corresponds to the type. */ public static Class<?> getPrimitiveType(Class<?> type) { if (Byte.class.equals(type)) { return Byte.TYPE; } else if (Short.class.equals(type)) { return Short.TYPE; } else if (Integer.class.equals(type)) { return Integer.TYPE; } else if (Long.class.equals(type)) { return Long.TYPE; } else if (Boolean.class.equals(type)) { return Boolean.TYPE; } else if (Float.class.equals(type)) { return Float.TYPE; } else if (Double.class.equals(type)) { return Double.TYPE; } return type; }
From source file:org.xmlsh.util.JavaUtils.java
public static <T> T convert(Object value, Class<T> targetClass) throws InvalidArgumentException { assert (targetClass != null); assert (value != null); if (targetClass.isInstance(value)) return targetClass.cast(value); Class<?> sourceClass = value.getClass(); // Asking for an XdmValue class if (XdmValue.class.isAssignableFrom(targetClass)) { if (value instanceof XdmNode) return (T) (XdmValue) value; if (targetClass.isAssignableFrom(XdmAtomicValue.class)) { // Try some smart conversions of all types XdmAtomicValue knows if (value instanceof Boolean) return (T) new XdmAtomicValue(((Boolean) value).booleanValue()); else if (value instanceof Double) return (T) new XdmAtomicValue(((Double) value).doubleValue()); else if (value instanceof Float) return (T) new XdmAtomicValue(((Float) value).floatValue()); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof BigDecimal) return (T) new XdmAtomicValue((BigDecimal) value); else if (value instanceof URI) return (T) new XdmAtomicValue((URI) value); else if (value instanceof Long) return (T) new XdmAtomicValue((Long) value); else if (value instanceof QName) return (T) new XdmAtomicValue((QName) value); // Still wanting an xdm value }/*from w w w . ja v a 2 s. co m*/ if (isAtomic(value)) return (T) new XdmAtomicValue(value.toString()); } boolean bAtomic = isAtomic(value); Class<?> vclass = value.getClass(); if (targetClass.isPrimitive() && bAtomic) { /* Try to match non-primative types */ if (targetClass == Integer.TYPE) { if (vclass == Long.class) value = Integer.valueOf(((Long) value).intValue()); else if (vclass == Short.class) value = Integer.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Integer.valueOf(((Byte) value).intValue()); else value = Integer.valueOf(value.toString()); } else if (targetClass == Long.TYPE) { if (vclass == Integer.class) value = Long.valueOf(((Integer) value).intValue()); else if (vclass == Short.class) value = Long.valueOf(((Short) value).intValue()); else if (vclass == Byte.class) value = Long.valueOf(((Byte) value).intValue()); value = Long.valueOf(value.toString()); } else if (targetClass == Short.TYPE) { if (vclass == Integer.class) value = Short.valueOf((short) ((Integer) value).intValue()); else if (vclass == Long.class) value = Short.valueOf((short) ((Long) value).intValue()); else if (vclass == Byte.class) value = Short.valueOf((short) ((Byte) value).intValue()); value = Short.valueOf(value.toString()); } else if (targetClass == Byte.TYPE) { if (vclass == Integer.class) value = Byte.valueOf((byte) ((Integer) value).intValue()); else if (vclass == Long.class) value = Byte.valueOf((byte) ((Long) value).intValue()); else if (vclass == Short.class) value = Byte.valueOf((byte) ((Short) value).intValue()); value = Byte.valueOf(value.toString()); } else ; // skip return (T) value; } // Bean constructor Constructor<?> cnst = getBeanConstructor(targetClass, sourceClass); if (cnst != null) try { return (T) cnst.newInstance(convert(value, cnst.getParameterTypes()[0])); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { mLogger.debug("Exception converting argument for constructor", e); } // Cast through string String svalue = value.toString(); if (targetClass == Integer.class) value = Integer.valueOf(svalue); else if (targetClass == Long.class) value = Long.valueOf(svalue); else if (targetClass == Short.class) value = Short.valueOf(svalue); else if (targetClass == Float.class) value = Float.valueOf(svalue); else if (targetClass == Double.class) value = Double.valueOf(svalue); else value = null; return (T) value; }
From source file:com.flexive.faces.renderer.FxSelectRenderer.java
/** * Convert select many values to given array class * * @param context faces context//ww w .j a va2 s .c om * @param uiSelectMany select many component * @param arrayClass the array class * @param newValues new values to convert * @return converted values * @throws ConverterException on errors */ protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result; Converter converter; int len = (null != newValues ? newValues.length : 0); Class elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) return newValues; try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) return result; // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = FxJsfComponentUtils.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) return newValues; StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) valueStr.append(newValues[i]); else valueStr.append(' ').append(newValues[i]); } throw new ConverterException("Could not get a converter for " + String.valueOf(valueStr)); } } if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } return result; }
From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java
/** * Transform an primitive array to an object array. * /*from w w w . j a v a2s .c o m*/ * @param arr * the array. * @return an array. */ private static Object toArray(final Object arr) { if (arr == null) { return arr; } final Class cls = arr.getClass(); if (!cls.isArray()) { return arr; } Class compType = cls.getComponentType(); int dim = 1; while (!compType.isPrimitive()) { if (!compType.isArray()) { return arr; } else { dim++; compType = compType.getComponentType(); } } final int[] length = new int[dim]; length[0] = Array.getLength(arr); Object[] newarr = null; try { if (compType.equals(Integer.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Integer"), length); } else if (compType.equals(Double.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Double"), length); } else if (compType.equals(Long.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Long"), length); } else if (compType.equals(Float.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Float"), length); } else if (compType.equals(Short.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Short"), length); } else if (compType.equals(Byte.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Byte"), length); } else if (compType.equals(Character.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Character"), length); } else if (compType.equals(Boolean.TYPE)) { newarr = (Object[]) Array.newInstance(Class.forName("java.lang.Boolean"), length); } } catch (ClassNotFoundException ex) { System.out.println(ex); } for (int i = 0; i < length[0]; i++) { if (dim != 1) { newarr[i] = toArray(Array.get(arr, i)); } else { newarr[i] = Array.get(arr, i); } } return newarr; }
From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassFromType(final org.objectweb.asm.Type type) { if (type.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) { return Boolean.TYPE; } else if (type.equals(org.objectweb.asm.Type.BYTE_TYPE)) { return Byte.TYPE; } else if (type.equals(org.objectweb.asm.Type.CHAR_TYPE)) { return Character.TYPE; } else if (type.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) { return Double.TYPE; } else if (type.equals(org.objectweb.asm.Type.FLOAT_TYPE)) { return Float.TYPE; } else if (type.equals(org.objectweb.asm.Type.INT_TYPE)) { return Integer.TYPE; } else if (type.equals(org.objectweb.asm.Type.LONG_TYPE)) { return Long.TYPE; } else if (type.equals(org.objectweb.asm.Type.SHORT_TYPE)) { return Short.TYPE; } else if (type.getSort() == org.objectweb.asm.Type.ARRAY) { final org.objectweb.asm.Type elementType = type.getElementType(); int[] dimensions = new int[type.getDimensions()]; if (elementType.equals(org.objectweb.asm.Type.BOOLEAN_TYPE)) { return Array.newInstance(boolean.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.BYTE_TYPE)) { return Array.newInstance(byte.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.CHAR_TYPE)) { return Array.newInstance(char.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.DOUBLE_TYPE)) { return Array.newInstance(double.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.FLOAT_TYPE)) { return Array.newInstance(float.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.INT_TYPE)) { return Array.newInstance(int.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.LONG_TYPE)) { return Array.newInstance(long.class, dimensions).getClass(); } else if (elementType.equals(org.objectweb.asm.Type.SHORT_TYPE)) { return Array.newInstance(short.class, dimensions).getClass(); }//from w ww . j a v a 2 s . c o m } // try // { return getClassForName(type.getClassName()); // return Class.forName(type.getClassName(), true, StaticTestCluster.classLoader); // } // catch (final ClassNotFoundException e) // { // throw new RuntimeException(e); // } }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testUnaryNumericPromotion() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Promotion.class); List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'unaryNumericPromotion']]//Expression[UnaryExpression]"), ASTExpression.class); int index = 0; assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Integer.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Float.TYPE, expressions.get(index++).getType()); assertEquals(Double.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:org.pentaho.reporting.engine.classic.core.util.beans.BeanUtility.java
public static boolean isSameType(final Class declared, final Class object) { if (declared.equals(object)) { return true; }/*from w ww . j a va 2s .c om*/ if (Float.TYPE.equals(declared) && Float.class.equals(object)) { return true; } if (Double.TYPE.equals(declared) && Double.class.equals(object)) { return true; } if (Byte.TYPE.equals(declared) && Byte.class.equals(object)) { return true; } if (Character.TYPE.equals(declared) && Character.class.equals(object)) { return true; } if (Short.TYPE.equals(declared) && Short.class.equals(object)) { return true; } if (Integer.TYPE.equals(declared) && Integer.class.equals(object)) { return true; } if (Long.TYPE.equals(declared) && Long.class.equals(object)) { return true; } return false; }
From source file:org.crank.javax.faces.component.MenuRenderer.java
protected Object convertSelectManyValues(FacesContext context, UISelectMany uiSelectMany, Class<?> arrayClass, String[] newValues) throws ConverterException { Object result = null;//from www. j a va 2s.c o m Converter converter = null; int len = (null != newValues ? newValues.length : 0); Class<?> elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } StringBuffer valueStr = new StringBuffer(); for (int i = 0; i < len; i++) { if (i == 0) { valueStr.append(newValues[i]); } else { valueStr.append(' ').append(newValues[i]); } } Object[] params = { valueStr.toString(), "null Converter" }; throw new ConverterException( MessageUtils.getExceptionMessage(MessageUtils.CONVERSION_ERROR_MESSAGE_ID, params)); } } assert (null != result); if (elementType.isPrimitive()) { for (int i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i]))); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i]))); } } } else { for (int i = 0; i < len; i++) { if (logger.isLoggable(Level.FINE)) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); logger.fine("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }