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:com.googlecode.batchfb.impl.ErrorDetectingWrapper.java

/**
 * The basic graph error looks like this:
<pre>/*from  w  ww  .  j a va  2s  .c  om*/
{
error: {
 type: "OAuthException"
 message: "Error validating application."
}
}
</pre>
 */
protected void checkForStandardGraphError(JsonNode node) {
    JsonNode errorNode = node.get("error");
    if (errorNode != null) {
        // If we're missing type or message, it must be some other kind of error
        String type = errorNode.path("type").textValue();
        if (type == null)
            return;

        String msg = errorNode.path("message").textValue();
        if (msg == null)
            return;

        JsonNode codeNode = errorNode.get("code");
        Integer code = codeNode == null ? null : codeNode.intValue();

        JsonNode subcodeNode = errorNode.get("error_subcode");
        Integer subcode = subcodeNode == null ? null : subcodeNode.intValue();

        String userTitle = errorNode.path("error_user_title").textValue();
        String userMsg = errorNode.path("error_user_msg").textValue();

        if (code != null) {
            // Special case, migration exceptions are poorly structured
            if (code == 21)
                this.throwPageMigratedException(msg, code, subcode, userTitle, userMsg);

            // Documented here: https://developers.facebook.com/docs/graph-api/using-graph-api
            if (code == 10 || (code >= 200 && code <= 299))
                throw new PermissionException(msg, type, code, subcode, userTitle, userMsg);
        }

        // We check to see if we have an exception that matches the type, otherwise
        // we simply throw the base FacebookException
        String proposedExceptionType = Batcher.class.getPackage().getName() + ".err." + type;

        try {
            Class<?> exceptionClass = Class.forName(proposedExceptionType);
            Constructor<?> ctor = exceptionClass.getConstructor(String.class, String.class, Integer.TYPE,
                    Integer.TYPE);
            throw (FacebookException) ctor.newInstance(msg, type, code, subcode);
        } catch (FacebookException e) {
            throw e;
        } catch (Exception e) {
            throw new ErrorFacebookException(type + ": " + msg, type, code, subcode, userTitle, userMsg);
        }
    }
}

From source file:net.sf.jrf.domain.PersistentObjectDynaProperty.java

/** Constructs instance and property name and class.
* @param name property name.//from ww w . j a  va 2s.c o  m
* @param cls value object <code>Class</code>.
* @param readMethodName name of the read <code>Method</code>
* @param writeMethodName name of the write <code>Method</code>
*/
public PersistentObjectDynaProperty(String name, Class cls, String readMethodName, String writeMethodName) {
    super(name, cls);
    this.readMethodName = readMethodName;
    this.writeMethodName = writeMethodName;
    if (cls.isPrimitive()) {
        if (cls.equals(Boolean.TYPE))
            primitiveWrapperClass = Boolean.class;
        else if (cls.equals(Byte.TYPE))
            primitiveWrapperClass = Byte.class;
        else if (cls.equals(Character.TYPE))
            primitiveWrapperClass = Character.class;
        else if (cls.equals(Double.TYPE))
            primitiveWrapperClass = Double.class;
        else if (cls.equals(Float.TYPE))
            primitiveWrapperClass = Float.class;
        else if (cls.equals(Integer.TYPE))
            primitiveWrapperClass = Integer.class;
        else if (cls.equals(Long.TYPE))
            primitiveWrapperClass = Long.class;
        else if (cls.equals(Short.TYPE))
            primitiveWrapperClass = Short.class;

    } else if (java.util.List.class.isAssignableFrom(cls) || cls.isArray()) {
        indexed = true;
    } else if (java.util.Map.class.isAssignableFrom(cls)) {
        mapped = true;
    }
}

From source file:org.apache.jackrabbit.core.util.db.Oracle10R1ConnectionHelper.java

/**
 * Creates a temporary oracle.sql.BLOB instance via reflection and spools the contents of the specified
 * stream.//from w  ww .j  a  va  2s  .c o  m
 */
