Example usage for java.lang Integer TYPE

List of usage examples for java.lang Integer TYPE

Introduction

In this page you can find the example usage for java.lang Integer TYPE.

Prototype

Class TYPE

To view the source code for java.lang Integer TYPE.

Click Source Link

Document

The Class instance representing the primitive type int .

Usage

From source file:org.jdto.util.ClassUtils.java

/**
 * <p>Checks if one/*from  w  w  w  . j  a va 2s. co  m*/
 * <code>Class</code> can be assigned to a variable of another
 * <code>Class</code>.</p>
 *
 * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method,
 * this method takes into account widenings of primitive classes and
 * <code>null</code>s.</p>
 *
 * <p>Primitive widenings allow an int to be assigned to a long, float or
 * double. This method returns the correct result for these cases.</p>
 *
 * <p><code>Null</code> may be assigned to any reference type. This method
 * will return
 * <code>true</code> if
 * <code>null</code> is passed in and the toClass is non-primitive.</p>
 *
 * <p>Specifically, this method tests whether the type represented by the
 * specified
 * <code>Class</code> parameter can be converted to the type represented by
 * this
 * <code>Class</code> object via an identity conversion widening primitive
 * or widening reference conversion. See <em><a
 * href="http://java.sun.com/docs/books/jls/">The Java Language
 * Specification</a></em>, sections 5.1.1, 5.1.2 and 5.1.4 for details.</p>
 *
 * @param cls the Class to check, may be null
 * @param toClass the Class to try to assign into, returns false if null
 * @param autoboxing whether to use implicit autoboxing/unboxing between
 * primitives and wrappers
 * @return
 * <code>true</code> if assignment possible
 * @since 2.5
 */
public static boolean isAssignable(Class cls, Class toClass, boolean autoboxing) {
    if (toClass == null) {
        return false;
    }
    // have to check for null, as isAssignableFrom doesn't
    if (cls == null) {
        return !(toClass.isPrimitive());
    }
    //autoboxing:
    if (autoboxing) {
        if (cls.isPrimitive() && !toClass.isPrimitive()) {
            cls = primitiveToWrapper(cls);
            if (cls == null) {
                return false;
            }
        }
        if (toClass.isPrimitive() && !cls.isPrimitive()) {
            cls = wrapperToPrimitive(cls);
            if (cls == null) {
                return false;
            }
        }
    }
    if (cls.equals(toClass)) {
        return true;
    }
    if (cls.isPrimitive()) {
        if (toClass.isPrimitive() == false) {
            return false;
        }
        if (Integer.TYPE.equals(cls)) {
            return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Long.TYPE.equals(cls)) {
            return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        if (Boolean.TYPE.equals(cls)) {
            return false;
        }
        if (Double.TYPE.equals(cls)) {
            return false;
        }
        if (Float.TYPE.equals(cls)) {
            return Double.TYPE.equals(toClass);
        }
        if (Character.TYPE.equals(cls)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Short.TYPE.equals(cls)) {
            return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass)
                    || Double.TYPE.equals(toClass);
        }
        if (Byte.TYPE.equals(cls)) {
            return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass)
                    || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass);
        }
        // should never get here
        return false;
    }
    return toClass.isAssignableFrom(cls);
}

From source file:ca.sqlpower.architect.swingui.TestPlayPenComponent.java

/**
 * Returns true if an instance of the given property type is of a mutable class.
 * Throws an exception if it lacks a case for the given type.
 * //from w w w  . j  a va 2s .  com
 * @param property The property that should be checked for mutability.
 */
