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:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java

@Test
public void testBinaryNumericOperators() throws JaxenException {
    ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class);
    List<ASTExpression> expressions = convertList(acu.findChildNodesWithXPath(
            "//Block[preceding-sibling::MethodDeclarator[@Image = 'binaryNumericOperators']]//Expression"),
            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(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());

    // Make sure we got them all.
    assertEquals("All expressions not tested", index, expressions.size());
}

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

/**
 * Returns a new value that is not equal to oldVal. The
 * returned object will be a new instance compatible with oldVal.  
 * /*from  w  ww .  j a  v a 2  s  .  c o m*/
 * @param property The property that should be modified.
 * @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.
 */
private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == String.class) {
        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() == Double.class || property.getPropertyType() == Double.TYPE) {
        if (oldVal == null) {
            newVal = new Double(0);
        } else {
            newVal = new Double(((Double) oldVal).doubleValue() + 1);
        }
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        if (oldVal == null) {
            newVal = new Integer(0);
        } else {
            newVal = new Integer(((Integer) oldVal).intValue() + 1);
        }
    } 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() == Font.class) {
        if (oldVal == null) {
            newVal = FontManager.getDefaultPhysicalFont();
        } else {
            Font oldFont = (Font) oldVal;
            newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle());
        }
    } else if (property.getPropertyType() == Set.class) {
        newVal = new HashSet();
        ((Set) newVal).add("test");
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
        ((List) newVal).add("test");
    } else if (property.getPropertyType() == Point.class) {
        newVal = new Point(1, 3);
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in getNewDifferentValue()");
    }

    return newVal;
}

From source file:org.jivesoftware.smack.XMPPConnection.java

private void initReaderAndWriter() throws XMPPException {
    try {/* w ww  .java2s  .c o m*/
        if (!usingCompression) {
            reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
            writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
        } else {
            try {
                Class<?> zoClass = Class.forName("com.jcraft.jzlib.ZOutputStream");
                Constructor<?> constructor = zoClass.getConstructor(OutputStream.class, Integer.TYPE);
                Object out = constructor.newInstance(socket.getOutputStream(), 9);
                Method method = zoClass.getMethod("setFlushMode", Integer.TYPE);
                method.invoke(out, 2);
                writer = new BufferedWriter(new OutputStreamWriter((OutputStream) out, "UTF-8"));

                Class<?> ziClass = Class.forName("com.jcraft.jzlib.ZInputStream");
                constructor = ziClass.getConstructor(InputStream.class);
                Object in = constructor.newInstance(socket.getInputStream());
                method = ziClass.getMethod("setFlushMode", Integer.TYPE);
                method.invoke(in, 2);
                reader = new BufferedReader(new InputStreamReader((InputStream) in, "UTF-8"));
            } catch (Exception e) {
                e.printStackTrace();
                reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
                writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
            }
        }
    } catch (IOException ioe) {
        throw new XMPPException("XMPPError establishing connection with server.",
                new XMPPError(XMPPError.Condition.remote_server_error,
                        "XMPPError establishing connection with server."),
                ioe);
    }

    // If debugging is enabled, we open a window and write out all network traffic.
    initDebugger();
}

From source file:nl.strohalm.cyclos.controls.groups.EditGroupAction.java

