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:Main.java

public static void setGL16Mode() {
    System.err.println("Orion::setGL16Mode");
    try {/*from  w w w  .  j a  v  a 2s  . c  o m*/
        if (successful) {
            Constructor RegionParamsConstructor = epdControllerRegionParamsClass.getConstructor(new Class[] {
                    Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, epdControllerWaveClass });

            Object localRegionParams = RegionParamsConstructor
                    .newInstance(new Object[] { 0, 0, 600, 800, waveEnums[1] }); // Wave = GU

            Method epdControllerSetRegionMethod = epdControllerClass.getMethod("setRegion",
                    new Class[] { String.class, epdControllerRegionClass, epdControllerRegionParamsClass,
                            epdControllerModeClass });
            epdControllerSetRegionMethod.invoke(null,
                    new Object[] { "Orion", regionEnums[2], localRegionParams, modeEnums[2] }); // Mode = ONESHOT_ALL
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static String getColumnType(Class<?> fieldType) {
    if (String.class == fieldType) {
        return "TEXT";
    }//w ww .  j  a  v a  2  s.co  m
    if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
        return "INTEGER";
    }
    if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
        return "BIGINT";
    }
    if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
        return "FLOAT";
    }
    if ((Short.TYPE == fieldType) || (Short.class == fieldType)) {
        return "INT";
    }
    if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
        return "DOUBLE";
    }
    if (Blob.class == fieldType) {
        return "BLOB";
    }

    return "TEXT";
}

From source file:Main.java

public static boolean hasPermission(Context appContext, String appOpsServiceId) throws UnknownError {

    ApplicationInfo appInfo = appContext.getApplicationInfo();

    String pkg = appContext.getPackageName();
    int uid = appInfo.uid;
    Class appOpsClass = null;//from   w w  w  .j  a  v  a  2 s.  c  o  m
    Object appOps = appContext.getSystemService("appops");

    try {

        appOpsClass = Class.forName("android.app.AppOpsManager");

        Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE,
                String.class);

        Field opValue = appOpsClass.getDeclaredField(appOpsServiceId);

        int value = (int) opValue.getInt(Integer.class);
        Object result = checkOpNoThrowMethod.invoke(appOps, value, uid, pkg);

        return Integer.parseInt(result.toString()) == 0; // AppOpsManager.MODE_ALLOWED

    } catch (ClassNotFoundException e) {
        throw new UnknownError("class not found");
    } catch (NoSuchMethodException e) {
        throw new UnknownError("no such method");
    } catch (NoSuchFieldException e) {
        throw new UnknownError("no such field");
    } catch (InvocationTargetException e) {
        throw new UnknownError("invocation target");
    } catch (IllegalAccessException e) {
        throw new UnknownError("illegal access");
    }

}

From source file:Main.java

public static ContentValues objectToContentValues(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("please check your argument");
    }/*from w w w.ja  v  a2  s.c o m*/
    ContentValues contentValues = new ContentValues();
    try {
        Field[] fields = object.getClass().getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            Type type = field.getType();
            field.setAccessible(true);
            if (type.equals(String.class)) {
                contentValues.put(fieldName, field.get(object).toString());
            } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
                contentValues.put(fieldName, field.getInt(object));
            } else if (type.equals(Float.class) || type.equals(Float.TYPE)) {
                contentValues.put(fieldName, field.getFloat(object));
            } else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
                contentValues.put(fieldName, field.getLong(object));
            } else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
                contentValues.put(fieldName, field.getDouble(object));
            } else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
                contentValues.put(fieldName, field.getBoolean(object));
            }
        }
    } catch (IllegalAccessException | IllegalArgumentException e) {
        e.printStackTrace();
    }
    return contentValues;
}

From source file:Platform.java

/**
 * Unmaximizes the specified Frame.//w  w w.ja  v a2s.com
 */
public static void unmaximize(Frame f) {
    if (!isJRE13) {
        try {
            Method m1 = Frame.class.getMethod("getExtendedState", (Class[]) null);
            Method m2 = Frame.class.getMethod("setExtendedState", new Class[] { Integer.TYPE });
            int i = ((Integer) m1.invoke(f, (Object[]) null)).intValue();
            m2.invoke(f, new Object[] { new Integer(i & ~6) });
        } catch (java.lang.reflect.InvocationTargetException ite) {
        } catch (NoSuchMethodException nsme) {
        } catch (IllegalAccessException iae) {
        }
    }
}

From source file:Main.java