private boolean isPropertyInstanceMutable(PropertyDescriptor property) {
    if (property.getPropertyType() == String.class) {
        return false;
    } else if (property.getPropertyType().isAssignableFrom(Enum.class)) {
        return false;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return false;
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        return false;
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        return false;
    } else if (property.getPropertyType() == Color.class) {
        return false;
    } else if (property.getPropertyType() == Font.class) {
        return false;
    } else if (property.getPropertyType() == Point.class) {
        return true;
    } else if (property.getPropertyType() == Dimension.class) {
        return true;
    } else if (property.getPropertyType() == Insets.class) {
        return true;
    } else if (property.getPropertyType() == Set.class) {
        return true;
    } else if (property.getPropertyType() == List.class) {
        return true;
    } else if (property.getPropertyType() == TablePane.class) {
        return true;
    } else if (property.getPropertyType() == SQLTable.class) {
        return true;
    } else if (property.getPropertyType() == JPopupMenu.class) {
        return true;
    }
    if (property.getName().equals("model")) {
        return true;
    }
    throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
            + property.getPropertyType().getName() + ") in isPropertyInstanceMutable()");
}

From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.BindQueryParametersHandler.java

/**
 * Binds the parameters to given statement.
 * @param parameter the {@link Parameter}.
 * @param parameterIndex the parameter index.
 * @param sql the sql./*from   w  w w.  j  ava2s. c o m*/
 * @param statement the prepared statement.
 * @param typeManager the metadata type manager.
 * @param conversionUtils the <code>ConversionUtils</code> instance.
 * @param <T> the type.
 * @throws QueryJBuildException if the binding fails.
 */
@SuppressWarnings("unchecked")
protected <T> void bindParameter(@NotNull final Parameter<String, T> parameter, final int parameterIndex,
        @NotNull final Sql<String> sql, @NotNull final PreparedStatement statement,
        @NotNull final TypeManager typeManager, @NotNull final ConversionUtils conversionUtils)
        throws QueryJBuildException {
    @Nullable
    QueryJBuildException exceptionToThrow = null;

    @Nullable
    final Log t_Log = UniqueLogFactory.getLog(CustomSqlValidationHandler.class);

    @Nullable
    final Method t_Method;

    @Nullable
    final Collection<Class<?>> t_cParameterClasses;

    @Nullable
    final Class<T> t_Type = retrieveType(parameter, typeManager);

    if (t_Type != null) {
        if (typeManager.isPrimitiveWrapper(t_Type)) {
            t_cParameterClasses = Arrays.asList(Integer.TYPE, typeManager.toPrimitive(t_Type));
        } else {
            t_cParameterClasses = Arrays.asList(Integer.TYPE, t_Type);
        }

        t_Method = retrievePreparedStatementMethod(parameter, parameterIndex, t_Type, sql, t_cParameterClasses);

        @Nullable
        final Object t_ParameterValue = retrieveParameterValue(parameter, parameterIndex,
                t_Type.getSimpleName(), t_Type, sql, conversionUtils);

        try {
            t_Method.invoke(statement, parameterIndex + 1, t_ParameterValue);
        } catch (@NotNull final IllegalAccessException illegalAccessException) {
            if (t_Log != null) {
                t_Log.warn(COULD_NOT_BIND_PARAMETER_VIA + PREPARED_STATEMENT_SET + t_Type.getSimpleName()
                        + "(int, " + t_Type.getName() + ")", illegalAccessException);
            }

            exceptionToThrow = new UnsupportedCustomSqlParameterTypeException(t_Type.getSimpleName(),
                    parameterIndex + 1, parameter.getName(), sql, illegalAccessException);
        } catch (@NotNull final InvocationTargetException invocationTargetException) {
            if (t_Log != null) {
                t_Log.warn(COULD_NOT_BIND_PARAMETER_VIA + PREPARED_STATEMENT_SET + t_Type.getSimpleName()
                        + "(int, " + t_Type.getName() + ")", invocationTargetException);
            }

            exceptionToThrow = new UnsupportedCustomSqlParameterTypeException(t_Type.getSimpleName(),
                    parameterIndex + 1, parameter.getName(), sql, invocationTargetException);
        }
    }

    if (exceptionToThrow != null) {
        throw exceptionToThrow;
    }
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <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>/*from  w  ww .j av  a  2s . c  om*/
 * ArrayUtils.add(null, 0)   = [0]
 * ArrayUtils.add([1], 0)    = [1, 0]
 * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static int[] add(int[] array, int element) {
    int[] newArray = (int[]) copyArrayGrow1(array, Integer.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:com.aol.one.patch.DefaultPatcher.java

private List<MethodData> generateMethodData(List<String> methodNames, JsonNode valueNode) {

    List<MethodData> dataList = new ArrayList<>();
    if (valueNode.isTextual()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, String.class, valueNode.asText()));
        }//from  w ww.  j a v  a2s . c  om
    } else if (valueNode.isNumber()) {
        for (String methodName : methodNames) {
            if (valueNode.isIntegralNumber()) {
                dataList.add(new MethodData(methodName, Long.TYPE, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Long.class, valueNode.asLong()));
                dataList.add(new MethodData(methodName, Integer.TYPE, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Integer.class, valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.TYPE, (short) valueNode.asInt()));
                dataList.add(new MethodData(methodName, Short.class, (short) valueNode.asInt()));
            } else {
                dataList.add(new MethodData(methodName, Double.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Double.class, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.TYPE, valueNode.asDouble()));
                dataList.add(new MethodData(methodName, Float.class, valueNode.asDouble()));
            }
        }
    } else if (valueNode.isBoolean()) {
        for (String methodName : methodNames) {
            dataList.add(new MethodData(methodName, Boolean.TYPE, valueNode.asBoolean()));
            dataList.add(new MethodData(methodName, Boolean.class, valueNode.asBoolean()));
        }

    }

    // default
    for (String methodName : methodNames) {
        dataList.add(new MethodData(methodName, JsonNode.class, valueNode));
    }

    return dataList;
}