private void initMember(final BeanBinder<? extends MemberGroup> memberGroupBinder,
        final BeanBinder<? extends MemberGroupSettings> memberSettingsBinder) {
    memberGroupBinder.registerBinder("memberSettings", memberSettingsBinder);
    memberGroupBinder.registerBinder("active", PropertyBinder.instance(Boolean.TYPE, "active"));
    memberGroupBinder.registerBinder("initialGroup", PropertyBinder.instance(Boolean.TYPE, "initialGroup"));
    memberGroupBinder.registerBinder("initialGroupShow",
            PropertyBinder.instance(String.class, "initialGroupShow"));
    memberGroupBinder.registerBinder("registrationAgreement",
            PropertyBinder.instance(RegistrationAgreement.class, "registrationAgreement"));
    memberGroupBinder.registerBinder("defaultMailMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "defaultMailMessages"));
    memberGroupBinder.registerBinder("smsMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "smsMessages"));
    memberGroupBinder.registerBinder("defaultSmsMessages",
            SimpleCollectionBinder.instance(Message.Type.class, "defaultSmsMessages"));
    memberGroupBinder.registerBinder("defaultAllowChargingSms",
            PropertyBinder.instance(Boolean.TYPE, "defaultAllowChargingSms"));
    memberGroupBinder.registerBinder("defaultAcceptFreeMailing",
            PropertyBinder.instance(Boolean.TYPE, "defaultAcceptFreeMailing"));
    memberGroupBinder.registerBinder("defaultAcceptPaidMailing",
            PropertyBinder.instance(Boolean.TYPE, "defaultAcceptPaidMailing"));
    memberGroupBinder.registerBinder("channels", SimpleCollectionBinder.instance(Channel.class, "channels"));
    memberGroupBinder.registerBinder("defaultChannels",
            SimpleCollectionBinder.instance(Channel.class, "defaultChannels"));
    memberGroupBinder.registerBinder("cardType", PropertyBinder.instance(CardType.class, "cardType"));

    final LocalSettings localSettings = settingsService.getLocalSettings();
    memberSettingsBinder.registerBinder("pinLength", DataBinderHelper.rangeConstraintBinder("pinLength"));
    memberSettingsBinder.registerBinder("maxPinWrongTries",
            PropertyBinder.instance(Integer.TYPE, "maxPinWrongTries"));
    memberSettingsBinder.registerBinder("pinBlockTimeAfterMaxTries",
            DataBinderHelper.timePeriodBinder("pinBlockTimeAfterMaxTries"));
    memberSettingsBinder.registerBinder("pinLength", DataBinderHelper.rangeConstraintBinder("pinLength"));
    memberSettingsBinder.registerBinder("smsChargeTransferType",
            PropertyBinder.instance(TransferType.class, "smsChargeTransferType"));
    memberSettingsBinder.registerBinder("smsChargeAmount",
            PropertyBinder.instance(BigDecimal.class, "smsChargeAmount", localSettings.getNumberConverter()));
    memberSettingsBinder.registerBinder("smsFree", PropertyBinder.instance(Integer.TYPE, "smsFree"));
    memberSettingsBinder.registerBinder("smsShowFreeThreshold",
            PropertyBinder.instance(Integer.TYPE, "smsShowFreeThreshold"));
    memberSettingsBinder.registerBinder("smsAdditionalCharged",
            PropertyBinder.instance(Integer.TYPE, "smsAdditionalCharged"));
    memberSettingsBinder.registerBinder("smsAdditionalChargedPeriod",
            DataBinderHelper.timePeriodBinder("smsAdditionalChargedPeriod"));
    memberSettingsBinder.registerBinder("smsContextClassName",
            PropertyBinder.instance(String.class, "smsContextClassName"));

    memberSettingsBinder.registerBinder("maxAdsPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxAdsPerMember"));
    memberSettingsBinder.registerBinder("maxAdImagesPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxAdImagesPerMember"));
    memberSettingsBinder.registerBinder("defaultAdPublicationTime",
            DataBinderHelper.timePeriodBinder("defaultAdPublicationTime"));
    memberSettingsBinder.registerBinder("maxAdPublicationTime",
            DataBinderHelper.timePeriodBinder("maxAdPublicationTime"));
    memberSettingsBinder.registerBinder("enablePermanentAds",
            PropertyBinder.instance(Boolean.TYPE, "enablePermanentAds"));
    memberSettingsBinder.registerBinder("externalAdPublication",
            PropertyBinder.instance(MemberGroupSettings.ExternalAdPublication.class, "externalAdPublication"));
    memberSettingsBinder.registerBinder("maxAdDescriptionSize",
            PropertyBinder.instance(Integer.TYPE, "maxAdDescriptionSize"));
    memberSettingsBinder.registerBinder("sendPasswordByEmail",
            PropertyBinder.instance(Boolean.TYPE, "sendPasswordByEmail"));
    memberSettingsBinder.registerBinder("emailValidation",
            SimpleCollectionBinder.instance(EmailValidation.class, HashSet.class, "emailValidation"));
    memberSettingsBinder.registerBinder("maxImagesPerMember",
            PropertyBinder.instance(Integer.TYPE, "maxImagesPerMember"));
    memberSettingsBinder.registerBinder("viewLoansByGroup",
            PropertyBinder.instance(Boolean.TYPE, "viewLoansByGroup"));
    memberSettingsBinder.registerBinder("repayLoanByGroup",
            PropertyBinder.instance(Boolean.TYPE, "repayLoanByGroup"));
    memberSettingsBinder.registerBinder("maxSchedulingPayments",
            PropertyBinder.instance(Integer.TYPE, "maxSchedulingPayments"));
    memberSettingsBinder.registerBinder("maxSchedulingPeriod",
            DataBinderHelper.timePeriodBinder("maxSchedulingPeriod"));
    memberSettingsBinder.registerBinder("showPosWebPaymentDescription",
            PropertyBinder.instance(Boolean.TYPE, "showPosWebPaymentDescription"));
    memberSettingsBinder.registerBinder("expireMembersAfter",
            DataBinderHelper.timePeriodBinder("expireMembersAfter"));
    memberSettingsBinder.registerBinder("groupAfterExpiration",
            PropertyBinder.instance(MemberGroup.class, "groupAfterExpiration"));
}

