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:androidx.core.app.NotificationManagerCompat.java

/**
 * Returns whether notifications from the calling package are not blocked.
 *//*  w  w  w .  j av  a  2 s  .  c om*/
public boolean areNotificationsEnabled() {
    if (Build.VERSION.SDK_INT >= 24) {
        return mNotificationManager.areNotificationsEnabled();
    } else if (Build.VERSION.SDK_INT >= 19) {
        AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        ApplicationInfo appInfo = mContext.getApplicationInfo();
        String pkg = mContext.getApplicationContext().getPackageName();
        int uid = appInfo.uid;
        try {
            Class<?> appOpsClass = Class.forName(AppOpsManager.class.getName());
            Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
                    String.class);
            Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
            int value = (int) opPostNotificationValue.get(Integer.class);
            return ((int) checkOpNoThrowMethod.invoke(appOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
        } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException
                | InvocationTargetException | IllegalAccessException | RuntimeException e) {
            return true;
        }
    } else {
        return true;
    }
}

From source file:org.apache.struts.action.TestDynaActionForm.java

/**
 * Positive getDynaProperty on property <code>intProperty</code>.
 *///from w  w  w  .  ja  v a  2  s  .c om
public void testGetDescriptorInt() {
    testGetDescriptorBase("intProperty", Integer.TYPE);
}

From source file:com.ryan.ryanreader.jsonwrap.JsonBufferedObject.java

public void populateObject(final Object o) throws InterruptedException, IOException, IllegalArgumentException,
        InstantiationException, NoSuchMethodException, InvocationTargetException {

    if (join() != Status.LOADED) {
        throwFailReasonException();/*from   w w w.  j  a va  2  s  . co m*/
    }

    final Field[] objectFields = o.getClass().getFields();

    try {

        for (final Field objectField : objectFields) {

            if ((objectField.getModifiers() & Modifier.TRANSIENT) != 0) {
                continue;
            }

            final JsonValue val;

            if (properties.containsKey(objectField.getName())) {
                val = properties.get(objectField.getName());

            } else if (objectField.getName().startsWith("_json_")) {
                val = properties.get(objectField.getName().substring("_json_".length()));
            } else {
                val = null;
            }

            if (val == null) {
                continue;
            }

            objectField.setAccessible(true);

            final Class<?> fieldType = objectField.getType();

            if (fieldType == Long.class || fieldType == Long.TYPE) {
                objectField.set(o, val.asLong());

            } else if (fieldType == Double.class || fieldType == Double.TYPE) {
                objectField.set(o, val.asDouble());

            } else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asLong().intValue());

            } else if (fieldType == Float.class || fieldType == Float.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asDouble().floatValue());

            } else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
                objectField.set(o, val.asBoolean());

            } else if (fieldType == String.class) {
                objectField.set(o, val.asString());

            } else if (fieldType == JsonBufferedArray.class) {
                objectField.set(o, val.asArray());

            } else if (fieldType == JsonBufferedObject.class) {
                objectField.set(o, val.asObject());

            } else if (fieldType == JsonValue.class) {
                objectField.set(o, val);

            } else if (fieldType == Object.class) {

                final Object result;

                switch (val.getType()) {
                case BOOLEAN:
                    result = val.asBoolean();
                    break;
                case INTEGER:
                    result = val.asLong();
                    break;
                case STRING:
                    result = val.asString();
                    break;
                case FLOAT:
                    result = val.asDouble();
                    break;
                default:
                    result = val;
                }

                objectField.set(o, result);

            } else {
                objectField.set(o, val.asObject(fieldType));
            }
        }

    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.netspective.commons.lang.ValueBeanGeneratorClassLoader.java

/**
 * Convert runtime java.lang.Class to BCEL Type object.
 *
 * @param cl Java class/*from   www  .  ja v  a2 s .  co  m*/
 *
 * @return corresponding Type object
 */