From source file:org.apache.mina.statemachine.transition.MethodTransition.java

@SuppressWarnings("unchecked")
private boolean match(Class<?> paramType, Object arg, Class argType) {
    if (paramType.isPrimitive()) {
        if (paramType.equals(Boolean.TYPE)) {
            return arg instanceof Boolean;
        }//w ww  . j  a  v a 2s . co m
        if (paramType.equals(Integer.TYPE)) {
            return arg instanceof Integer;
        }
        if (paramType.equals(Long.TYPE)) {
            return arg instanceof Long;
        }
        if (paramType.equals(Short.TYPE)) {
            return arg instanceof Short;
        }
        if (paramType.equals(Byte.TYPE)) {
            return arg instanceof Byte;
        }
        if (paramType.equals(Double.TYPE)) {
            return arg instanceof Double;
        }
        if (paramType.equals(Float.TYPE)) {
            return arg instanceof Float;
        }
        if (paramType.equals(Character.TYPE)) {
            return arg instanceof Character;
        }
    }
    return argType.isAssignableFrom(paramType) && paramType.isAssignableFrom(arg.getClass());
}

From source file:nz.co.senanque.validationengine.ValidationUtils.java

public static Comparable<?> convertTo(final Class<Comparable<?>> clazz, Object obj) {
    if (obj == null) {
        return null;
    }/*ww w  . j av a2s .  c o m*/
    if (clazz.isAssignableFrom(obj.getClass())) {
        return (Comparable<?>) obj;
    }
    final String oStr = String.valueOf(obj);
    if (clazz.equals(String.class)) {
        return oStr;
    }
    if (clazz.equals(Long.class) || clazz.equals(Long.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Long(((Number) obj).longValue());
        }
        return Long.valueOf(oStr);
    }
    if (clazz.equals(Integer.class) || clazz.equals(Integer.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Integer(((Number) obj).intValue());
        }
        return Integer.valueOf(oStr);
    }
    if (clazz.equals(Double.class) || clazz.equals(Double.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Double(((Number) obj).doubleValue());
        }
        return Double.valueOf(oStr);
    }
    if (clazz.equals(Float.class) || clazz.equals(Float.TYPE)) {
        if (Number.class.isAssignableFrom(obj.getClass())) {
            return new Float(((Number) obj).floatValue());
        }
        return Float.valueOf(oStr);
    }
    if (clazz.equals(BigDecimal.class)) {
        return new BigDecimal(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);
    }
    return null;
}

From source file:Main.java