From source file:org.eclipse.jubula.rc.swt.utils.SwtUtils.java

/**
 * Sends a message to the win32 window manager. This method is only for
 * win32./*from  w ww.  j  a v  a2s .co  m*/
 * 
 * @param hWnd      The handle of the component to send the message to.
 * @param msg       The message to send.
 * @param wParam    wParam
 * @param lParam    lParam
 * 
 * @return  the response to the message.
 */
static int sendMessage(int hWnd, int msg, int wParam, int[] lParam) throws Exception {

    int result = 0;
    String methodName = "SendMessage"; //$NON-NLS-1$
    String className = "org.eclipse.swt.internal.win32.OS"; //$NON-NLS-1$

    Class clazz = Class.forName(className);
    Class[] params = new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, lParam.getClass(), };
    Method method = clazz.getMethod(methodName, params);
    Object[] args = new Object[] { new Integer(hWnd), new Integer(msg), new Integer(wParam), lParam, };
    result = ((Integer) method.invoke(clazz, args)).intValue();

    return result;
}

From source file:javadz.beanutils.LazyDynaBean.java

/**
 * Create a new Instance of a 'Primitive' Property.
 * @param name The name of the property/*  w  w w.  j  a v a  2  s  .co  m*/
 * @param type The class of the property
 * @return The new value
 */
protected Object createPrimitiveProperty(String name, Class type) {

    if (type == Boolean.TYPE) {
        return Boolean.FALSE;
    } else if (type == Integer.TYPE) {
        return Integer_ZERO;
    } else if (type == Long.TYPE) {
        return Long_ZERO;
    } else if (type == Double.TYPE) {
        return Double_ZERO;
    } else if (type == Float.TYPE) {
        return Float_ZERO;
    } else if (type == Byte.TYPE) {
        return Byte_ZERO;
    } else if (type == Short.TYPE) {
        return Short_ZERO;
    } else if (type == Character.TYPE) {
        return Character_SPACE;
    } else {
        return null;
    }

}

From source file:com.aliyun.fs.oss.utils.OSSClientAgent.java

