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:ch.rasc.wampspring.method.MethodParameterConverterTest.java
@Test public void testToint() throws NoSuchMethodException, SecurityException { Method testMethod = getClass().getDeclaredMethod("intParam", Integer.TYPE); MethodParameter param = new MethodParameter(testMethod, 0); assertThat(this.converter.convert(param, null)).isNull(); assertThat(this.converter.convert(param, (byte) 1)).isEqualTo(1); assertThat(this.converter.convert(param, (short) 2)).isEqualTo(2); assertThat(this.converter.convert(param, 3)).isEqualTo(3); assertThat(this.converter.convert(param, 4L)).isEqualTo(4); assertThat(this.converter.convert(param, 5.5f)).isEqualTo(5); assertThat(this.converter.convert(param, 6.6)).isEqualTo(6); assertThat(this.converter.convert(param, new BigDecimal("3.141"))).isEqualTo(3); }
From source file:com.link_intersystems.lang.Conversions.java
/** * <em>java language specification - 5.1.2 Widening Primitive Conversion</em> * .//from w w w . ja v a2s.com * * <code> * <blockquote>The following 19 specific conversions on primitive types * are called the widening primitive conversions: * <ul> * <li>byte to short, int, long, float, or double</li> * <li>short to int, long, float, or double</li> * <li>char to int, long, float, or double</li> * <li>int to long, float, or double</li> * <li>long to float or double</li> * <li>float to double</li> * </blockquote> * </code> * * @param from * the base type * @param to * the widening type * @return true if from to to is a primitive widening. * @since 1.0.0.0 */ public static boolean isPrimitiveWidening(Class<?> from, Class<?> to) { Assert.isTrue(Primitives.isPrimitive(from), PARAMETER_MUST_BE_A_PRIMITIVE, "form"); Assert.isTrue(Primitives.isPrimitive(to), PARAMETER_MUST_BE_A_PRIMITIVE, "to"); boolean isPrimitiveWidening = false; if (isIdentity(from, Byte.TYPE)) { isPrimitiveWidening = isPrimitiveByteWidening(to); } else if (isIdentity(from, Short.TYPE)) { isPrimitiveWidening = isPrimitiveShortWidening(to); } else if (isIdentity(from, Character.TYPE)) { isPrimitiveWidening = isPrimitiveCharacterWidening(to); } else if (isIdentity(from, Integer.TYPE)) { isPrimitiveWidening = isPrimitiveIntegerWidening(to); } else if (isIdentity(from, Long.TYPE)) { isPrimitiveWidening = isPrimitiveLongWidening(to); } else if (isIdentity(from, Float.TYPE)) { isPrimitiveWidening = isPrimitiveFloatWidening(to); } /* * must be a double - no widening available */ return isPrimitiveWidening; }
From source file:io.github.jhipster.config.apidoc.PageableParameterBuilderPlugin.java
@Override public void apply(ParameterContext context) { ResolvedMethodParameter parameter = context.resolvedMethodParameter(); Class<?> type = parameter.getParameterType().getErasedType(); if (type != null && Pageable.class.isAssignableFrom(type)) { Function<ResolvedType, ? extends ModelReference> factory = createModelRefFactory(context); ModelReference intModel = factory.apply(resolver.resolve(Integer.TYPE)); ModelReference stringModel = factory.apply(resolver.resolve(List.class, String.class)); List<Parameter> parameters = newArrayList( context.parameterBuilder().parameterType("query").name("page").modelRef(intModel) .description("Page number of the requested page").build(), context.parameterBuilder().parameterType("query").name("size").modelRef(intModel) .description("Size of a page").build(), context.parameterBuilder().parameterType("query").name("sort").modelRef(stringModel) .allowMultiple(true) .description("Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. " + "Multiple sort criteria are supported.") .build());/*from w w w. j av a 2s. com*/ context.getOperationContext().operationBuilder().parameters(parameters); } }
From source file:be.fgov.kszbcss.rhq.websphere.component.jdbc.db2.pool.ConnectionContextImpl.java
ConnectionContextImpl(Map<String, Object> properties) { dataSource = new DB2SimpleDataSource(); BeanInfo beanInfo;/* w ww .j a v a 2 s . com*/ try { beanInfo = Introspector.getBeanInfo(DB2SimpleDataSource.class); } catch (IntrospectionException ex) { throw new Error(ex); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { String name = descriptor.getName(); if (properties.containsKey(name)) { Object value = properties.get(name); Class<?> propertyType = descriptor.getPropertyType(); if (log.isDebugEnabled()) { log.debug("Setting property " + name + ": propertyType=" + propertyType.getName() + ", value=" + value + " (class=" + (value == null ? "<N/A>" : value.getClass().getName()) + ")"); } if (propertyType != String.class && value instanceof String) { // Need to convert value to correct type if (propertyType == Integer.class || propertyType == Integer.TYPE) { value = Integer.valueOf((String) value); } if (log.isDebugEnabled()) { log.debug("Converted value to " + value + " (class=" + value.getClass().getName() + ")"); } } try { descriptor.getWriteMethod().invoke(dataSource, value); } catch (IllegalArgumentException ex) { throw new RuntimeException("Failed to set '" + name + "' property", ex); } catch (IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (InvocationTargetException ex) { Throwable cause = ex.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { throw new RuntimeException(ex); } } } } }
From source file:org.thingsplode.synapse.serializers.jackson.adapters.ParameterWrapperDeserializer.java
@Override public ParameterWrapper deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonNode node = jp.readValueAsTree(); if (node != null && node.size() > 0 && node.isContainerNode()) { ParameterWrapper pw = ParameterWrapper.create(); ArrayNode paramsNode = (ArrayNode) node.get("params"); Iterator<JsonNode> elemIterator = paramsNode.elements(); while (elemIterator.hasNext()) { JsonNode currentNode = elemIterator.next(); if (currentNode.getNodeType() == JsonNodeType.OBJECT) { try { String paramid = ((ObjectNode) currentNode).get("paramid").asText(); String typeName = ((ObjectNode) currentNode).get("type").asText(); Class paramType = null; if (null != typeName) switch (typeName) { case "long": paramType = Long.TYPE; break; case "byte": paramType = Byte.TYPE; break; case "short": paramType = Short.TYPE; break; case "int": paramType = Integer.TYPE; break; case "float": paramType = Float.TYPE; break; case "double": paramType = Double.TYPE; break; case "boolean": paramType = Boolean.TYPE; break; case "char": paramType = Character.TYPE; break; default: paramType = Class.forName(typeName); break; }/*from ww w. j ava2 s . c o m*/ Object parameterObject = jp.getCodec().treeToValue(currentNode.get("value"), paramType); pw.add(paramid, paramType, parameterObject); } catch (ClassNotFoundException ex) { throw new JsonParseException(jp, ex.getMessage()); } } } return pw; } else { return null; } }
From source file:ClassUtils.java
/** * Helper for invoking an instance method that takes a single parameter. * This method also handles parameters of primitive type. * //from w ww.j a v a2 s . c om * @param cl * The class that the instance belongs to * @param instance * The object on which we will invoke the method * @param methodName * The method name * @param param * The parameter * @throws Throwable */ public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable { Class paramClass; if (param instanceof Integer) paramClass = Integer.TYPE; else if (param instanceof Long) paramClass = Long.TYPE; else if (param instanceof Short) paramClass = Short.TYPE; else if (param instanceof Boolean) paramClass = Boolean.TYPE; else if (param instanceof Double) paramClass = Double.TYPE; else if (param instanceof Float) paramClass = Float.TYPE; else if (param instanceof Character) paramClass = Character.TYPE; else if (param instanceof Byte) paramClass = Byte.TYPE; else paramClass = param.getClass(); Method method = cl.getMethod(methodName, new Class[] { paramClass }); try { return method.invoke(instance, new Object[] { param }); } catch (InvocationTargetException e) { throw e.getCause(); } }
From source file:com.psiphon3.psiphonlibrary.WebViewProxySettings.java
@SuppressWarnings("rawtypes") private static boolean setWebkitProxyICS(Context ctx, String host, int port) { try {/*w w w . j a v a2 s . com*/ Class webViewCoreClass = Class.forName("android.webkit.WebViewCore"); Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } } } catch (Exception e) { MyLog.d("Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } catch (Error e) { MyLog.d("Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } return false; }
From source file:com.swtxml.swt.metadata.WidgetRegistry.java
@SuppressWarnings("unchecked") public Constructor getWidgetConstructor(Class<? extends Widget> widgetClass) { return CollectionUtils.find(Arrays.asList(widgetClass.getConstructors()), new IFilter<Constructor>() { public boolean match(Constructor constructor) { return (constructor.getParameterTypes().length == 2 && constructor.getParameterTypes()[1] == Integer.TYPE); }/* w w w . j a va2 s.co m*/ }); }
From source file:org.apache.flume.sink.hbase.TestAsyncHBaseSink.java
@BeforeClass public static void setUp() throws Exception { /*//from ww w .j av a2 s . c o m * Borrowed from HCatalog ManyMiniCluster.java * https://svn.apache.org/repos/asf/incubator/hcatalog/trunk/ * storage-handlers/hbase/src/test/org/apache/hcatalog/ * hbase/ManyMiniCluster.java * */ String hbaseDir = new File(workDir, "hbase").getAbsolutePath(); String hbaseRoot = "file://" + hbaseDir; Configuration hbaseConf = HBaseConfiguration.create(); hbaseConf.set(HConstants.HBASE_DIR, hbaseRoot); hbaseConf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, 2181); hbaseConf.set(HConstants.ZOOKEEPER_QUORUM, "0.0.0.0"); hbaseConf.setInt("hbase.master.info.port", -1); hbaseConf.setInt("hbase.zookeeper.property.maxClientCnxns", 500); String zookeeperDir = new File(workDir, "zk").getAbsolutePath(); int zookeeperPort = 2181; zookeeperCluster = new MiniZooKeeperCluster(); Method m; Class<?> zkParam[] = { Integer.TYPE }; try { m = MiniZooKeeperCluster.class.getDeclaredMethod("setDefaultClientPort", zkParam); } catch (NoSuchMethodException e) { m = MiniZooKeeperCluster.class.getDeclaredMethod("setClientPort", zkParam); } m.invoke(zookeeperCluster, new Object[] { new Integer(zookeeperPort) }); zookeeperCluster.startup(new File(zookeeperDir)); hbaseCluster = new MiniHBaseCluster(hbaseConf, 1); HMaster master = hbaseCluster.getMaster(); Object serverName = master.getServerName(); String hostAndPort; if (serverName instanceof String) { System.out.println("Server name is string, using HServerAddress."); m = HMaster.class.getDeclaredMethod("getMasterAddress", new Class<?>[] {}); Class<?> clazz = Class.forName("org.apache.hadoop.hbase.HServerAddress"); /* * Call method to get server address */ Object serverAddr = clazz.cast(m.invoke(master, new Object[] {})); //returns the address as hostname:port hostAndPort = serverAddr.toString(); } else { System.out.println("ServerName is org.apache.hadoop.hbase.ServerName," + "using getHostAndPort()"); Class<?> clazz = Class.forName("org.apache.hadoop.hbase.ServerName"); m = clazz.getDeclaredMethod("getHostAndPort", new Class<?>[] {}); hostAndPort = m.invoke(serverName, new Object[] {}).toString(); } hbaseConf.set("hbase.master", hostAndPort); testUtility = new HBaseTestingUtility(hbaseConf); testUtility.setZkCluster(zookeeperCluster); hbaseCluster.startMaster(); Map<String, String> ctxMap = new HashMap<String, String>(); ctxMap.put("table", tableName); ctxMap.put("columnFamily", columnFamily); ctxMap.put("serializer", "org.apache.flume.sink.hbase.SimpleAsyncHbaseEventSerializer"); ctxMap.put("serializer.payloadColumn", plCol); ctxMap.put("serializer.incrementColumn", inColumn); ctx.putAll(ctxMap); }
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
private static void loadObject(Object retObj, Field f, JSONObject jsonObj) throws JSONSerializationException { String key = f.getName();//from w w w.j a v a 2 s. c om Class type = f.getType(); try { if (type.isPrimitive()) { if (type == Integer.TYPE) { f.setInt(retObj, jsonObj.getInt(key)); } else if (type == Long.TYPE) { f.setLong(retObj, jsonObj.getInt(key)); } else if (type == Short.TYPE) { f.setShort(retObj, (short) jsonObj.getInt(key)); } else if (type == Boolean.TYPE) { f.setBoolean(retObj, jsonObj.getBoolean(key)); } else if (type == Double.TYPE) { f.setDouble(retObj, jsonObj.getDouble(key)); } else if (type == Float.TYPE) { f.setFloat(retObj, (float) jsonObj.getDouble(key)); } else if (type == Character.TYPE) { char ch = jsonObj.getString(key).charAt(0); f.setChar(retObj, ch); } else if (type == Byte.TYPE) { f.setByte(retObj, (byte) jsonObj.getInt(key)); } else { throw new JSONSerializationException("Unknown primitive: " + type); } } else if (type == String.class) { f.set(retObj, jsonObj.getString(key)); } else if (JSONSerializable.class.isAssignableFrom(type)) { JSONObject jObj = jsonObj.getJSONObject(key); JSONSerializable serObj = deSerialize(type, jObj); f.set(retObj, serObj); } } catch (Exception e) { throw new JSONSerializationException(e.getMessage(), e); } }