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:com.github.diogochbittencourt.googleplaydownloader.downloader.impl.AndroidHttpClient.java
/** * Create a new HttpClient with reasonable defaults (which you can update). * * @param userAgent to report in your HTTP requests * @param context to use for caching SSL sessions (may be null for no caching) * @return AndroidHttpClient for you to use for all your requests. */// ww w . j av a2 s . c o m public static AndroidHttpClient newInstance(String userAgent, Context context) { HttpParams params = new BasicHttpParams(); // Turn off stale checking. Our connections break all the time anyway, // and it's not worth it to pay the penalty of checking every time. HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params, 8192); // Don't handle redirects -- return them to the caller. Our code // often wants to re-POST after a redirect, which we must do ourselves. HttpClientParams.setRedirecting(params, false); Object sessionCache = null; // Use a session cache for SSL sockets -- Froyo only if (null != context && null != sSslSessionCacheClass) { Constructor<?> ct; try { ct = sSslSessionCacheClass.getConstructor(Context.class); sessionCache = ct.newInstance(context); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // Set the specified user agent and register standard protocols. HttpProtocolParams.setUserAgent(params, userAgent); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SocketFactory sslCertificateSocketFactory = null; if (null != sessionCache) { Method getHttpSocketFactoryMethod; try { getHttpSocketFactoryMethod = SSLCertificateSocketFactory.class .getDeclaredMethod("getHttpSocketFactory", Integer.TYPE, sSslSessionCacheClass); sslCertificateSocketFactory = (SocketFactory) getHttpSocketFactoryMethod.invoke(null, SOCKET_OPERATION_TIMEOUT, sessionCache); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (null == sslCertificateSocketFactory) { sslCertificateSocketFactory = SSLSocketFactory.getSocketFactory(); } schemeRegistry.register(new Scheme("https", sslCertificateSocketFactory, 443)); ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry); // We use a factory method to modify superclass initialization // parameters without the funny call-a-static-method dance. return new AndroidHttpClient(manager, params); }
From source file:com.enonic.cms.business.portal.datasource.methodcall.MethodCallFactory.java
private static Object convertParameter(Class type, String value) { if (type == Integer.TYPE) { try {/*w w w. j a v a 2 s.c o m*/ return new Integer(value); } catch (NumberFormatException e) { throw new IllegalArgumentException("Expected value of type Integer, got: " + value, e); } } else if (type == String.class) { return value; } else if (type == Boolean.TYPE) { return Boolean.valueOf(value); } else if (type == String[].class) { if (value == null) { return null; } TStringArrayList arrayList = new TStringArrayList(); String[] stringArray = StringUtil.splitString(value, ','); for (String strValue : stringArray) { strValue = strValue.trim(); if (!StringUtils.isEmpty(strValue)) { arrayList.add(strValue); } } return arrayList.toNativeArray(); } else if (type == int[].class) { if (value == null) { return null; } String[] tmpArray = StringUtil.splitString(value, ','); int[] intArray = new int[tmpArray.length]; int index = 0; for (String tmp : tmpArray) { intArray[index++] = Integer.parseInt(tmp.trim()); } return intArray; } else { return null; } }
From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java
public Object invokeDummy(MethodInvocation invocation) throws Throwable { log.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 w w w . ja v a2 s.c o m }
From source file:net.sf.json.JSONUtils.java
/** * Tests if obj is a primitive number or wrapper.<br> *//*from ww w . ja v a2 s . c o m*/ public static boolean isNumber(Object obj) { if (((obj != null) && (obj.getClass() == Byte.TYPE)) || ((obj != null) && (obj.getClass() == Short.TYPE)) || ((obj != null) && (obj.getClass() == Integer.TYPE)) || ((obj != null) && (obj.getClass() == Long.TYPE)) || ((obj != null) && (obj.getClass() == Float.TYPE)) || ((obj != null) && (obj.getClass() == Double.TYPE))) { return true; } if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer) || (obj instanceof Long) || (obj instanceof Float) || (obj instanceof Double)) { return true; } return false; }
From source file:escada.tpc.common.clients.jmx.ClientEmulationStartup.java
private void startClientEmulation(boolean exit) { ClientEmulation e = null;/*from ww w . j a va2 s .c o m*/ Vector<ClientEmulation> ebs = new Vector<ClientEmulation>(); DatabaseManager dbManager = null; try { logger.info("Starting up the client application."); logger.info("Remote Emulator for Database Benchmark ..."); logger.info("Universidade do Minho (Grupo de Sistemas Distribuidos)"); logger.info("Version 0.1"); Class cl = null; Constructor co = null; cl = Class.forName(this.workloadResources.getDbClass()); try { co = cl.getConstructor(new Class[] { Integer.TYPE }); } catch (Exception ex) { } if (co == null) { dbManager = (DatabaseManager) cl.newInstance(); } else { dbManager = (DatabaseManager) co .newInstance(new Object[] { new Integer(this.workloadResources.getClients()) }); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD_HH_mm"); String date = sdf.format(new Date()); PerformanceLogger.setPrintWriter("TPCC-" + date + "-" + this.workloadResources.getPrefix() + "-time-" + this.workloadResources.getMeasurementTime() + "-clients-" + this.workloadResources.getClients() + "-frag-" + this.workloadResources.getFrag() + "-think-" + this.workloadResources.isThinkTime() + ".dat"); PerformanceCounters.getReference();//Initialize instance dbManager.setConnectionPool(this.workloadResources.isConnectionPoolEnabled()); dbManager.setMaxConnection(this.workloadResources.getPoolSize()); dbManager.setDriverName(this.databaseResources.getDriver()); dbManager.setjdbcPath(this.databaseResources.getConnectionString()); dbManager.setUserInfo(this.databaseResources.getUserName(), this.databaseResources.getPassword()); for (int i = 0; i < this.workloadResources.getClients(); i++) { e = new ClientEmulation(); e.setFinished(false); e.setTraceInformation(this.workloadResources.getTrace()); e.setNumberConcurrentEmulators(this.workloadResources.getClients()); e.setStatusThinkTime(this.workloadResources.isThinkTime()); e.setStatusReSubmit(this.workloadResources.isResubmit()); e.setDatabase(dbManager); e.setEmulationName(this.workloadResources.getPrefix()); e.setHostId(Integer.toString(this.workloadResources.getHostId())); e.create(this.workloadResources.getEbClass(), this.workloadResources.getStClass(), i, this.workloadResources.getFrag(), this, this.workloadResources.getPrefix()); Thread t = new Thread(e); t.setName(this.workloadResources.getPrefix() + "-" + i); e.setThread(t); t.start(); ebs.add(e); } synchronized (this) { server.setClientEmulations(this.workloadResources.getPrefix(), ebs); server.attachClientToServer(this.workloadResources.getPrefix(), this.databaseResources.getConnectionString()); } logger.info("Running simulation for " + this.workloadResources.getMeasurementTime() + " minute(s)."); waitForRampDown(this.workloadResources.getPrefix(), 0, this.workloadResources.getMeasurementTime()); for (int i = 0; i < this.workloadResources.getClients(); i++) { e = (ClientEmulation) ebs.elementAt(i); //logger.info("Waiting for the eb " + i + " to finish its job.."); //try { e.setCompletion(true); //e.getThread().join(); /*} catch (InterruptedException inte) { inte.printStackTrace(); continue; }*/ } for (int i = 0; i < this.workloadResources.getClients(); i++) { e = (ClientEmulation) ebs.elementAt(i); logger.info("Waiting for the eb " + i + " to finish its job.."); try { // e.setCompletion(true); e.getThread().join(); } catch (InterruptedException inte) { inte.printStackTrace(); continue; } } logger.info("EBs finished."); PerformanceLogger.info("-------------------- SUMMARY ---------------------------"); PerformanceLogger.info("Abort rate:" + PerformanceCounters.getReference().getTotalAbortRate()); PerformanceLogger.info("Average latency:" + PerformanceCounters.getReference().getAverageLatency()); PerformanceLogger .info("Measured tpmC:" + PerformanceCounters.getReference().getTotalNewOrderCommitRate()); PerformanceLogger.close(); } catch (Exception ex) { logger.info("Error while creating clients: ", ex); } finally { synchronized (this) { this.server.removeClientEmulations(this.workloadResources.getPrefix()); this.server.removeClientStage(this.workloadResources.getPrefix()); this.server.detachClientToServer(this.workloadResources.getPrefix(), this.databaseResources.getConnectionString()); notifyAll(); } try { dbManager.releaseConnections(); } catch (SQLException e1) { e1.printStackTrace(); } logger.info("Ebs finished their jobs.."); if (exit) System.exit(0); } }
From source file:com.vilt.minium.impl.BaseWebElementsImpl.java
public Object invoke(Method method, Object... args) { if (method.isVarArgs()) { args = expandVarArgs(args);/*from w w w. j a v a2s . c om*/ } String expression = computeExpression(this, isAsyncMethod(method), method.getName(), args); if (method.getReturnType() != Object.class && method.getReturnType().isAssignableFrom(this.getClass())) { T webElements = WebElementsFactoryHelper.createExpressionWebElements(factory, myself, expression); return webElements; } else { Object result = null; boolean async = isAsyncMethod(method); Iterable<WebElementsDriver<T>> webDrivers = candidateWebDrivers(); if (method.getReturnType() == Void.TYPE) { for (WebElementsDriver<T> wd : webDrivers) { factory.getInvoker().invokeExpression(wd, async, expression); } } else { if (Iterables.size(webDrivers) == 0) { throw new WebElementsException("The expression has no frame or window to be evaluated to"); } else if (Iterables.size(webDrivers) == 1) { WebElementsDriver<T> wd = Iterables.get(webDrivers, 0); result = factory.getInvoker().invokeExpression(wd, async, expression); } else { String sizeExpression = computeExpression(this, false, "size"); WebElementsDriver<T> webDriverWithResults = null; for (WebElementsDriver<T> wd : webDrivers) { long size = (Long) factory.getInvoker().invokeExpression(wd, async, sizeExpression); if (size > 0) { if (webDriverWithResults == null) { webDriverWithResults = wd; } else { throw new WebElementsException( "Several frames or windows match the same expression, so value cannot be computed"); } } } if (webDriverWithResults != null) { result = factory.getInvoker().invokeExpression(webDriverWithResults, async, expression); } } } if (logger.isDebugEnabled()) { String val; if (method.getReturnType() == Void.TYPE) { val = "void"; } else { val = StringUtils.abbreviate(argToStringFunction.apply(result), 40); if (val.startsWith("'") && !val.endsWith("'")) val += "(...)'"; } logger.debug("[Value: {}] {}", argToStringFunction.apply(result), expression); } // let's handle numbers when return type is int if (method.getReturnType() == Integer.TYPE) { return result == null ? 0 : ((Number) result).intValue(); } else { return result; } } }
From source file:ca.sqlpower.sqlobject.BaseSQLObjectTestCase.java
/** * XXX This test should use the {@link GenericNewValueMaker} as it has it's own mini * version inside it. This test should also be using the annotations to decide which * setters can fire events./* ww w .j a v a2 s . c o m*/ * * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws SQLObjectException */ public void testAllSettersGenerateEvents() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SQLObjectException { SQLObject so = getSQLObjectUnderTest(); so.populate(); propertiesToIgnoreForEventGeneration.addAll(getPropertiesToIgnoreForEvents()); //Ignored because we expect the object to be populated. propertiesToIgnoreForEventGeneration.add("exportedKeysPopulated"); propertiesToIgnoreForEventGeneration.add("importedKeysPopulated"); propertiesToIgnoreForEventGeneration.add("columnsPopulated"); propertiesToIgnoreForEventGeneration.add("indicesPopulated"); CountingSQLObjectListener listener = new CountingSQLObjectListener(); SQLPowerUtils.listenToHierarchy(so, listener); if (so instanceof SQLDatabase) { // should be handled in the Datasource propertiesToIgnoreForEventGeneration.add("name"); } List<PropertyDescriptor> settableProperties; settableProperties = Arrays.asList(PropertyUtils.getPropertyDescriptors(so.getClass())); for (PropertyDescriptor property : settableProperties) { Object oldVal; if (propertiesToIgnoreForEventGeneration.contains(property.getName())) continue; try { oldVal = PropertyUtils.getSimpleProperty(so, property.getName()); // check for a setter if (property.getWriteMethod() == null) { continue; } } catch (NoSuchMethodException e) { System.out.println( "Skipping non-settable property " + property.getName() + " on " + so.getClass().getName()); continue; } Object newVal; // don't init here so compiler can warn if the following code doesn't always give it a value if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { if (oldVal != null) { newVal = ((Integer) oldVal) + 1; } else { newVal = 1; } } else if (property.getPropertyType() == String.class) { // make sure it's unique newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.TYPE || property.getPropertyType() == Boolean.class) { if (oldVal == null) { newVal = Boolean.TRUE; } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == SQLCatalog.class) { newVal = new SQLCatalog(new SQLDatabase(), "This is a new catalog"); } else if (property.getPropertyType() == SPDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1"); } else if (property.getPropertyType() == JDBCDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1"); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); } else if (property.getPropertyType() == SQLColumn.class) { newVal = new SQLColumn(); } else if (property.getPropertyType() == SQLIndex.class) { newVal = new SQLIndex(); } else if (property.getPropertyType() == SQLRelationship.SQLImportedKey.class) { SQLRelationship rel = new SQLRelationship(); newVal = rel.getForeignKey(); } else if (property.getPropertyType() == SQLRelationship.Deferrability.class) { if (oldVal == SQLRelationship.Deferrability.INITIALLY_DEFERRED) { newVal = SQLRelationship.Deferrability.NOT_DEFERRABLE; } else { newVal = SQLRelationship.Deferrability.INITIALLY_DEFERRED; } } else if (property.getPropertyType() == SQLRelationship.UpdateDeleteRule.class) { if (oldVal == SQLRelationship.UpdateDeleteRule.CASCADE) { newVal = SQLRelationship.UpdateDeleteRule.RESTRICT; } else { newVal = SQLRelationship.UpdateDeleteRule.CASCADE; } } else if (property.getPropertyType() == SQLIndex.AscendDescend.class) { if (oldVal == SQLIndex.AscendDescend.ASCENDING) { newVal = SQLIndex.AscendDescend.DESCENDING; } else { newVal = SQLIndex.AscendDescend.ASCENDING; } } else if (property.getPropertyType() == Throwable.class) { newVal = new Throwable(); } else if (property.getPropertyType() == BasicSQLType.class) { if (oldVal != BasicSQLType.OTHER) { newVal = BasicSQLType.OTHER; } else { newVal = BasicSQLType.TEXT; } } else if (property.getPropertyType() == UserDefinedSQLType.class) { newVal = new UserDefinedSQLType(); } else if (property.getPropertyType() == SQLTypeConstraint.class) { if (oldVal != SQLTypeConstraint.NONE) { newVal = SQLTypeConstraint.NONE; } else { newVal = SQLTypeConstraint.CHECK; } } else if (property.getPropertyType() == String[].class) { newVal = new String[3]; } else if (property.getPropertyType() == PropertyType.class) { if (oldVal != PropertyType.NOT_APPLICABLE) { newVal = PropertyType.NOT_APPLICABLE; } else { newVal = PropertyType.VARIABLE; } } else if (property.getPropertyType() == List.class) { newVal = Arrays.asList("one", "two"); } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") from " + so.getClass() + " on property " + property.getDisplayName()); } int oldChangeCount = listener.getChangedCount(); try { System.out.println("Setting property '" + property.getName() + "' to '" + newVal + "' (" + newVal.getClass().getName() + ")"); BeanUtils.copyProperty(so, property.getName(), newVal); // some setters fire multiple events (they change more than one property) assertTrue( "Event for set " + property.getName() + " on " + so.getClass().getName() + " didn't fire!", listener.getChangedCount() > oldChangeCount); if (listener.getChangedCount() == oldChangeCount + 1) { assertEquals("Property name mismatch for " + property.getName() + " in " + so.getClass(), property.getName(), ((PropertyChangeEvent) listener.getLastEvent()).getPropertyName()); assertEquals("New value for " + property.getName() + " was wrong", newVal, ((PropertyChangeEvent) listener.getLastEvent()).getNewValue()); } } catch (InvocationTargetException e) { System.out.println("(non-fatal) Failed to write property '" + property.getName() + " to type " + so.getClass().getName()); } } }
From source file:nz.co.senanque.validationengine.ConvertUtils.java
public static Object getObjectForNull(Class<?> clazz) { if (clazz.equals(Long.TYPE)) { return new Long(0); } else if (clazz.equals(Integer.TYPE)) { return new Integer(0); } else if (clazz.equals(Float.TYPE)) { return new Float(0.0F); } else if (clazz.equals(Double.TYPE)) { return new Double(0.0D); } else if (clazz.equals(Boolean.TYPE)) { return new Boolean(false); }//from w w w .ja v a2 s. co m return null; }
From source file:com.nfwork.dbfound.json.JSONDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable; assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable; assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable; assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable; assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable; assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable; assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable; assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable;//from w ww .java 2 s . c o m } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }
From source file:net.sourceforge.pmd.lang.java.ast.Java10Test.java
@Test public void testForLoopEnhancedWithVar2() { ASTCompilationUnit compilationUnit = ParserTstUtil.parseAndTypeResolveJava("10", loadSource("LocalVariableTypeInferenceForLoopEnhanced2.java")); List<ASTLocalVariableDeclaration> localVars = compilationUnit .findDescendantsOfType(ASTLocalVariableDeclaration.class); assertEquals(4, localVars.size());//from w ww .java2 s . c om assertNull(localVars.get(1).getTypeNode()); ASTVariableDeclarator varDecl2 = localVars.get(1).getFirstChildOfType(ASTVariableDeclarator.class); assertSame("type should be String", String.class, varDecl2.getType()); ASTVariableDeclaratorId varId2 = varDecl2.getFirstChildOfType(ASTVariableDeclaratorId.class); assertSame("type should be String", String.class, varId2.getType()); assertNull(localVars.get(3).getTypeNode()); ASTVariableDeclarator varDecl4 = localVars.get(3).getFirstChildOfType(ASTVariableDeclarator.class); assertSame("type should be int", Integer.TYPE, varDecl4.getType()); }