@SuppressWarnings("unchecked")
private UploadPartCopyResult uploadPartCopy(String uploadId, String srcBucket, String dstBucket, String srcKey,
        String dstKey, Long partSize, Long beginIndex, int partNumber, Configuration conf, boolean retry)
        throws IOException, ServiceException, ClientException {
    try {//  w  w w.ja  va2s  .  c om
        Class UploadPartCopyRequestClz = ResourceLoader.getInstance().getUrlClassLoader(conf)
                .loadClass("com.aliyun.oss.model.UploadPartCopyRequest");
        Constructor cons = UploadPartCopyRequestClz.getConstructor(String.class, String.class, String.class,
                String.class);
        Object uploadPartCopyRequest = cons.newInstance(srcBucket, srcKey, dstBucket, dstKey);
        Method method0 = UploadPartCopyRequestClz.getMethod("setBeginIndex", Long.class);
        method0.invoke(uploadPartCopyRequest, beginIndex);
        Method method1 = UploadPartCopyRequestClz.getMethod("setUploadId", String.class);
        method1.invoke(uploadPartCopyRequest, uploadId);
        Method method2 = UploadPartCopyRequestClz.getMethod("setPartSize", Long.class);
        method2.invoke(uploadPartCopyRequest, partSize);
        Method method3 = UploadPartCopyRequestClz.getMethod("setPartNumber", Integer.TYPE);
        method3.invoke(uploadPartCopyRequest, partNumber);

        Method method = this.ossClientClz.getMethod("uploadPartCopy", UploadPartCopyRequestClz);
        Object ret = method.invoke(this.ossClient, uploadPartCopyRequest);
        return gson.fromJson(gson.toJson(ret), UploadPartCopyResult.class);
    } catch (Exception e) {
        if (retry && updateOSSClient(e)) {
            return uploadPartCopy(uploadId, srcBucket, dstBucket, srcKey, dstKey, partSize, beginIndex,
                    partNumber, conf, false);
        } else {
            handleException(e);
            return null;
        }
    }
}

From source file:objenome.util.ClassUtils.java

/**
 * <p>Checks if one {@code Class} can be assigned to a variable of
 * another {@code Class}.</p>//from  w w w  .  j  av a2  s.  c o m
 *
 * <p>Unlike the {@link Class#isAssignableFrom(Class)} method,
 * this method takes into account widenings of primitive classes and
 * {@code null}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} may be assigned to any reference type. This method
 * will return {@code true} if {@code null} is passed in and the
 * toClass is non-primitive.</p>
 *
 * <p>Specifically, this method tests whether the type represented by the
 * specified {@code Class} parameter can be converted to the type
 * represented by this {@code Class} object via an identity conversion
 * widening primitive or widening reference conversion. See
 * <em><a href="http://docs.oracle.com/javase/specs/">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} if assignment possible
 */
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()) {
            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.TestPlayPen.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  .jav a2s  .  c  om
  * @param property The property that should be checked for mutability.
  */
private boolean isPropertyInstanceMutable(PropertyDescriptor property) {
    if (property.getPropertyType() == String.class) {
        return false;
    } else if (Enum.class.isAssignableFrom(property.getPropertyType())) {
        return false;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        return false;
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        return false;
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        return false;
    } else if (property.getPropertyType() == Color.class) {
        return false;
    } else if (property.getPropertyType() == Font.class) {
        return false;
    } else if (property.getPropertyType() == Set.class) {
        return true;
    } else if (property.getPropertyType() == List.class) {
        return true;
    } else if (property.getPropertyType() == Point.class) {
        return true;
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in isPropertyInstanceMutable()");
    }
}

From source file:com.sun.faces.config.ManagedBeanFactory.java

private Class getValueClassConsideringPrimitives(String valueClass) throws ClassNotFoundException {
    Class valueType = java.lang.String.class;
    if (null != valueClass && 0 < valueClass.length()) {
        if (valueClass.equals(Boolean.TYPE.getName())) {
            valueType = Boolean.TYPE;
        } else if (valueClass.equals(Byte.TYPE.getName())) {
            valueType = Byte.TYPE;
        } else if (valueClass.equals(Double.TYPE.getName())) {
            valueType = Double.TYPE;
        } else if (valueClass.equals(Float.TYPE.getName())) {
            valueType = Float.TYPE;
        } else if (valueClass.equals(Integer.TYPE.getName())) {
            valueType = Integer.TYPE;
        } else if (valueClass.equals(Character.TYPE.getName())) {
            valueType = Character.TYPE;
        } else if (valueClass.equals(Short.TYPE.getName())) {
            valueType = Short.TYPE;
        } else if (valueClass.equals(Long.TYPE.getName())) {
            valueType = Long.TYPE;
        } else {/*from  ww w .  j  a  v a  2  s  .  co m*/
            valueType = Util.loadClass(valueClass, this);
        }
    }
    return valueType;
}