/**
 * <p>Copies the given array and adds the given element at the end of the new array.</p>
 *
 * <p>The new array contains the same elements of the input
 * array plus the given element in the last position. The component type of
 * the new array is the same as that of the input array.</p>
 *
 * <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>/*from w  ww .j ava 2  s  . c  o  m*/
 * ArrayUtils.add(null, 0)   = [0]
 * ArrayUtils.add([1], 0)    = [1, 0]
 * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 * </pre>
 *
 * @param array  the array to copy and add the element to, may be {@code null}
 * @param element  the object to add at the last index of the new array
 * @return A new array containing the existing elements plus the new element
 * @since 2.1
 */
public static int[] add(final int[] array, final int element) {
    final int[] newArray = (int[]) copyArrayGrow1(array, Integer.TYPE);
    newArray[newArray.length - 1] = element;
    return newArray;
}

From source file:org.briljantframework.data.vector.ConvertTest.java

@Test
public void testTo_convertToComplex() throws Exception {

    System.out.println(Na.of(Integer.TYPE));

    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, 10));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, 10.0));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, 10.0f));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, 10l));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, (short) 10));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, (byte) 10));
    assertEquals(Complex.valueOf(10), Convert.to(Complex.class, Complex.valueOf(10)));
    assertEquals(Complex.valueOf(1), Convert.to(Complex.class, Logical.TRUE));
    assertEquals(Complex.valueOf(1), Convert.to(Complex.class, true));
}

From source file:org.androidtransfuse.analysis.FragmentAnalysis.java

private void setupFragmentProfile(ComponentDescriptor fragmentDescriptor, ASTType astType, ASTType fragmentType,
        AnalysisContext context, Integer layout) {

    ASTMethod onCreateViewMethod = getASTMethod("onCreateView", LayoutInflater.class, ViewGroup.class,
            Bundle.class);

    fragmentDescriptor.setInitMethodBuilder(astClassFactory.getType(OnCreate.class),
            componentBuilderFactory.buildFragmentMethodBuilder(layout, onCreateViewMethod));

    fragmentDescriptor.setInjectionNodeFactory(componentBuilderFactory
            .buildInjectionNodeFactory(ImmutableSet.<ASTAnnotation>of(), astType, context));

    //onActivityCreated
    fragmentDescriptor/* ww w  .  j  ava  2  s .  co  m*/
            .addGenerators(buildEventMethod(OnActivityCreated.class, "onActivityCreated", Bundle.class));
    //onStart
    fragmentDescriptor.addGenerators(buildEventMethod(OnStart.class, "onStart"));
    //onResume
    fragmentDescriptor.addGenerators(buildEventMethod(OnResume.class, "onResume"));
    //onPause
    fragmentDescriptor.addGenerators(buildEventMethod(OnPause.class, "onPause"));
    //onStop
    fragmentDescriptor.addGenerators(buildEventMethod(OnStop.class, "onStop"));
    //onDestroyView
    fragmentDescriptor.addGenerators(buildEventMethod(OnDestroyView.class, "onDestroyView"));
    //onDestroy
    fragmentDescriptor.addGenerators(buildEventMethod(OnDestroy.class, "onDestroy"));
    //onDetach
    fragmentDescriptor.addGenerators(buildEventMethod(OnDetach.class, "onDetach"));
    //onLowMemory
    fragmentDescriptor.addGenerators(buildEventMethod(OnLowMemory.class, "onLowMemory"));

    //onConfigurationChanged
    fragmentDescriptor.addGenerators(
            buildEventMethod(OnConfigurationChanged.class, "onConfigurationChanged", Configuration.class));

    if (fragmentType.extendsFrom(astClassFactory.getType(ListFragment.class))) {
        ASTMethod onListItemClickMethod = getASTMethod(ListActivity.class, "onListItemClick", ListView.class,
                View.class, Integer.TYPE, Long.TYPE);
        fragmentDescriptor.addGenerators(componentBuilderFactory.buildMethodCallbackGenerator(
                astClassFactory.getType(OnListItemClick.class),
                componentBuilderFactory.buildMirroredMethodGenerator(onListItemClickMethod, false)));
    }

    fragmentDescriptor.addGenerators(listenerRegistrationGenerator);

    fragmentDescriptor.addRegistration(observesExpressionDecorator);

}