List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
From source file:org.impalaframework.spring.DebuggingInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { logger.debug("Calling method " + invocation); Class<?> returnType = invocation.getMethod().getReturnType(); if (Void.TYPE.equals(returnType)) return null; if (Byte.TYPE.equals(returnType)) return (byte) 0; if (Short.TYPE.equals(returnType)) return (short) 0; if (Integer.TYPE.equals(returnType)) return (int) 0; if (Long.TYPE.equals(returnType)) return 0L; if (Float.TYPE.equals(returnType)) return 0f; if (Double.TYPE.equals(returnType)) return 0d; if (Boolean.TYPE.equals(returnType)) return false; return null;//from w w w . j ava 2 s. co m }
From source file:org.pentaho.platform.plugin.services.versionchecker.PentahoVersionCheckReflectHelper.java
public static List performVersionCheck(final boolean ignoreExistingUpdates, final int versionRequestFlags) { // check to see if jar is loaded before continuing if (PentahoVersionCheckReflectHelper.isVersionCheckerAvailable()) { try {//from w ww . j av a 2 s . c om // use reflection so anyone can delete the version checker jar without pain // PentahoVersionCheckHelper helper = new PentahoVersionCheckHelper(); Class helperClass = Class .forName("org.pentaho.platform.plugin.services.versionchecker.PentahoVersionCheckHelper"); //$NON-NLS-1$ Object helper = helperClass.getConstructors()[0].newInstance(new Object[] {}); // helper.setIgnoreExistingUpdates(ignoreExistingUpdates); Method setIgnoreExistingUpdatesMethod = helperClass.getDeclaredMethod("setIgnoreExistingUpdates", //$NON-NLS-1$ new Class[] { Boolean.TYPE }); setIgnoreExistingUpdatesMethod.invoke(helper, new Object[] { new Boolean(ignoreExistingUpdates) }); // helper.setVersionRequestFlags(versionRequestFlags); Method setVersionRequestFlagsMethod = helperClass.getDeclaredMethod("setVersionRequestFlags", //$NON-NLS-1$ new Class[] { Integer.TYPE }); setVersionRequestFlagsMethod.invoke(helper, new Object[] { new Integer(versionRequestFlags) }); // helper.performUpdate(); Method performUpdateMethod = helperClass.getDeclaredMethod("performUpdate", new Class[] {}); //$NON-NLS-1$ performUpdateMethod.invoke(helper, new Object[] {}); // List results = helper.getResults(); Method getResultsMethod = helperClass.getDeclaredMethod("getResults", new Class[] {}); //$NON-NLS-1$ List results = (List) getResultsMethod.invoke(helper, new Object[] {}); return results; } catch (Exception e) { // ignore errors } } return null; }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }// w ww. j a va2s . com if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return oStr; } if (clazz.equals(java.util.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(java.sql.Date.class)) { return java.sql.Date.valueOf(oStr); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:io.github.benas.jpopulator.impl.DefaultRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @return a random value for the given type or null if the type is not supported *///from w w w . j av a2 s .c o m public static Object getRandomValue(final Class type) { /* * String and Character types */ if (type.equals(String.class)) { return RandomStringUtils.randomAlphabetic(ConstantsUtil.DEFAULT_STRING_LENGTH); } if (type.equals(Character.TYPE) || type.equals(Character.class)) { return RandomStringUtils.randomAlphabetic(1).charAt(0); } /* * Boolean type */ if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return ConstantsUtil.RANDOM.nextBoolean(); } /* * Numeric types */ if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) (ConstantsUtil.RANDOM.nextInt()); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return ConstantsUtil.RANDOM.nextInt(); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return ConstantsUtil.RANDOM.nextLong(); } if (type.equals(Double.TYPE) || type.equals(Double.class)) { return ConstantsUtil.RANDOM.nextDouble(); } if (type.equals(Float.TYPE) || type.equals(Float.class)) { return ConstantsUtil.RANDOM.nextFloat(); } if (type.equals(BigInteger.class)) { return new BigInteger( Math.abs(ConstantsUtil.RANDOM.nextInt(ConstantsUtil.DEFAULT_BIG_INTEGER_NUM_BITS_LENGTH)), ConstantsUtil.RANDOM); } if (type.equals(BigDecimal.class)) { return new BigDecimal(ConstantsUtil.RANDOM.nextDouble()); } if (type.equals(AtomicLong.class)) { return new AtomicLong(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(AtomicInteger.class)) { return new AtomicInteger(ConstantsUtil.RANDOM.nextInt()); } /* * Date and time types */ if (type.equals(java.util.Date.class)) { return ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue(); } if (type.equals(java.sql.Date.class)) { return new java.sql.Date(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(java.sql.Time.class)) { return new java.sql.Time(ConstantsUtil.RANDOM.nextLong()); } if (type.equals(java.sql.Timestamp.class)) { return new java.sql.Timestamp(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(Calendar.class)) { return Calendar.getInstance(); } if (type.equals(org.joda.time.DateTime.class)) { return new org.joda.time.DateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDate.class)) { return new org.joda.time.LocalDate(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalTime.class)) { return new org.joda.time.LocalTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.LocalDateTime.class)) { return new org.joda.time.LocalDateTime(ConstantsUtil.DATE_RANGE_RANDOMIZER.getRandomValue().getTime()); } if (type.equals(org.joda.time.Duration.class)) { return new org.joda.time.Duration(Math.abs(ConstantsUtil.RANDOM.nextLong())); } if (type.equals(org.joda.time.Period.class)) { return new org.joda.time.Period(Math.abs(ConstantsUtil.RANDOM.nextInt())); } if (type.equals(org.joda.time.Interval.class)) { long startDate = Math.abs(ConstantsUtil.RANDOM.nextInt()); long endDate = startDate + Math.abs(ConstantsUtil.RANDOM.nextInt()); return new org.joda.time.Interval(startDate, endDate); } /* * Enum type */ if (type.isEnum() && type.getEnumConstants().length > 0) { Object[] enumConstants = type.getEnumConstants(); return enumConstants[ConstantsUtil.RANDOM.nextInt(enumConstants.length)]; } /* * Return null for any unsupported type */ return null; }
From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java
public PrimitiveMapping(MethodInfo getter) { super(getter); TypeInfo type = getter.getReturnType(); Class primitive = type.isPrimitive(); this.boxed = (primitive == null); if (primitive != null) { this.nullable = false; }// w w w .j ava 2 s.com if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName()) || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName()) || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName()) || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName()) || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) { sqlTypeName = SqliteTypes.integer; } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName()) || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) { sqlTypeName = SqliteTypes.real; } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) { sqlTypeName = SqliteTypes.text; } String suffix = type.getSimpleName(); if (suffix.equals("Integer")) { suffix = "Int"; } else if (suffix.equals("Character")) { suffix = "Char"; } suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1); readerName = "Readers.read" + suffix; stmtSetter = "set" + suffix; }
From source file:com.csipsimple.utils.Columns.java
public Columns(String[] names, Class<?>[] classes) { this.names = names; types = new Type[names.length]; for (int i = 0; i < names.length; i++) { if (classes[i] == String.class) { types[i] = Type.STRING; } else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) { types[i] = Type.INT;/*from ww w.j a v a2s.com*/ } else if (classes[i] == Long.TYPE || classes[i] == Long.class) { types[i] = Type.LONG; } else if (classes[i] == Float.TYPE || classes[i] == Float.class) { types[i] = Type.FLOAT; } else if (classes[i] == Double.TYPE || classes[i] == Double.class) { types[i] = Type.DOUBLE; } else if (classes[i] == Boolean.TYPE || classes[i] == Boolean.class) { types[i] = Type.BOOLEAN; } } }
From source file:org.fhcrc.cpl.viewer.util.ConvertHelper.java
protected void register() { super.register(); ConvertUtils.register(new MyBooleanConverter(), Boolean.TYPE); ConvertUtils.register(new NullSafeConverter(new MyBooleanConverter()), Boolean.class); ConvertUtils.register(new NullSafeConverter(new ByteArrayConverter()), byte[].class); ConvertUtils.register(new PercentWrapper(new DoubleConverter()), Double.TYPE); ConvertUtils.register(new NullSafeConverter(new PercentWrapper(new DoubleConverter())), Double.class); ConvertUtils.register(new PercentWrapper(new FloatConverter()), Float.TYPE); ConvertUtils.register(new NullSafeConverter(new PercentWrapper(new FloatConverter())), Float.class); ConvertUtils.register(new ChargeWrapper(new IntegerConverter()), Integer.TYPE); ConvertUtils.register(new NullSafeConverter(new ChargeWrapper(new IntegerConverter())), Integer.class); ConvertUtils.register(new NullSafeConverter(new DateFriendlyStringConverter()), String.class); ConvertUtils.register(new LenientTimestampConverter(), java.sql.Timestamp.class); ConvertUtils.register(new LenientDateConverter(), java.util.Date.class); }
From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java
public PrimitiveType getPrimitiveType(Class primitiveType) { if (String.class.isAssignableFrom(primitiveType)) { return new SimpleTextType(); } else if (Boolean.TYPE.isAssignableFrom(primitiveType)) { final BooleanTypeImpl booleanTypeImpl = new BooleanTypeImpl(); booleanTypeImpl.setNullable(false); return booleanTypeImpl; } else if (Boolean.class.isAssignableFrom(primitiveType)) { return new BooleanTypeImpl(); } else if (double.class.isAssignableFrom(primitiveType)) { final DoubleType doubleTypeImpl = new DoubleType(); doubleTypeImpl.setNullable(false); return doubleTypeImpl; } else if (Double.class.isAssignableFrom(primitiveType)) { return new DoubleType(); } else if (float.class.isAssignableFrom(primitiveType)) { final FloatTypeImpl typeImpl = new FloatTypeImpl(); typeImpl.setNullable(false);//from ww w .ja v a 2 s . c o m return typeImpl; } else if (Float.class.isAssignableFrom(primitiveType)) { return new FloatTypeImpl(); } else if (BigDecimal.class.isAssignableFrom(primitiveType)) { return new BigDecimalTypeImpl(); } else if (int.class.isAssignableFrom(primitiveType)) { final IntegerType integerTypeImpl = new IntegerType(); integerTypeImpl.setNullable(false); return integerTypeImpl; } else if (Integer.class.isAssignableFrom(primitiveType)) { return new IntegerType(); } else if (long.class.isAssignableFrom(primitiveType)) { return new LongType(false); } else if (Long.class.isAssignableFrom(primitiveType)) { return new LongType(true); } else if (Number.class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(Number.class, true); } else if (Character.TYPE.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(Character.TYPE, false); } else if (Character.class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(Character.class, true); } else if (BigDecimal.class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(BigDecimal.class, true); } else if (BigInteger.class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(BigInteger.class, true); } else if (Byte.TYPE.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(Byte.TYPE, false); } else if (byte[].class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(byte[].class, true); } else if (Byte.class.isAssignableFrom(primitiveType)) { return new SimplePrimitiveType(Byte.class, true); } else if (Enum.class.isAssignableFrom(primitiveType)) { return new SimpleEnumType(primitiveType); } else { PrimitiveType found = classToType.get(primitiveType); Class parentClass = primitiveType; while (found == null && parentClass.getSuperclass() != null) { found = classToType.get(parentClass); parentClass = parentClass.getSuperclass(); } if (found == null) { for (Class<?> interfaze : primitiveType.getInterfaces()) { found = classToType.get(interfaze); if (found != null) { return found; } } } return found; } }
From source file:org.wso2.carbon.analytics.spark.core.util.AnalyticsCommonUtils.java
public static DataType getDataType(Type returnType) throws AnalyticsUDFException { DataType udfReturnType = null;/* w w w . j ava 2s. co m*/ if (returnType == Integer.TYPE || returnType == Integer.class) { udfReturnType = DataTypes.IntegerType; } else if (returnType == Double.TYPE || returnType == Double.class) { udfReturnType = DataTypes.DoubleType; } else if (returnType == Float.TYPE || returnType == Float.class) { udfReturnType = DataTypes.FloatType; } else if (returnType == Long.TYPE || returnType == Long.class) { udfReturnType = DataTypes.LongType; } else if (returnType == Boolean.TYPE || returnType == Boolean.class) { udfReturnType = DataTypes.BooleanType; } else if (returnType == String.class) { udfReturnType = DataTypes.StringType; } else if (returnType == Short.TYPE || returnType == Short.class) { udfReturnType = DataTypes.ShortType; } else if (returnType == NullType.class) { udfReturnType = DataTypes.NullType; } else if (returnType == Byte.TYPE || returnType == Byte.class) { udfReturnType = DataTypes.ByteType; } else if (returnType == byte[].class || returnType == Byte[].class) { udfReturnType = DataTypes.BinaryType; } else if (returnType == Date.class) { udfReturnType = DataTypes.DateType; } else if (returnType == Timestamp.class) { udfReturnType = DataTypes.TimestampType; } else if (returnType == BigDecimal.class) { udfReturnType = DataTypes.createDecimalType(); } else if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; /*if return type is a List types will contain only 1 element, if return type is Map it will have 2 elements types representing key and the value.*/ Type[] types = type.getActualTypeArguments(); if (types != null && types.length > 0) { switch (types.length) { case 1: { udfReturnType = DataTypes.createArrayType(getDataType(types[0])); break; } case 2: { udfReturnType = DataTypes.createMapType(getDataType(types[0]), getDataType(types[1])); break; } default: throw new AnalyticsUDFException("Cannot Map the return type either to ArrayType or MapType"); } } } else { throw new AnalyticsUDFException("Cannot determine the return DataType"); } return udfReturnType; }
From source file:com.microsoft.tfs.client.common.ui.helpers.EditorHelper.java
/** * Saves all dirty editors matching the given saveable filter. * * @param filter/* w w w . j a v a 2 s . c om*/ * the {@link WorkbenchPartSaveableFilter} to use to determine if the * given workbench parts should be saved (not <code>null</code>) * * @return <code>true</code> if successful, <code>false</code> if the user * cancelled the command. */ public static boolean saveAllDirtyEditors(final WorkbenchPartSaveableFilter filter) { /* * Attempt to save all dirty editors. Eclipse 3.3+ offers "saveAll" * which allows us to pick an choose which dirty items will be saved. * Older versions of Eclipse only offer "saveAllEditors" which saves * every dirty editor. Pre-10.0 versions of Team Explorer used * "saveAllEditors" which remains as the fallback. * * As an additional headache, Eclipse 3.0 (RAD 6.0) does not have some * of the interface types the method uses, so we have to load those via * reflection before finding the "saveAll" method. */ final IWorkbench workbench = PlatformUI.getWorkbench(); boolean saveResult = false; boolean reflectionError = false; try { // Since Eclipse 3.1 final Class iShellProviderClass = CheckinControl.class.getClassLoader() .loadClass("org.eclipse.jface.window.IShellProvider"); //$NON-NLS-1$ // Since Eclipse 3.3 final Class iSaveableFilterClass = CheckinControl.class.getClassLoader() .loadClass("org.eclipse.ui.ISaveableFilter"); //$NON-NLS-1$ final Class[] parameters = new Class[4]; parameters[0] = iShellProviderClass; parameters[1] = IRunnableContext.class; parameters[2] = iSaveableFilterClass; parameters[3] = Boolean.TYPE; final Method m = workbench.getClass().getMethod("saveAll", parameters); //$NON-NLS-1$ final Object[] arguments = new Object[4]; arguments[0] = workbench.getActiveWorkbenchWindow(); arguments[1] = workbench.getActiveWorkbenchWindow(); arguments[2] = new WorkbenchPartSaveableFilterAdapter(filter); arguments[3] = Boolean.TRUE; try { final Boolean result = (Boolean) m.invoke(workbench, arguments); saveResult = result.booleanValue(); } catch (final Exception e) { saveResult = false; } } catch (final ClassNotFoundException e) { reflectionError = true; } catch (final NoSuchMethodException e) { reflectionError = true; } if (reflectionError) { saveResult = workbench.saveAllEditors(true); } return saveResult; }