private static boolean isWideningPrimitiveNumberConversion(final Class source, final Class target) {
    if (target == Short.TYPE && (source == Byte.TYPE)) {
        return true;
    } else if (target == Integer.TYPE && (source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Long.TYPE && (source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Float.TYPE
            && (source == Long.TYPE || source == Integer.TYPE || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else if (target == Double.TYPE && (source == Float.TYPE || source == Long.TYPE || source == Integer.TYPE
            || source == Short.TYPE || source == Byte.TYPE)) {
        return true;
    } else {//  w ww .  j av a 2s.  c o  m
        return false;
    }
}

From source file:PrimitiveUtils.java

public static Object read(String value, Class type) {
    Object ret = value;/* ww  w  . j  a va2s  .com*/
    if (Integer.TYPE.equals(type)) {
        ret = Integer.valueOf(value);
    }
    if (Byte.TYPE.equals(type)) {
        ret = Byte.valueOf(value);
    }
    if (Short.TYPE.equals(type)) {
        ret = Short.valueOf(value);
    }
    if (Long.TYPE.equals(type)) {
        ret = Long.valueOf(value);
    }
    if (Float.TYPE.equals(type)) {
        ret = Float.valueOf(value);
    }
    if (Double.TYPE.equals(type)) {
        ret = Double.valueOf(value);
    }
    if (Boolean.TYPE.equals(type)) {
        ret = Boolean.valueOf(value);
    }
    if (Character.TYPE.equals(type)) {
        ret = value.charAt(0);
    }
    // TODO others.
    return ret;
}

From source file:Main.java

public static Point positionToClickPoint(Container component, int caretPosition, Container invokedIn) {
    if (component == null) {
        return null;
    }/*  w ww  . ja  v a2 s .c  om*/

    //System.err.println("Checking: " + component.getClass().getName());
    if (component.getClass().getName().indexOf("EditorPane") >= 0) {
        try {
            java.lang.reflect.Method pointGetter = component.getClass().getMethod("modelToView",
                    new Class[] { Integer.TYPE });
            Rectangle rec = (Rectangle) pointGetter.invoke(component,
                    new Object[] { new Integer(caretPosition) });
            //System.err.println("Before: " + (int)rec.getY());
            // FIXME: somehow it fails here to convert point from scrollable component
            Point point = SwingUtilities.convertPoint(component, (int) rec.getX(), (int) rec.getY() + 10,
                    invokedIn);
            // FIXME: ugly hack :(
            if (point.getY() > 1024) {
                point = new Point((int) point.getX(), 250);
            }
            //System.err.println("After: " + (int)point.getY());
            return point;
        } catch (Exception e) {
            System.err.println("Method invocation exception caught");
            e.printStackTrace();

            //FIXME: BUG
            return null;
            //throw new RuntimeException("Method invocation exception caught");
        }
    }

    for (int i = 0; i < component.getComponentCount(); i++) {
        java.awt.Component childComponent = component.getComponent(i);
        if (childComponent instanceof javax.swing.JComponent) {
            Point point = positionToClickPoint((javax.swing.JComponent) childComponent, caretPosition,
                    invokedIn);
            if (point != null) {
                return point;
            }
        }
    }

    return null;
}

From source file:Main.java

public static void setNextFocusForwardId(final View view, final int nextFocusForwardId) {
    try {//from w  w w . j  av  a 2s .  c  o m
        final Method setNextFocusForwardId = TextView.class.getMethod("setNextFocusForwardId", Integer.TYPE);
        setNextFocusForwardId.invoke(view, nextFocusForwardId);
    } catch (final NoSuchMethodException x) {
        // expected on API levels below 11
    } catch (final Exception x) {
        throw new RuntimeException(x);
    }
}

From source file:Main.java

public static Drawable showUninstallAPKIcon(Context context, String apkPath) {
    String PATH_PackageParser = "android.content.pm.PackageParser";
    String PATH_AssetManager = "android.content.res.AssetManager";
    try {//from   ww w. j  a  v a 2 s .c  o m
        Class<?> pkgParserCls = Class.forName(PATH_PackageParser);
        Class<?>[] typeArgs = new Class[1];
        typeArgs[0] = String.class;
        Constructor<?> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
        Object[] valueArgs = new Object[1];
        valueArgs[0] = apkPath;
        Object pkgParser = pkgParserCt.newInstance(valueArgs);
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.setToDefaults();
        typeArgs = new Class[4];
        typeArgs[0] = File.class;
        typeArgs[1] = String.class;
        typeArgs[2] = DisplayMetrics.class;
        typeArgs[3] = Integer.TYPE;
        Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod("parsePackage", typeArgs);
        valueArgs = new Object[4];
        valueArgs[0] = new File(apkPath);
        valueArgs[1] = apkPath;
        valueArgs[2] = metrics;
        valueArgs[3] = 0;
        Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
        Field appInfoFld = pkgParserPkg.getClass().getDeclaredField("applicationInfo");
        ApplicationInfo info = (ApplicationInfo) appInfoFld.get(pkgParserPkg);
        Class<?> assetMagCls = Class.forName(PATH_AssetManager);
        Constructor<?> assetMagCt = assetMagCls.getConstructor((Class[]) null);
        Object assetMag = assetMagCt.newInstance((Object[]) null);
        typeArgs = new Class[1];
        typeArgs[0] = String.class;
        Method assetMag_addAssetPathMtd = assetMagCls.getDeclaredMethod("addAssetPath", typeArgs);
        valueArgs = new Object[1];
        valueArgs[0] = apkPath;
        assetMag_addAssetPathMtd.invoke(assetMag, valueArgs);
        Resources res = context.getResources();
        typeArgs = new Class[3];
        typeArgs[0] = assetMag.getClass();
        typeArgs[1] = res.getDisplayMetrics().getClass();
        typeArgs[2] = res.getConfiguration().getClass();
        Constructor<?> resCt = Resources.class.getConstructor(typeArgs);
        valueArgs = new Object[3];
        valueArgs[0] = assetMag;
        valueArgs[1] = res.getDisplayMetrics();
        valueArgs[2] = res.getConfiguration();
        res = (Resources) resCt.newInstance(valueArgs);
        if (info.icon != 0) {
            Drawable icon = res.getDrawable(info.icon);
            return icon;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}