List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:Main.java
/** * Determines whether notifications are enabled for the app represented by |context|. * Notifications may be disabled because either the user, or a management tool, has explicitly * disallowed the Chrome App to display notifications. * * This check requires Android KitKat or later. Earlier versions will return an INDETERMINABLE * status. When an exception occurs, an EXCEPTION status will be returned instead. * * @param context The context to check of whether it can show notifications. * @return One of the APP_NOTIFICATION_STATUS_* constants defined in this class. *//* w w w. ja va 2s. c o m*/ @TargetApi(Build.VERSION_CODES.KITKAT) static int determineAppNotificationStatus(Context context) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return APP_NOTIFICATIONS_STATUS_UNDETERMINABLE; } final String packageName = context.getPackageName(); final int uid = context.getApplicationInfo().uid; final AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { Class appOpsManagerClass = Class.forName(AppOpsManager.class.getName()); @SuppressWarnings("unchecked") final Method checkOpNoThrowMethod = appOpsManagerClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class); final Field opPostNotificationField = appOpsManagerClass.getDeclaredField(OP_POST_NOTIFICATION); int value = (int) opPostNotificationField.get(Integer.class); int status = (int) checkOpNoThrowMethod.invoke(appOpsManager, value, uid, packageName); return status == AppOpsManager.MODE_ALLOWED ? APP_NOTIFICATIONS_STATUS_ENABLED : APP_NOTIFICATIONS_STATUS_DISABLED; } catch (RuntimeException e) { } catch (Exception e) { // Silently fail here, since this is just collecting statistics. The histogram includes // a count for thrown exceptions, if that proves to be significant we can revisit. } return APP_NOTIFICATIONS_STATUS_EXCEPTION; }
From source file:com.bedatadriven.rebar.persistence.mapping.PrimitiveMapping.java
public PrimitiveMapping(MethodInfo getter) { super(getter); TypeInfo type = getter.getReturnType(); Class primitive = type.isPrimitive(); this.boxed = (primitive == null); if (primitive != null) { this.nullable = false; }/*from w w w . ja v a2 s. c o m*/ if (primitive == Integer.TYPE || type.getQualifiedName().equals(Integer.class.getName()) || primitive == Short.TYPE || type.getQualifiedName().equals(Short.class.getName()) || primitive == Long.TYPE || type.getQualifiedName().equals(Long.class.getName()) || primitive == Byte.TYPE || type.getQualifiedName().equals(Byte.class.getName()) || primitive == Boolean.TYPE || type.getQualifiedName().equals(Boolean.class.getName())) { sqlTypeName = SqliteTypes.integer; } else if (primitive == Float.TYPE || type.getQualifiedName().equals(Float.class.getName()) || primitive == Double.TYPE || type.getQualifiedName().equals(Double.class.getName())) { sqlTypeName = SqliteTypes.real; } else if (primitive == Character.TYPE || type.getQualifiedName().equals(Character.class.getName())) { sqlTypeName = SqliteTypes.text; } String suffix = type.getSimpleName(); if (suffix.equals("Integer")) { suffix = "Int"; } else if (suffix.equals("Character")) { suffix = "Char"; } suffix = suffix.substring(0, 1).toUpperCase() + suffix.substring(1); readerName = "Readers.read" + suffix; stmtSetter = "set" + suffix; }
From source file:org.apache.jorphan.reflect.ClassTools.java
/** * Call a class constructor with an integer parameter * @param className name of the class to be constructed * @param parameter the value to be used in the constructor * @return an instance of the class//from w w w . ja v a 2s .co m * @throws JMeterException if class cannot be created */ public static Object construct(String className, int parameter) throws JMeterException { Object instance = null; try { Class<?> clazz = ClassUtils.getClass(className); Constructor<?> constructor = clazz.getConstructor(Integer.TYPE); instance = constructor.newInstance(Integer.valueOf(parameter)); } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | NoSuchMethodException | SecurityException | IllegalAccessException | InstantiationException e) { throw new JMeterException(e); } return instance; }
From source file:com.ms.commons.summer.web.util.json.JsonNumberMorpher.java
/** * Creates a new morpher for the target type. * //from www. j a va 2s. co m * @param type must be a primitive or wrapper type. BigDecimal and BigInteger are also supported. */ public JsonNumberMorpher(Class<?> type) { super(false); if (type == null) { throw new MorphException("Must specify a type"); } if (type != Byte.TYPE && type != Short.TYPE && type != Integer.TYPE && type != Long.TYPE && type != Float.TYPE && type != Double.TYPE && !Byte.class.isAssignableFrom(type) && !Short.class.isAssignableFrom(type) && !Integer.class.isAssignableFrom(type) && !Long.class.isAssignableFrom(type) && !Float.class.isAssignableFrom(type) && !Double.class.isAssignableFrom(type) && !BigInteger.class.isAssignableFrom(type) && !BigDecimal.class.isAssignableFrom(type)) { throw new MorphException("Must specify a Number subclass"); } this.type = type; }
From source file:com.dwdesign.tweetings.util.WebViewProxySettings.java
public static boolean setProxy(WebView webView, String host, int port) { final Context context = webView.getContext(); // PSIPHON: added support for Android 4.x WebView proxy try {/*from ww w .java2 s . c o m*/ final Class<?> webViewCoreClass = Class.forName("android.webkit.WebViewCore"); final Class<?> proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { final Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); final Constructor<?> c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); final Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } } } catch (final Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.net.ProxyProperties: " + e.toString()); } try { final Object requestQueueObject = getRequestQueue(context); if (requestQueueObject != null) { // Create Proxy config object and set it into request Q final HttpHost httpHost = new HttpHost(host, port, "http"); setDeclaredField(requestQueueObject, "mProxyHost", httpHost); // Log.d("Webkit Setted Proxy to: " + host + ":" + port); return true; } } catch (final Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } return false; }
From source file:org.impalaframework.spring.DebuggingInterceptor.java
public Object invoke(MethodInvocation invocation) throws Throwable { logger.debug("Calling method " + invocation); Class<?> returnType = invocation.getMethod().getReturnType(); if (Void.TYPE.equals(returnType)) return null; if (Byte.TYPE.equals(returnType)) return (byte) 0; if (Short.TYPE.equals(returnType)) return (short) 0; if (Integer.TYPE.equals(returnType)) return (int) 0; if (Long.TYPE.equals(returnType)) return 0L; if (Float.TYPE.equals(returnType)) return 0f; if (Double.TYPE.equals(returnType)) return 0d; if (Boolean.TYPE.equals(returnType)) return false; return null;//from ww w. ja v a2 s .c o m }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Comparable<?> convertTo(Class<?> clazz, Object obj) { if (obj == null) { return null; }//from w w w . j a v a 2 s . com if (clazz.isAssignableFrom(obj.getClass())) { return (Comparable<?>) obj; } if (clazz.isPrimitive()) { if (clazz.equals(Long.TYPE)) { clazz = Long.class; } else if (clazz.equals(Integer.TYPE)) { clazz = Integer.class; } else if (clazz.equals(Float.TYPE)) { clazz = Float.class; } else if (clazz.equals(Double.TYPE)) { clazz = Double.class; } else if (clazz.equals(Boolean.TYPE)) { clazz = Boolean.class; } } if (Number.class.isAssignableFrom(clazz)) { if (obj.getClass().equals(String.class)) { obj = new Double((String) obj); } if (!Number.class.isAssignableFrom(obj.getClass())) { throw new RuntimeException( "Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); } Number number = (Number) obj; if (clazz.equals(Long.class)) { return new Long(number.longValue()); } if (clazz.equals(Integer.class)) { return new Integer(number.intValue()); } if (clazz.equals(Float.class)) { return new Float(number.floatValue()); } if (clazz.equals(Double.class)) { return new Double(number.doubleValue()); } if (clazz.equals(BigDecimal.class)) { return new BigDecimal(number.doubleValue()); } } final String oStr = String.valueOf(obj); if (clazz.equals(String.class)) { return 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); } if (clazz.equals(Boolean.class)) { return new Boolean(oStr); } throw new RuntimeException("Cannot convert from " + obj.getClass().getName() + " to " + clazz.getName()); }
From source file:com.textuality.lifesaver.Columns.java
public Columns(String[] names, Class<?>[] classes, String key1, String key2) { this.names = names; types = new Type[names.length]; this.key1 = key1; this.key2 = key2; for (int i = 0; i < names.length; i++) { if (classes[i] == String.class) types[i] = Type.STRING; else if (classes[i] == Integer.TYPE || classes[i] == Integer.class) types[i] = Type.INT;/*ww w. j a v a 2s. c o m*/ else if (classes[i] == Long.TYPE || classes[i] == Long.class) types[i] = Type.LONG; else if (classes[i] == Float.TYPE || classes[i] == Float.class) types[i] = Type.FLOAT; else if (classes[i] == Double.TYPE || classes[i] == Double.class) types[i] = Type.DOUBLE; } }
From source file:io.github.benas.jpopulator.randomizers.validation.MaxValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param maxValue the maximum threshold for the generated value * @return a random value (lower than maxValue) for the given type or null if the type is not supported *///from www. j a v a2 s.c om public static Object getRandomValue(final Class type, final long maxValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(Byte.MIN_VALUE, maxValue); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(Short.MIN_VALUE, maxValue); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(Integer.MIN_VALUE, maxValue); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(Long.MIN_VALUE, maxValue)); } return null; }
From source file:io.github.benas.jpopulator.randomizers.validation.MinValueRandomizer.java
/** * Generate a random value for the given type. * * @param type the type for which a random value will be generated * @param minValue the minimum threshold for the generated value * @return a random value (greater than maxValue) for the given type or null if the type is not supported *///from ww w . ja v a2 s . co m public static Object getRandomValue(final Class type, final long minValue) { if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return (byte) randomDataGenerator.nextLong(minValue, Byte.MAX_VALUE); } if (type.equals(Short.TYPE) || type.equals(Short.class)) { return (short) randomDataGenerator.nextLong(minValue, Short.MAX_VALUE); } if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return (int) randomDataGenerator.nextLong(minValue, Integer.MAX_VALUE); } if (type.equals(Long.TYPE) || type.equals(Long.class)) { return randomDataGenerator.nextLong(minValue, Long.MAX_VALUE); } if (type.equals(BigInteger.class)) { return new BigInteger(String.valueOf(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE))); } if (type.equals(BigDecimal.class)) { return new BigDecimal(randomDataGenerator.nextLong(minValue, Long.MAX_VALUE)); } return null; }