private Blob createTemporaryBlob(Connection con, InputStream in) throws Exception {
    /*
     * BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION);
     * blob.open(BLOB.MODE_READWRITE); OutputStream out = blob.getBinaryOutputStream(); ... out.flush();
     * out.close(); blob.close(); return blob;
     */
    Method createTemporary = blobClass.getMethod("createTemporary",
            new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE });
    Object blob = createTemporary.invoke(null,
            new Object[] { ConnectionFactory.unwrap(con), Boolean.FALSE, durationSessionConstant });
    Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE });
    open.invoke(blob, new Object[] { modeReadWriteConstant });
    Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
    OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob);
    try {
        IOUtils.copy(in, out);
    } finally {
        try {
            out.flush();
        } catch (IOException ioe) {
        }
        out.close();
    }
    Method close = blobClass.getMethod("close", new Class[0]);
    close.invoke(blob);
    return (Blob) blob;
}

From source file:com.netflix.governator.lifecycle.ConfigurationProcessor.java

private Supplier<?> getConfigurationSupplier(final Field field, final ConfigurationKey key, final Class<?> type,
        Supplier<?> current) {
    if (String.class.isAssignableFrom(type)) {
        return configurationProvider.getStringSupplier(key, (String) current.get());
    } else if (Boolean.class.isAssignableFrom(type) || Boolean.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getBooleanSupplier(key, (Boolean) current.get());
    } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getIntegerSupplier(key, (Integer) current.get());
    } else if (Long.class.isAssignableFrom(type) || Long.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getLongSupplier(key, (Long) current.get());
    } else if (Double.class.isAssignableFrom(type) || Double.TYPE.isAssignableFrom(type)) {
        return configurationProvider.getDoubleSupplier(key, (Double) current.get());
    } else if (Date.class.isAssignableFrom(type)) {
        return configurationProvider.getDateSupplier(key, (Date) current.get());
    } else {/*from  ww w.jav a2 s . c  o  m*/
        log.error("Field type not supported: " + type + " (" + field.getName() + ")");
        return null;
    }
}

From source file:nl.strohalm.cyclos.services.settings.LocalSettingsHandler.java

