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:jef.tools.ArrayUtils.java
/** * ?//from ww w . j a v a 2 s. c om * * @param obj * @return */ public static Object[] toObject(Object obj) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> priType = c.getComponentType(); if (!priType.isPrimitive()) return (Object[]) obj; if (priType == Boolean.TYPE) { return toObject((boolean[]) obj); } else if (priType == Byte.TYPE) { return toObject((byte[]) obj); } else if (priType == Character.TYPE) { return toObject((char[]) obj); } else if (priType == Integer.TYPE) { return toObject((int[]) obj); } else if (priType == Long.TYPE) { return toObject((long[]) obj); } else if (priType == Float.TYPE) { return toObject((float[]) obj); } else if (priType == Double.TYPE) { return toObject((double[]) obj); } else if (priType == Short.TYPE) { return toObject((short[]) obj); } throw new IllegalArgumentException(); }
From source file:net.sourceforge.pmd.lang.java.ast.Java10Test.java
@Test public void testForLoopWithVar() { ASTCompilationUnit compilationUnit = ParserTstUtil.parseAndTypeResolveJava("10", loadSource("LocalVariableTypeInferenceForLoop.java")); List<ASTLocalVariableDeclaration> localVars = compilationUnit .findDescendantsOfType(ASTLocalVariableDeclaration.class); assertEquals(1, localVars.size());//from w w w .j ava2 s . c o m assertNull(localVars.get(0).getTypeNode()); ASTVariableDeclarator varDecl = localVars.get(0).getFirstChildOfType(ASTVariableDeclarator.class); assertSame("type should be int", Integer.TYPE, varDecl.getType()); }
From source file:org.apache.sling.models.impl.model.AbstractInjectableElement.java
private static Object getDefaultValue(AnnotatedElement element, Type type, InjectAnnotationProcessor2 annotationProcessor) { if (annotationProcessor != null && annotationProcessor.hasDefault()) { return annotationProcessor.getDefault(); }/* w ww.j a v a 2 s . com*/ Default defaultAnnotation = element.getAnnotation(Default.class); if (defaultAnnotation == null) { return null; } Object value = null; if (type instanceof Class) { Class<?> injectedClass = (Class<?>) type; if (injectedClass.isArray()) { Class<?> componentType = injectedClass.getComponentType(); if (componentType == String.class) { value = defaultAnnotation.values(); } else if (componentType == Integer.TYPE) { value = defaultAnnotation.intValues(); } else if (componentType == Integer.class) { value = ArrayUtils.toObject(defaultAnnotation.intValues()); } else if (componentType == Long.TYPE) { value = defaultAnnotation.longValues(); } else if (componentType == Long.class) { value = ArrayUtils.toObject(defaultAnnotation.longValues()); } else if (componentType == Boolean.TYPE) { value = defaultAnnotation.booleanValues(); } else if (componentType == Boolean.class) { value = ArrayUtils.toObject(defaultAnnotation.booleanValues()); } else if (componentType == Short.TYPE) { value = defaultAnnotation.shortValues(); } else if (componentType == Short.class) { value = ArrayUtils.toObject(defaultAnnotation.shortValues()); } else if (componentType == Float.TYPE) { value = defaultAnnotation.floatValues(); } else if (componentType == Float.class) { value = ArrayUtils.toObject(defaultAnnotation.floatValues()); } else if (componentType == Double.TYPE) { value = defaultAnnotation.doubleValues(); } else if (componentType == Double.class) { value = ArrayUtils.toObject(defaultAnnotation.doubleValues()); } else { log.warn("Default values for {} are not supported", componentType); } } else { if (injectedClass == String.class) { value = defaultAnnotation.values().length == 0 ? "" : defaultAnnotation.values()[0]; } else if (injectedClass == Integer.class) { value = defaultAnnotation.intValues().length == 0 ? 0 : defaultAnnotation.intValues()[0]; } else if (injectedClass == Long.class) { value = defaultAnnotation.longValues().length == 0 ? 0l : defaultAnnotation.longValues()[0]; } else if (injectedClass == Boolean.class) { value = defaultAnnotation.booleanValues().length == 0 ? false : defaultAnnotation.booleanValues()[0]; } else if (injectedClass == Short.class) { value = defaultAnnotation.shortValues().length == 0 ? ((short) 0) : defaultAnnotation.shortValues()[0]; } else if (injectedClass == Float.class) { value = defaultAnnotation.floatValues().length == 0 ? 0f : defaultAnnotation.floatValues()[0]; } else if (injectedClass == Double.class) { value = defaultAnnotation.doubleValues().length == 0 ? 0d : defaultAnnotation.doubleValues()[0]; } else { log.warn("Default values for {} are not supported", injectedClass); } } } else { log.warn("Cannot provide default for {}", type); } return value; }
From source file:com.sf.ddao.orm.RSMapperFactoryRegistry.java
public static RowMapperFactory getScalarMapper(final Type itemType, final int idx, boolean req) { if (itemType == String.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getString(idx); }// w w w . j ava 2 s . c o m }; } if (itemType == Integer.class || itemType == Integer.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getInt(idx); } }; } if (itemType == URL.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getURL(idx); } }; } if (itemType == BigInteger.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { final BigDecimal res = rs.getBigDecimal(idx); return res == null ? null : res.toBigInteger(); } }; } if (itemType == BigDecimal.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBigDecimal(idx); } }; } if (itemType == InputStream.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBinaryStream(idx); } }; } if (itemType == Boolean.class || itemType == Boolean.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBoolean(idx); } }; } if (itemType == Blob.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBlob(idx); } }; } if (itemType == java.sql.Date.class || itemType == java.util.Date.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getTimestamp(idx); } }; } if (itemType instanceof Class) { final Class itemClass = (Class) itemType; final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass); if (columnMapper != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return columnMapper.map(rs, idx); } }; } final Converter converter = ConvertUtils.lookup(itemClass); if (converter != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(idx); if (s == null) { return null; } return converter.convert(itemClass, s); } }; } if (Enum.class.isAssignableFrom((Class<?>) itemType)) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(idx); if (s == null) { return null; } //noinspection unchecked return Enum.valueOf((Class<Enum>) itemType, s); } }; } } if (req) { throw new IllegalArgumentException("no mapping defined for " + itemType); } return null; }
From source file:candr.yoclip.option.OptionSetter.java
@Override public void setOption(final T bean, final String value) { final Class<?> setterParameterType = getType(); try {/*from www . j av a 2 s .c o m*/ if (Boolean.TYPE.equals(setterParameterType) || Boolean.class.isAssignableFrom(setterParameterType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(setterParameterType) || Byte.class.isAssignableFrom(setterParameterType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(setterParameterType) || Short.class.isAssignableFrom(setterParameterType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(setterParameterType) || Integer.class.isAssignableFrom(setterParameterType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(setterParameterType) || Long.class.isAssignableFrom(setterParameterType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(setterParameterType) || Character.class.isAssignableFrom(setterParameterType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(setterParameterType) || Float.class.isAssignableFrom(setterParameterType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(setterParameterType) || Double.class.isAssignableFrom(setterParameterType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(setterParameterType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OptionParameter only supports %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, setterParameterType); throw new OptionsParseException(error, e); } }
From source file:rb.app.TransientRBSystem.java
/** * Evaluate theta_q_m (for the q^th mass matrix term) at the current parameter. *//* ww w .ja va 2s.c o m*/ public double eval_theta_q_m(int q) { Method meth; try { // Get a reference to get_n_M_functions, which does not // take any arguments Class partypes[] = new Class[2]; partypes[0] = Integer.TYPE; partypes[1] = double[].class; meth = mAffineFnsClass.getMethod("evaluateM", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateM failed", nsme); } Double theta_val; try { Object arglist[] = new Object[2]; arglist[0] = new Integer(q); arglist[1] = current_parameters.getArray(); Object theta_obj = meth.invoke(mTheta, arglist); theta_val = (Double) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return theta_val.doubleValue(); }
From source file:com.psiphon3.psiphonlibrary.WebViewProxySettings.java
@TargetApi(Build.VERSION_CODES.KITKAT) @SuppressWarnings("rawtypes") private static boolean setWebkitProxyKitKat(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try {/*from www. j a v a 2 s .c o m*/ Class applicationClass = Class.forName("android.app.Application"); Field loadedApkField = applicationClass.getDeclaredField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkClass = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkClass.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object receiver : ((ArrayMap) receiverMap).keySet()) { Class receiverClass = receiver.getClass(); if (receiverClass.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = receiverClass.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); final String CLASS_NAME = "android.net.ProxyProperties"; Class proxyPropertiesClass = Class.forName(CLASS_NAME); Constructor constructor = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, null); intent.putExtra("proxy", (Parcelable) proxyProperties); onReceiveMethod.invoke(receiver, appContext, intent); } } } return true; } catch (ClassNotFoundException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (NoSuchFieldException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (IllegalAccessException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (IllegalArgumentException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (NoSuchMethodException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (InvocationTargetException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } catch (InstantiationException e) { MyLog.d("Exception setting WebKit proxy on KitKat through ProxyChangeListener: " + e.toString()); } return false; }
From source file:candr.yoclip.option.OptionField.java
@Override public void setOption(final T bean, final String value) { final Class<?> fieldType = getField().getType(); try {/*from w ww . j ava2 s. c om*/ if (Boolean.TYPE.equals(fieldType) || Boolean.class.isAssignableFrom(fieldType)) { setBooleanOption(bean, value); } else if (Byte.TYPE.equals(fieldType) || Byte.class.isAssignableFrom(fieldType)) { setByteOption(bean, value); } else if (Short.TYPE.equals(fieldType) || Short.class.isAssignableFrom(fieldType)) { setShortOption(bean, value); } else if (Integer.TYPE.equals(fieldType) || Integer.class.isAssignableFrom(fieldType)) { setIntegerOption(bean, value); } else if (Long.TYPE.equals(fieldType) || Long.class.isAssignableFrom(fieldType)) { setLongOption(bean, value); } else if (Character.TYPE.equals(fieldType) || Character.class.isAssignableFrom(fieldType)) { setCharacterOption(bean, value); } else if (Float.TYPE.equals(fieldType) || Float.class.isAssignableFrom(fieldType)) { setFloatOption(bean, value); } else if (Double.TYPE.equals(fieldType) || Double.class.isAssignableFrom(fieldType)) { setDoubleOption(bean, value); } else if (String.class.isAssignableFrom(fieldType)) { setStringOption(bean, value); } else { final String supportedTypes = "boolean, byte, short, int, long, char, float, double, and String"; throw new OptionsParseException( String.format("OldOptionsParser only support %s types", supportedTypes)); } } catch (NumberFormatException e) { final String error = String.format("Error converting '%s' to %s", value, fieldType); throw new OptionsParseException(error, e); } }
From source file:net.sourceforge.pmd.lang.java.ast.Java12Test.java
@Test public void testSwitchExpressionsBreak() { ASTCompilationUnit compilationUnit = ParserTstUtil.parseAndTypeResolveJava("12", loadSource("SwitchExpressionsBreak.java")); Assert.assertNotNull(compilationUnit); ASTSwitchExpression switchExpression = compilationUnit.getFirstDescendantOfType(ASTSwitchExpression.class); Assert.assertEquals(11, switchExpression.jjtGetNumChildren()); Assert.assertTrue(switchExpression.jjtGetChild(0) instanceof ASTExpression); Assert.assertEquals(5, switchExpression.findChildrenOfType(ASTSwitchLabel.class).size()); ASTBreakStatement breakStatement = switchExpression.getFirstDescendantOfType(ASTBreakStatement.class); Assert.assertEquals("SwitchExpressionsBreak.SIX", breakStatement.getImage()); Assert.assertTrue(breakStatement.jjtGetChild(0) instanceof ASTExpression); ASTLocalVariableDeclaration localVar = compilationUnit .findDescendantsOfType(ASTLocalVariableDeclaration.class).get(1); ASTVariableDeclarator localVarDecl = localVar.getFirstChildOfType(ASTVariableDeclarator.class); Assert.assertEquals(Integer.TYPE, localVarDecl.getType()); Assert.assertEquals(Integer.TYPE, switchExpression.getType()); }
From source file:org.hyperic.lather.util.Latherize.java
public void latherize(boolean xDocletStyle, String outPackage, Class fClass, OutputStream os) throws LatherizeException, IOException { final String INDENT = " "; PrintWriter pWriter;//from www .j a va2s . c om DynaProperty[] dProps; WrapDynaBean dBean; DynaClass dClass; Object beanInstance; String className, lClassName; try { beanInstance = fClass.newInstance(); } catch (IllegalAccessException exc) { throw new LatherizeException("Illegal access trying to create " + "new instance"); } catch (InstantiationException exc) { throw new LatherizeException("Unable to instantiate: " + exc.getMessage()); } dBean = new WrapDynaBean(beanInstance); dClass = dBean.getDynaClass(); dProps = dClass.getDynaProperties(); pWriter = new PrintWriter(os); className = fClass.getName(); className = className.substring(className.lastIndexOf(".") + 1); lClassName = "Lather" + className; pWriter.println("package " + outPackage + ";"); pWriter.println(); pWriter.println("import " + LatherValue.class.getName() + ";"); pWriter.println("import " + LatherRemoteException.class.getName() + ";"); pWriter.println("import " + LatherKeyNotFoundException.class.getName() + ";"); pWriter.println("import " + fClass.getName() + ";"); pWriter.println(); pWriter.println("public class " + lClassName); pWriter.println(" extends LatherValue"); pWriter.println("{"); for (int i = 0; i < dProps.length; i++) { pWriter.print(" "); if (!this.isLatherStyleProp(dProps[i])) { pWriter.print("// "); } pWriter.println("private static final String " + this.makePropVar(dProps[i]) + " = \"" + dProps[i].getName() + "\";"); } pWriter.println(); pWriter.println(" public " + lClassName + "(){"); pWriter.println(" super();"); pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + lClassName + "(" + className + " v){"); pWriter.println(" super();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String getter = "v." + this.makeGetter(dProps[i]) + "()"; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { String lName; lName = dProps[i].getName(); lName = lName.substring(0, 1).toLowerCase() + lName.substring(1); pWriter.println(INDENT + "if(v." + lName + "HasBeenSet()){"); pWriter.print(" "); } if (dProps[i].getType().equals(String.class)) { pWriter.println(INDENT + "this.setStringValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + ".intValue());"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ");"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println( INDENT + "this.setDoubleValue(" + propVar + ", (double)" + getter + ".longValue());"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println(INDENT + "this.setIntValue(" + propVar + ", " + getter + " ? 1 : 0);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println( INDENT + "this.setIntValue(" + propVar + ", " + getter + ".booleanValue() ? 1 : 0);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ");"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println(INDENT + "this.setDoubleValue(" + propVar + ", " + getter + ".doubleValue());"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println(INDENT + "this.setByteAValue(" + propVar + ", " + getter + ");"); } else { pWriter.println(INDENT + "this.setObjectValue(" + "DONT KNOW HOW TO HANDLE THIS, " + getter + ");"); } if (xDocletStyle) { pWriter.println(INDENT + "}"); pWriter.println(); } } pWriter.println(" }"); pWriter.println(); pWriter.println(" public " + className + " get" + className + "(){"); pWriter.println(INDENT + className + " r = new " + className + "();"); pWriter.println(); for (int i = 0; i < dProps.length; i++) { String propVar = this.makePropVar(dProps[i]); String setter = "r." + this.makeSetter(dProps[i]) + "("; if (!this.isLatherStyleProp(dProps[i])) { continue; } if (xDocletStyle) { pWriter.println(INDENT + "try {"); pWriter.print(" "); } pWriter.print(INDENT + setter); if (dProps[i].getType().equals(String.class)) { pWriter.println("this.getStringValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.TYPE)) { pWriter.println("this.getIntValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Integer.class)) { pWriter.println("new Integer(this.getIntValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Long.TYPE)) { pWriter.println("(long)this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Long.class)) { pWriter.println("new Long((long)this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(Boolean.TYPE)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "true : false);"); } else if (dProps[i].getType().equals(Boolean.class)) { pWriter.println("this.getIntValue(" + propVar + ") == 1 ? " + "Boolean.TRUE : Boolean.FALSE);"); } else if (dProps[i].getType().equals(Double.TYPE)) { pWriter.println("this.getDoubleValue(" + propVar + "));"); } else if (dProps[i].getType().equals(Double.class)) { pWriter.println("new Double(this.getDoubleValue(" + propVar + ")));"); } else if (dProps[i].getType().equals(byte[].class)) { pWriter.println("this.getByteAValue(" + propVar + "));"); } else { pWriter.println("DONT KNOW HOW TO HANDLE " + propVar + "));"); } if (xDocletStyle) { pWriter.println(INDENT + "} catch(LatherKeyNotFoundException " + "exc){}"); pWriter.println(); } } pWriter.println(INDENT + "return r;"); pWriter.println(" }"); pWriter.println(); pWriter.println(" protected void validate()"); pWriter.println(" throws LatherRemoteException"); pWriter.println(" {"); if (!xDocletStyle) { pWriter.println(" try { "); pWriter.println(" this.get" + className + "();"); pWriter.println(" } catch(LatherKeyNotFoundException e){"); pWriter.println(" throw new LatherRemoteException(\"" + "All values not set\");"); pWriter.println(" }"); } pWriter.println(" }"); pWriter.println("}"); pWriter.flush(); }