public static Type getBCELType(java.lang.Class cl) {
    if (cl == null) {
        throw new IllegalArgumentException("Class must not be null");
    }

    /* That's an amzingly easy case, because getName() returns
     * the signature. That's what we would have liked anyway.
     */
    if (cl.isArray()) {
        return Type.getType(cl.getName());
    } else if (cl.isPrimitive()) {
        if (cl == Integer.TYPE) {
            return Type.INT;
        } else if (cl == Void.TYPE) {
            return Type.VOID;
        } else if (cl == Double.TYPE) {
            return Type.DOUBLE;
        } else if (cl == Float.TYPE) {
            return Type.FLOAT;
        } else if (cl == Boolean.TYPE) {
            return Type.BOOLEAN;
        } else if (cl == Byte.TYPE) {
            return Type.BYTE;
        } else if (cl == Short.TYPE) {
            return Type.SHORT;
        } else if (cl == Long.TYPE) {
            return Type.LONG;
        } else if (cl == Character.TYPE) {
            return Type.CHAR;
        } else {
            throw new IllegalStateException("Ooops, what primitive type is " + cl);
        }
    } else { // "Real" class
        return new ObjectType(cl.getName());
    }
}

From source file:org.apache.struts.action.DynaActionForm.java

/**
 * <p>Return the value of a simple property with the specified name.</p>
 *
 * @param name Name of the property whose value is to be retrieved
 * @return The value of a simple property with the specified name.
 * @throws IllegalArgumentException if there is no property of the
 *                                  specified name
 * @throws NullPointerException     if the type specified for the property
 *                                  is invalid
 *///from ww w  .  ja  v a  2  s  .co m
public Object get(String name) {
    // Return any non-null value for the specified property
    Object value = dynaValues.get(name);

    if (value != null) {
        return (value);
    }

    // Return a null value for a non-primitive property
    Class type = getDynaProperty(name).getType();

    if (type == null) {
        throw new NullPointerException("The type for property " + name + " is invalid");
    }

    if (!type.isPrimitive()) {
        return (value);
    }

    // Manufacture default values for primitive properties
    if (type == Boolean.TYPE) {
        return (Boolean.FALSE);
    } else if (type == Byte.TYPE) {
        return (new Byte((byte) 0));
    } else if (type == Character.TYPE) {
        return (new Character((char) 0));
    } else if (type == Double.TYPE) {
        return (new Double(0.0));
    } else if (type == Float.TYPE) {
        return (new Float((float) 0.0));
    } else if (type == Integer.TYPE) {
        return (new Integer(0));
    } else if (type == Long.TYPE) {
        return (new Long(0));
    } else if (type == Short.TYPE) {
        return (new Short((short) 0));
    } else {
        return (null);
    }
}

From source file:com.adobe.acs.commons.data.Variant.java

@SuppressWarnings("squid:S3776")
public <T> T asType(Class<T> type) {
    if (type == Byte.TYPE || type == Byte.class) {
        return (T) apply(toLong(), Long::byteValue);
    } else if (type == Integer.TYPE || type == Integer.class) {
        return (T) apply(toLong(), Long::intValue);
    } else if (type == Long.TYPE || type == Long.class) {
        return (T) toLong();
    } else if (type == Short.TYPE || type == Short.class) {
        return (T) apply(toLong(), Long::shortValue);
    } else if (type == Float.TYPE || type == Float.class) {
        return (T) apply(toDouble(), Double::floatValue);
    } else if (type == Double.TYPE || type == Double.class) {
        return (T) toDouble();
    } else if (type == Boolean.TYPE || type == Boolean.class) {
        return (T) toBoolean();
    } else if (type == String.class) {
        return (T) toString();
    } else if (type == Date.class) {
        return (T) toDate();
    } else if (type == Instant.class) {
        return (T) toDate().toInstant();
    } else if (type == Calendar.class) {
        Calendar c = Calendar.getInstance();
        c.setTime(toDate());/*from   w ww. j a va2s  .  c om*/
        return (T) c;
    } else {
        return null;
    }
}

