List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:org.evosuite.testcase.statements.FunctionalMockStatement.java
public void fillWithNullRefs() { for (int i = 0; i < parameters.size(); i++) { VariableReference ref = parameters.get(i); if (ref == null) { Class<?> expected = getExpectedParameterType(i); Object value = null;//from ww w. j a v a2 s . co m if (expected.isPrimitive()) { //can't fill a primitive with null if (expected.equals(Integer.TYPE)) { value = 0; } else if (expected.equals(Float.TYPE)) { value = 0f; } else if (expected.equals(Double.TYPE)) { value = 0d; } else if (expected.equals(Long.TYPE)) { value = 0L; } else if (expected.equals(Boolean.TYPE)) { value = false; } else if (expected.equals(Short.TYPE)) { value = Short.valueOf("0"); } else if (expected.equals(Character.TYPE)) { value = 'a'; } } parameters.set(i, new ConstantValue(tc, new GenericClass(expected), value)); } } }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a double to the given primitive number class *//*from ww w. j a va 2s . c o m*/ static Number coerceToPrimitiveNumber(double pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte((byte) pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { return PrimitiveObjects.getShort((short) pValue); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return PrimitiveObjects.getInteger((int) pValue); } else if (pClass == Long.class || pClass == Long.TYPE) { return PrimitiveObjects.getLong((long) pValue); } else if (pClass == Float.class || pClass == Float.TYPE) { return PrimitiveObjects.getFloat((float) pValue); } else if (pClass == Double.class || pClass == Double.TYPE) { return PrimitiveObjects.getDouble(pValue); } else { return PrimitiveObjects.getInteger(0); } }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/* w w w . j a v a 2s .c o m*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] * ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static int[] add(int[] array, int index, int element) { return (int[]) add(array, index, Integer.valueOf(element), Integer.TYPE); }
From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java
private Object getPrimitive(Class<?> type, String s) throws NamingException { Object value = s;/* ww w . ja v a 2s .c o m*/ if (Integer.TYPE.equals(type)) { value = Integer.parseInt(s); } else if (Boolean.TYPE.equals(type)) { value = new Boolean("TRUE".equals(s)); } else if (Long.TYPE.equals(type)) { value = Long.parseLong(s); } else if (Float.TYPE.equals(type)) { value = Float.parseFloat(s); } else if (Double.TYPE.equals(type)) { value = Double.parseDouble(s); } else if (Byte.TYPE.equals(type)) { value = Byte.parseByte(s); } else if (Short.TYPE.equals(type)) { value = Short.parseShort(s); } return value; }
From source file:Main.java
/** * <p>Inserts the specified element at the specified position in the array. * Shifts the element currently at that position (if any) and any subsequent * elements to the right (adds one to their indices).</p> * * <p>This method returns a new array with the same elements of the input * array plus the given element on the specified position. The component * type of the returned array is always the same as that of the input * array.</p>/* w ww.j av a 2s .co m*/ * * <p>If the input array is {@code null}, a new one element array is returned * whose component type is the same as the element.</p> * * <pre> * ArrayUtils.add([1], 0, 2) = [2, 1] * ArrayUtils.add([2, 6], 2, 10) = [2, 6, 10] * ArrayUtils.add([2, 6], 0, -4) = [-4, 2, 6] * ArrayUtils.add([2, 6, 3], 2, 1) = [2, 6, 1, 3] * </pre> * * @param array the array to add the element to, may be {@code null} * @param index the position of the new object * @param element the object to add * @return A new array containing the existing elements and the new element * @throws IndexOutOfBoundsException if the index is out of range * (index < 0 || index > array.length). */ public static int[] add(final int[] array, final int index, final int element) { return (int[]) add(array, index, Integer.valueOf(element), Integer.TYPE); }
From source file:org.ejbca.ui.web.admin.configuration.StartServicesServlet.java
/** Method that checks if we have an integrity protected security audit device configured, and in that case logs the configuration startup * /*w w w.ja v a 2 s . c o m*/ * @param admin an authentication token used to log the configuration management startup (logged as a change as audit is configured during startup from properties file) * @param loggerIds the configured loggers among which we look for the protected device * @return true if there is an integrity protected audit device and is was configured during startup (and audit log of this config was made) */ private boolean checkForProtectedAudit(AuthenticationToken admin, final Set<String> loggerIds) { boolean ret = false; // See if we have IntegrityProtectedDevice configured, due to class loading constraints we can not use IntegrityProtectedDevice.class.getSimpleName(). // This is admin-gui and does not have access to that class final String integrityProtectedName = "IntegrityProtectedDevice"; for (Iterator<String> iterator = loggerIds.iterator(); iterator.hasNext();) { final String id = (String) iterator.next(); if (integrityProtectedName.equals(id)) { // Make a log row that integrity protected device is configured final Map<String, Object> logdetails = new LinkedHashMap<String, Object>(); try { // Use reflection to get the ProtectedDataConfiguration and make some calls to it. // This is needed since ProtectedDataConfiguration may not be available during compile time, or runtime Class<?> c = Class.forName("org.cesecore.dbprotection.ProtectedDataConfiguration"); // create instance ProtectedDataConfiguration.instance() Method instance = c.getMethod("instance", (Class[]) null); //Object[] args = new Object[0]; Object config = instance.invoke(null); // create method ProtectedDataConfiguration.getKeyId(String) Method getKeyId = c.getMethod("getKeyId", String.class); // create method ProtectedDataConfiguration.getProtectVersion(int) Method getProtectVersion = c.getMethod("getProtectVersion", Integer.TYPE); // create method ProtectedDataConfiguration.getKeyLabel(int) Method getKeyLabel = c.getMethod("getKeyLabel", Integer.TYPE); // Call ProtectedDataConfiguration.instance().getKeyId final String auditTableName = AuditRecordData.class.getSimpleName(); final Integer keyid = (Integer) getKeyId.invoke(config, auditTableName); if ((keyid != null) && (keyid > 0)) { if (CesecoreConfiguration.useDatabaseIntegrityProtection(auditTableName)) { // Call ProtectedDataConfiguration.instance().getProtectVersion final Integer protectVersion = (Integer) getProtectVersion.invoke(config, keyid); // Call ProtectedDataConfiguration.instance().getKeyLabel final String keyLabel = (String) getKeyLabel.invoke(config, keyid); logdetails.put("keyid", keyid); logdetails.put("protectVersion", protectVersion); logdetails.put("keyLabel", keyLabel); logSession.log(EventTypes.LOG_MANAGEMENT_CHANGE, EventStatus.SUCCESS, ModuleTypes.SECURITY_AUDIT, ServiceTypes.CORE, admin.toString(), null, null, null, logdetails); ret = true; } else { log.debug("No database integrity protection enabled for AuditRecordData."); } } else { log.debug("No keyid configured for AuditRecordData."); } } catch (ClassNotFoundException e) { log.info("No database integrity protection available in this version of EJBCA."); } catch (IllegalAccessException e) { log.info("No database integrity protection available due to initialization error: ", e); } catch (SecurityException e) { log.info("No database integrity protection available due to initialization error: ", e); } catch (NoSuchMethodException e) { log.info("No database integrity protection available due to initialization error: ", e); } catch (IllegalArgumentException e) { log.info("No database integrity protection available due to initialization error: ", e); } catch (InvocationTargetException e) { log.info("No database integrity protection available due to initialization error: ", e); } } } return ret; }
From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java
/** * Returns a new value that is not equal to oldVal. The returned object * will always be a NEW instance compatible with oldVal. This differs from * {@link #modifyObject(MatchMakerObject, PropertyDescriptor, Object)} in that * this does not take mutability into account. * /*from www . j a va 2s . c o 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. */ private Object getNewDifferentValue(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal) throws IOException { Object newVal; // don't init here so compiler can warn if the // following code doesn't always give it a value if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { if (oldVal == null) newVal = new Integer(0); else { newVal = ((Integer) oldVal) + 1; } } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) { if (oldVal == null) newVal = new Short("0"); else { Integer temp = (Short) oldVal + 1; newVal = Short.valueOf(temp.toString()); } } else if (property.getPropertyType() == String.class) { // make sure it's unique newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) { if (oldVal == null) { newVal = new Boolean(false); } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == Long.class) { if (oldVal == null) { newVal = new Long(0L); } else { newVal = new Long(((Long) oldVal).longValue() + 1L); } } else if (property.getPropertyType() == BigDecimal.class) { if (oldVal == null) { newVal = new BigDecimal(0); } else { newVal = new BigDecimal(((BigDecimal) oldVal).longValue() + 1L); } } else if (property.getPropertyType() == MungeSettings.class) { newVal = new MungeSettings(); Integer processCount = ((MatchMakerSettings) newVal).getProcessCount(); if (processCount == null) { processCount = new Integer(0); } else { processCount = new Integer(processCount + 1); } ((MatchMakerSettings) newVal).setProcessCount(processCount); } else if (property.getPropertyType() == MergeSettings.class) { newVal = new MergeSettings(); Integer processCount = ((MatchMakerSettings) newVal).getProcessCount(); if (processCount == null) { processCount = new Integer(0); } else { processCount = new Integer(processCount + 1); } ((MatchMakerSettings) newVal).setProcessCount(processCount); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); } else if (property.getPropertyType() == ViewSpec.class) { newVal = new ViewSpec("*", "test_table", "true"); } else if (property.getPropertyType() == File.class) { newVal = File.createTempFile("mmTest", ".tmp"); ((File) newVal).deleteOnExit(); } else if (property.getPropertyType() == PlFolder.class) { newVal = new PlFolder(); } else if (property.getPropertyType() == ProjectMode.class) { if (oldVal == ProjectMode.BUILD_XREF) { newVal = ProjectMode.FIND_DUPES; } else { newVal = ProjectMode.BUILD_XREF; } } else if (property.getPropertyType() == MergeActionType.class) { if (oldVal == MergeActionType.AUGMENT) { newVal = MergeActionType.SUM; } else { newVal = MergeActionType.AUGMENT; } } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) { newVal = new MatchMakerTranslateGroup(); } else if (property.getPropertyType() == MatchMakerObject.class) { newVal = new TestingAbstractMatchMakerObject(); } else if (property.getPropertyType() == SQLColumn.class) { newVal = new SQLColumn(); } else if (property.getPropertyType() == Date.class) { newVal = new Date(); } else if (property.getPropertyType() == List.class) { newVal = new ArrayList(); } else if (property.getPropertyType() == Project.class) { newVal = new Project(); ((Project) newVal).setName("Fake_Project_" + System.currentTimeMillis()); } else if (property.getPropertyType() == SQLIndex.class) { return new SQLIndex("new index", false, "", "HASHED", ""); } else if (property.getPropertyType() == Color.class) { if (oldVal == null) { newVal = new Color(0xFAC157); } else { Color oldColor = (Color) oldVal; newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000); } } else if (property.getPropertyType() == ChildMergeActionType.class) { if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) { newVal = ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT; } else { newVal = ChildMergeActionType.DELETE_ALL_DUP_CHILD; } } else if (property.getPropertyType() == MungeResultStep.class || property.getPropertyType() == DeDupeResultStep.class) { newVal = new DeDupeResultStep(); } else if (property.getPropertyType() == TableMergeRules.class) { if (oldVal == null) { newVal = mmo; } else { newVal = null; } } else if (property.getPropertyType() == PoolFilterSetting.class) { if (oldVal != PoolFilterSetting.EVERYTHING) { newVal = PoolFilterSetting.EVERYTHING; } else { newVal = PoolFilterSetting.INVALID_ONLY; } } else if (property.getPropertyType() == AutoValidateSetting.class) { if (oldVal != AutoValidateSetting.NOTHING) { newVal = AutoValidateSetting.NOTHING; } else { newVal = AutoValidateSetting.SERP_CORRECTABLE; } } else if (property.getPropertyType() == Point.class) { if (oldVal == null) { newVal = new Point(0, 0); } else { newVal = new Point(((Point) oldVal).x + 1, ((Point) oldVal).y + 1); } } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") from " + mmo.getClass()); } if (newVal instanceof MatchMakerObject) { ((MatchMakerObject) newVal).setSession(session); } return newVal; }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a Number to the given primitive number class *///from ww w. jav a2 s .co m static Number coerceToPrimitiveNumber(Number pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte(pValue.byteValue()); } else if (pClass == Short.class || pClass == Short.TYPE) { return PrimitiveObjects.getShort(pValue.shortValue()); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return PrimitiveObjects.getInteger(pValue.intValue()); } else if (pClass == Long.class || pClass == Long.TYPE) { return PrimitiveObjects.getLong(pValue.longValue()); } else if (pClass == Float.class || pClass == Float.TYPE) { return PrimitiveObjects.getFloat(pValue.floatValue()); } else if (pClass == Double.class || pClass == Double.TYPE) { return PrimitiveObjects.getDouble(pValue.doubleValue()); } else if (pClass == BigInteger.class) { if (pValue instanceof BigDecimal) return ((BigDecimal) pValue).toBigInteger(); else return BigInteger.valueOf(pValue.longValue()); } else if (pClass == BigDecimal.class) { if (pValue instanceof BigInteger) return new BigDecimal((BigInteger) pValue); else return new BigDecimal(pValue.doubleValue()); } else { return PrimitiveObjects.getInteger(0); } }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Gets the bean size intern.// w w w . j a v a 2 s . c om * * @param bean the bean * @param clazz the clazz * @param m the m * @param classNameMatcher the class name matcher * @param fieldNameMatcher the field name matcher * @return the bean size intern */ public static int getBeanSizeIntern(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m, Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) { if (classNameMatcher.match(clazz.getName()) == false) { return 0; } if (clazz.isArray() == true) { if (clazz == boolean[].class) { return (((boolean[]) bean).length * 4); } else if (clazz == char[].class) { return (((char[]) bean).length * 2); } else if (clazz == byte[].class) { return (((byte[]) bean).length * 1); } else if (clazz == short[].class) { return (((short[]) bean).length * 2); } else if (clazz == int[].class) { return (((int[]) bean).length * 4); } else if (clazz == long[].class) { return (((long[]) bean).length * 4); } else if (clazz == float[].class) { return (((float[]) bean).length * 4); } else if (clazz == double[].class) { return (((double[]) bean).length * 8); } else { int length = Array.getLength(bean); int ret = (length * 4); for (int i = 0; i < length; ++i) { ret += getBeanSize(Array.get(bean, i), m, classNameMatcher, fieldNameMatcher); } return ret; } } int ret = 0; try { for (Field f : clazz.getDeclaredFields()) { int mod = f.getModifiers(); if (Modifier.isStatic(mod) == true) { continue; } if (fieldNameMatcher.match(clazz.getName() + "." + f.getName()) == false) { continue; } if (f.getType() == Boolean.TYPE) { ret += 4; } else if (f.getType() == Character.TYPE) { ret += 2; } else if (f.getType() == Byte.TYPE) { ret += 1; } else if (f.getType() == Short.TYPE) { ret += 2; } else if (f.getType() == Integer.TYPE) { ret += 4; } else if (f.getType() == Long.TYPE) { ret += 8; } else if (f.getType() == Float.TYPE) { ret += 4; } else if (f.getType() == Double.TYPE) { ret += 8; } else { ret += 4; Object o = null; try { o = readField(bean, f); if (o == null) { continue; } } catch (NoClassDefFoundError ex) { // nothing continue; } int nestedsize = getBeanSize(o, o.getClass(), m, classNameMatcher, fieldNameMatcher); ret += nestedsize; } } } catch (NoClassDefFoundError ex) { // ignore here. } if (clazz == Object.class || clazz.getSuperclass() == null) { return ret; } ret += getBeanSizeIntern(bean, clazz.getSuperclass(), m, classNameMatcher, fieldNameMatcher); return ret; }
From source file:org.apache.syncope.core.provisioning.java.ConnectorFacadeProxy.java
private Object getPropertyValue(final String propType, final List<?> values) { Object value = null;/*w ww . j a v a 2 s.c o m*/ try { Class<?> propertySchemaClass = ClassUtils.forName(propType, ClassUtils.getDefaultClassLoader()); if (GuardedString.class.equals(propertySchemaClass)) { value = new GuardedString(values.get(0).toString().toCharArray()); } else if (GuardedByteArray.class.equals(propertySchemaClass)) { value = new GuardedByteArray((byte[]) values.get(0)); } else if (Character.class.equals(propertySchemaClass) || Character.TYPE.equals(propertySchemaClass)) { value = values.get(0) == null || values.get(0).toString().isEmpty() ? null : values.get(0).toString().charAt(0); } else if (Integer.class.equals(propertySchemaClass) || Integer.TYPE.equals(propertySchemaClass)) { value = Integer.parseInt(values.get(0).toString()); } else if (Long.class.equals(propertySchemaClass) || Long.TYPE.equals(propertySchemaClass)) { value = Long.parseLong(values.get(0).toString()); } else if (Float.class.equals(propertySchemaClass) || Float.TYPE.equals(propertySchemaClass)) { value = Float.parseFloat(values.get(0).toString()); } else if (Double.class.equals(propertySchemaClass) || Double.TYPE.equals(propertySchemaClass)) { value = Double.parseDouble(values.get(0).toString()); } else if (Boolean.class.equals(propertySchemaClass) || Boolean.TYPE.equals(propertySchemaClass)) { value = Boolean.parseBoolean(values.get(0).toString()); } else if (URI.class.equals(propertySchemaClass)) { value = URI.create(values.get(0).toString()); } else if (File.class.equals(propertySchemaClass)) { value = new File(values.get(0).toString()); } else if (String[].class.equals(propertySchemaClass)) { value = values.toArray(new String[] {}); } else { value = values.get(0) == null ? null : values.get(0).toString(); } } catch (Exception e) { LOG.error("Invalid ConnConfProperty specified: {} {}", propType, values, e); } return value; }