@Override
protected Map<String, Converter<?>> createConverters() {
    final Map<String, Converter<?>> localConverters = new LinkedHashMap<String, Converter<?>>();
    localConverters.put("applicationName", CoercionConverter.instance(String.class));
    localConverters.put("applicationUsername", CoercionConverter.instance(String.class));
    localConverters.put("rootUrl", CoercionConverter.instance(String.class));
    localConverters.put("language", CoercionConverter.instance(Language.class));
    localConverters.put("numberLocale", CoercionConverter.instance(NumberLocale.class));
    localConverters.put("precision", CoercionConverter.instance(Precision.class));
    localConverters.put("highPrecision", CoercionConverter.instance(Precision.class));
    localConverters.put("decimalInputMethod", CoercionConverter.instance(DecimalInputMethod.class));
    localConverters.put("datePattern", CoercionConverter.instance(DatePattern.class));
    localConverters.put("timePattern", CoercionConverter.instance(TimePattern.class));
    localConverters.put("timeZone", TimeZoneConverter.instance());
    localConverters.put("containerUrl", CoercionConverter.instance(String.class));
    localConverters.put("maxIteratorResults", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxPageResults", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxAjaxResults", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxUploadSize", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxUploadUnits", CoercionConverter.instance(FileUnits.class));
    localConverters.put("maxImageWidth", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxImageHeight", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxThumbnailWidth", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("maxThumbnailHeight", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("referenceLevels", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("smsEnabled", CoercionConverter.instance(Boolean.TYPE));
    localConverters.put("csvUseHeader", CoercionConverter.instance(Boolean.TYPE));
    localConverters.put("csvRecordSeparator", CoercionConverter.instance(CsvRecordSeparator.class));
    localConverters.put("csvValueSeparator", CoercionConverter.instance(CsvValueSeparator.class));
    localConverters.put("csvStringQuote", CoercionConverter.instance(CsvStringQuote.class));
    localConverters.put("cyclosId", CoercionConverter.instance(String.class));
    localConverters.put("sendSmsWebServiceUrl", CoercionConverter.instance(String.class));
    localConverters.put("smsChannelName", CoercionConverter.instance(String.class));
    localConverters.put("smsCustomFieldId", IdConverter.instance());
    localConverters.put("transactionNumber.prefix", CoercionConverter.instance(String.class));
    localConverters.put("transactionNumber.padLength", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("transactionNumber.suffix", CoercionConverter.instance(String.class));
    localConverters.put("emailRequired", CoercionConverter.instance(Boolean.TYPE));
    localConverters.put("emailUnique", CoercionConverter.instance(Boolean.TYPE));
    localConverters.put("brokeringExpirationPeriod.number", CoercionConverter.instance(Integer.class));
    localConverters.put("brokeringExpirationPeriod.field", CoercionConverter.instance(Field.class));
    localConverters.put("deleteMessagesOnTrashAfter.number", CoercionConverter.instance(Integer.class));
    localConverters.put("deleteMessagesOnTrashAfter.field", CoercionConverter.instance(Field.class));
    localConverters.put("deletePendingRegistrationsAfter.number", CoercionConverter.instance(Integer.class));
    localConverters.put("deletePendingRegistrationsAfter.field", CoercionConverter.instance(Field.class));
    localConverters.put("memberSortOrder", CoercionConverter.instance(SortOrder.class));
    localConverters.put("memberResultDisplay", CoercionConverter.instance(MemberResultDisplay.class));
    localConverters.put("adDescriptionFormat", CoercionConverter.instance(TextFormat.class));
    localConverters.put("messageFormat", CoercionConverter.instance(TextFormat.class));
    localConverters.put("schedulingHour", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("schedulingMinute", CoercionConverter.instance(Integer.TYPE));
    localConverters.put("transferListenerClass", CoercionConverter.instance(String.class));
    localConverters.put("maxChargebackTime.number", CoercionConverter.instance(Integer.class));
    localConverters.put("maxChargebackTime.field", CoercionConverter.instance(Field.class));
    localConverters.put("chargebackDescription", CoercionConverter.instance(String.class));
    localConverters.put("showCountersInAdCategories", CoercionConverter.instance(Boolean.TYPE));
    return localConverters;
}

From source file:uk.ac.imperial.presage2.db.json.JsonStorage.java

private <T> T returnAsType(JsonNode n, Class<T> type) {
    if (type == String.class)
        return type.cast(n.textValue());
    else if (type == Integer.class || type == Integer.TYPE)
        return type.cast(n.asInt());
    else if (type == Double.class || type == Double.TYPE)
        return type.cast(n.asDouble());
    else if (type == Boolean.class || type == Boolean.TYPE)
        return type.cast(n.asBoolean());
    else if (type == Long.class || type == Long.TYPE)
        return type.cast(n.asLong());

    throw new RuntimeException("Unknown type cast request");
}

From source file:org.evosuite.regression.ObjectFields.java

private static Object getFieldValue(Field field, Object p) {
    try {/*w w w  .  j av  a2  s.  c o m*/
        /*Class objClass = p.getClass();
        if(p instanceof java.lang.String){
           ((String) p).hashCode();
        }*/
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (fieldType.isPrimitive()) {
            if (fieldType.equals(Boolean.TYPE)) {
                return field.getBoolean(p);
            }
            if (fieldType.equals(Integer.TYPE)) {
                return field.getInt(p);
            }
            if (fieldType.equals(Byte.TYPE)) {
                return field.getByte(p);
            }
            if (fieldType.equals(Short.TYPE)) {
                return field.getShort(p);
            }
            if (fieldType.equals(Long.TYPE)) {
                return field.getLong(p);
            }
            if (fieldType.equals(Double.TYPE)) {
                return field.getDouble(p);
            }
            if (fieldType.equals(Float.TYPE)) {
                return field.getFloat(p);
            }
            if (fieldType.equals(Character.TYPE)) {
                return field.getChar(p);
            }
            throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!");
        }
        return field.get(p);
    } catch (IllegalAccessException exc) {
        throw new RuntimeException(exc);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        if (MAX_RECURSION != 0)
            MAX_RECURSION = 0;
        else
            throw new RuntimeErrorException(e);
        return getFieldValue(field, p);
    }
}

From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java

public Object morph(Object value) {
    if (value != null && type.isAssignableFrom(value.getClass())) {
        // no conversion needed
        return value;
    }/*w  w w.j a  v a2 s. c  om*/

    String str = String.valueOf(value).trim();

    if (!type.isPrimitive() && (value == null || str.length() == 0 || "null".equalsIgnoreCase(str))) {
        // if empty string and class != primitive treat it like null
        return null;
    }

    try {
        if (isDecimalNumber(type)) {
            if (Float.class.isAssignableFrom(type) || Float.TYPE == type) {
                return morphToFloat(str);
            } else if (Double.class.isAssignableFrom(type) || Double.TYPE == type) {
                return morphToDouble(str);
            } else {
                return morphToBigDecimal(str);
            }
        } else {
            if (Byte.class.isAssignableFrom(type) || Byte.TYPE == type) {
                return morphToByte(str);
            } else if (Short.class.isAssignableFrom(type) || Short.TYPE == type) {
                return morphToShort(str);
            } else if (Integer.class.isAssignableFrom(type) || Integer.TYPE == type) {
                return morphToInteger(str);
            } else if (Long.class.isAssignableFrom(type) || Long.TYPE == type) {
                return morphToLong(str);
            } else {
                return morphToBigInteger(str);
            }
        }
    } catch (ConvertErrorException e) {
        // JsonPropertyConvertContext.setConvertError((ConvertErrorException) e);
        return null;
    }
}

From source file:org.acmsl.commons.utils.ConversionUtils.java

/**
 * Converts given String to int if given value is not null.
 * @param value the value to convert.//from  w w  w.ja v a  2 s .c  o  m
 * @return the converted value.
 */
@Nullable
public Integer toIntIfNotNull(@Nullable final String value) {
    Integer result = null;

    @Nullable
    final Converter t_Converter = ConvertUtils.lookup(Integer.TYPE);

    if (t_Converter != null) {
        @Nullable
        final Object t_Result = t_Converter.convert(Integer.TYPE, value);

        if (t_Result instanceof Integer) {
            result = (Integer) t_Result;
        }
    }

    return result;
}

From source file:org.atemsource.atem.impl.common.attribute.primitive.PrimitiveTypeFactory.java

@PostConstruct
public void initialize() {
    classes = new ArrayList<Class>();
    classes.add(String.class);
    classes.add(Boolean.class);
    classes.add(Boolean.TYPE);/*from  w  w w  . j  ava 2s  . c o  m*/
    classes.add(Long.class);
    classes.add(Long.TYPE);
    classes.add(Integer.class);
    classes.add(Integer.TYPE);
    classes.add(Float.class);
    classes.add(Float.TYPE);
    classes.add(Double.TYPE);
    classes.add(Double.class);
    classes.add(Character.TYPE);
    classes.add(Character.TYPE);
    classes.add(Character.class);
    classes.add(Byte.TYPE);
    classes.add(Byte.class);
    classes.add(Enum.class);
    classes.add(BigInteger.class);
    classes.add(BigDecimal.class);
    Collection<PrimitiveTypeRegistrar> registrars = beanLocator.getInstances(PrimitiveTypeRegistrar.class);
    for (PrimitiveTypeRegistrar registrar : registrars) {
        PrimitiveType<?>[] types = registrar.getTypes();
        for (PrimitiveType<?> primitiveType : types) {
            classToType.put(primitiveType.getJavaType(), primitiveType);
            classes.add(primitiveType.getJavaType());
        }
    }
}