From source file:com.google.feedserver.util.BeanCliHelper.java

/**
 * Loop through each registered class and create and parse command line
 * options for fields decorated with {@link Flag}.
 */// ww  w  . ja va  2  s .c o m
private void populateBeansFromCommandLine() {

    // Go through all registered beans.
    for (Object bean : beans) {

        // Search for all fields in the bean with Flag decorator.
        for (Field field : bean.getClass().getDeclaredFields()) {
            Flag flag = field.getAnnotation(Flag.class);
            if (flag == null) {
                // not decorated, continue.
                continue;
            }
            String argName = field.getName();
            // Boolean Flags
            if (field.getType().getName().equals(Boolean.class.getName())
                    || field.getType().getName().equals(Boolean.TYPE.getName())) {
                if (flags.hasOption(argName)) {
                    setField(field, bean, new Boolean(true));
                } else if (flags.hasOption("no" + argName)) {
                    setField(field, bean, new Boolean(false));
                }
                // Integer Flags
            } else if (field.getType().getName().equals(Integer.class.getName())
                    || field.getType().getName().equals(Integer.TYPE.getName())) {
                String argValue = flags.getOptionValue(argName, null);
                if (argValue != null) {
                    try {
                        setField(field, bean, Integer.valueOf(argValue));
                    } catch (NumberFormatException e) {
                        throw new RuntimeException(e);
                    }
                }
                // String Flag
            } else if (field.getType().getName().equals(String.class.getName())) {
                String argValue = flags.getOptionValue(argName, null);
                if (argValue != null) {
                    setField(field, bean, argValue);
                }
                // Repeated String Flag
            } else if (field.getType().getName().equals(String[].class.getName())) {
                String[] argValues = flags.getOptionValues(argName);
                if (argValues != null) {
                    setField(field, bean, argValues);
                }
            }
        }
    }
}

From source file:org.quantumbadger.redreader.jsonwrap.JsonBufferedObject.java

public void populateObject(final Object o) throws InterruptedException, IOException, IllegalArgumentException,
        InstantiationException, NoSuchMethodException, InvocationTargetException {

    if (join() != STATUS_LOADED) {
        throwFailReasonException();/*  ww  w . ja  v  a 2  s.  c o m*/
    }

    final Field[] objectFields = o.getClass().getFields();

    try {

        for (final Field objectField : objectFields) {

            if ((objectField.getModifiers() & Modifier.TRANSIENT) != 0) {
                continue;
            }

            final JsonValue val;

            if (properties.containsKey(objectField.getName())) {
                val = properties.get(objectField.getName());

            } else if (objectField.getName().startsWith("_json_")) {
                val = properties.get(objectField.getName().substring("_json_".length()));
            } else {
                val = null;
            }

            if (val == null) {
                continue;
            }

            objectField.setAccessible(true);

            final Class<?> fieldType = objectField.getType();

            if (fieldType == Long.class || fieldType == Long.TYPE) {
                objectField.set(o, val.asLong());

            } else if (fieldType == Double.class || fieldType == Double.TYPE) {
                objectField.set(o, val.asDouble());

            } else if (fieldType == Integer.class || fieldType == Integer.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asLong().intValue());

            } else if (fieldType == Float.class || fieldType == Float.TYPE) {
                objectField.set(o, val.isNull() ? null : val.asDouble().floatValue());

            } else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) {
                objectField.set(o, val.asBoolean());

            } else if (fieldType == String.class) {
                objectField.set(o, val.asString());

            } else if (fieldType == JsonBufferedArray.class) {
                objectField.set(o, val.asArray());

            } else if (fieldType == JsonBufferedObject.class) {
                objectField.set(o, val.asObject());

            } else if (fieldType == JsonValue.class) {
                objectField.set(o, val);

            } else if (fieldType == Object.class) {

                final Object result;

                switch (val.getType()) {
                case JsonValue.TYPE_BOOLEAN:
                    result = val.asBoolean();
                    break;
                case JsonValue.TYPE_INTEGER:
                    result = val.asLong();
                    break;
                case JsonValue.TYPE_STRING:
                    result = val.asString();
                    break;
                case JsonValue.TYPE_FLOAT:
                    result = val.asDouble();
                    break;
                default:
                    result = val;
                }

                objectField.set(o, result);

            } else {
                objectField.set(o, val.asObject(fieldType));
            }
        }

    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.enerj.apache.commons.collections.TestFactoryUtils.java

public void testInstantiateFactoryComplex() {
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    // 2nd Jan 1970
    Factory factory = FactoryUtils.instantiateFactory(Date.class,
            new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE },
            new Object[] { new Integer(70), new Integer(0), new Integer(2) });
    assertNotNull(factory);/*from www .j ava  2s .co  m*/
    Object created = factory.create();
    assertTrue(created instanceof Date);
    // long time of 1 day (== 2nd Jan 1970)
    assertEquals(new Date(1000 * 60 * 60 * 24), created);
}

From source file:org.eclim.installer.eclipse.Application.java

public Object run(String[] args) {
    // get eclipse information:
    //   - profile name
    //   - configuration location (user local dir for root installed eclipse)
    //   - least of installed features
    if ("-info".equals(args[0])) {
        System.out.println("  Profile: " + System.getProperty("eclipse.p2.profile"));
        System.out.println("  Configuration: " + System.getProperty("osgi.configuration.area"));
        IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
        for (IBundleGroupProvider provider : providers) {
            IBundleGroup[] groups = provider.getBundleGroups();
            for (IBundleGroup group : groups) {
                FeatureEntry feature = (FeatureEntry) group;
                System.out.println("  Feature: " + feature.getIdentifier() + ' ' + feature.getVersion() + ' '
                        + feature.getSite().getResolvedURL());
            }//from   w  w w. ja v a 2 s .  co  m
        }
        return IApplication.EXIT_OK;
    }

    // remove temp p2 repositories
    // FIXME: after removing the repositories the changes don't seem to be
    // committed. Either some event listener is registered or the application
    // exists before the changes can be committed. Need to find out how to wait
    // or force a synchronous saving of the changes. Also, the
    // getKnownRepositories seems to not return the uri of the current update
    // site, perhaps making this those block moot.
    /*if ("-removeRepos".equals(args[0])){
      // see
      //   org.eclipse.equinox.p2.ui.RepositoryManipulationPage
      //   org.eclipse.equinox.internal.p2.ui.model.ElementUtils
            
      ProvisioningUI ui = ProvisioningUI.getDefaultUI();
      ui.signalRepositoryOperationStart();
      IMetadataRepositoryManager metaManager =
        ProvUI.getMetadataRepositoryManager(ui.getSession());
      IArtifactRepositoryManager artManager =
        ProvUI.getArtifactRepositoryManager(ui.getSession());
      URI[] repos = metaManager.getKnownRepositories(
          IRepositoryManager.REPOSITORIES_ALL);
      for (URI repo : repos){
        if (repo.toString().indexOf("formic_") != -1){
          System.out.println("Remove repository: " + repo);
          metaManager.removeRepository(repo);
          artManager.removeRepository(repo);
        }
      }
      ui.signalRepositoryOperationComplete(null, true);
            
      return IApplication.EXIT_OK;
    }*/

    long time = System.currentTimeMillis();

    try {
        processArguments(args);
        // EV: pull some private vars in to local scope. must be after
        // processArguments
        boolean printHelpInfo = ((Boolean) this.getPrivateField("printHelpInfo")).booleanValue();
        boolean printIUList = ((Boolean) this.getPrivateField("printIUList")).booleanValue();
        boolean printRootIUList = ((Boolean) this.getPrivateField("printRootIUList")).booleanValue();
        boolean printTags = ((Boolean) this.getPrivateField("printTags")).booleanValue();
        boolean purgeRegistry = ((Boolean) this.getPrivateField("purgeRegistry")).booleanValue();

        if (printHelpInfo) {
            // EV: invoke private method
            //performHelpInfo();
            invokePrivate("performHelpInfo", new Class[0], new Object[0]);
        } else {
            // EV: invoke private methods
            //initializeServices();
            //initializeRepositories();
            invokePrivate("initializeServices", new Class[0], new Object[0]);
            invokePrivate("initializeRepositories", new Class[0], new Object[0]);

            // EV: pull more private vars in.
            String NOTHING_TO_REVERT_TO = (String) this.getPrivateField("NOTHING_TO_REVERT_TO");
            String revertToPreviousState = (String) this.getPrivateField("revertToPreviousState");
            List<IVersionedId> rootsToInstall = (List<IVersionedId>) this.getPrivateField("rootsToInstall");
            List<IVersionedId> rootsToUninstall = (List<IVersionedId>) this.getPrivateField("rootsToUninstall");

            if (revertToPreviousState != NOTHING_TO_REVERT_TO) {
                // EV: invoke private methods
                //revertToPreviousState();
                invokePrivate("revertToPreviousState", new Class[0], new Object[0]);
            } else if (!(rootsToInstall.isEmpty() && rootsToUninstall.isEmpty()))
                performProvisioningActions();
            if (printIUList)
                // EV: invoke private method
                //performList();
                invokePrivate("performList", new Class[0], new Object[0]);
            if (printRootIUList)
                // EV: invoke private method
                //performListInstalledRoots();
                invokePrivate("performListInstalledRoots", new Class[0], new Object[0]);
            if (printTags)
                // EV: invoke private method
                //performPrintTags();
                invokePrivate("performPrintTags", new Class[0], new Object[0]);
            if (purgeRegistry)
                // EV: invoke private method
                //purgeRegistry();
                invokePrivate("purgeRegistry", new Class[0], new Object[0]);

            System.out.println(
                    NLS.bind(Messages.Operation_complete, new Long(System.currentTimeMillis() - time)));
        }
        return IApplication.EXIT_OK;
    } catch (CoreException e) {
        try {
            // EV: invoke private methods
            //deeplyPrint(e.getStatus(), System.err, 0);
            //logFailure(e.getStatus());
            invokePrivate("deeplyPrint", new Class[] { IStatus.class, PrintStream.class, Integer.TYPE },
                    new Object[] { e.getStatus(), System.err, 0 });
            invokePrivate("logFailure", new Class[] { IStatus.class }, new Object[] { e.getStatus() });

            //set empty exit data to suppress error dialog from launcher
            // EV: invoke private methods
            //setSystemProperty("eclipse.exitdata", ""); //$NON-NLS-1$ //$NON-NLS-2$
            invokePrivate("setSystemProperty", new Class[] { String.class, String.class },
                    new Object[] { "eclipse.exitdata", "" });

            // EV: throw exception for the installer
            //return EXIT_ERROR;
            String workspace = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString();
            String log = workspace + "/.metadata/.log";
            throw new RuntimeException("Operation failed. See '" + log + "' for additional info.", e);
        } catch (Exception ex) {
            ex.printStackTrace();
            return EXIT_ERROR;
        }

        // EV: handle reflection exceptions
    } catch (Exception e) {
        e.printStackTrace();
        return EXIT_ERROR;
    } finally {
        try {
            // EV: pull private var in.
            ServiceReference packageAdminRef = (ServiceReference) this.getPrivateField("packageAdminRef");
            if (packageAdminRef != null) {
                // EV: invoke private methods.
                //cleanupRepositories();
                //cleanupServices();
                invokePrivate("cleanupRepositories", new Class[0], new Object[0]);
                invokePrivate("cleanupServices", new Class[0], new Object[0]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}