List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:org.apache.struts.action.DynaActionForm.java
/** * <p>Indicates if an object of the source class is assignable to the * destination class.</p>//from w ww . ja v a2 s .c o m * * @param dest Destination class * @param source Source class * @return <code>true</code> if the source is assignable to the * destination; <code>false</code> otherwise. */ protected boolean isDynaAssignable(Class dest, Class source) { if (dest.isAssignableFrom(source) || ((dest == Boolean.TYPE) && (source == Boolean.class)) || ((dest == Byte.TYPE) && (source == Byte.class)) || ((dest == Character.TYPE) && (source == Character.class)) || ((dest == Double.TYPE) && (source == Double.class)) || ((dest == Float.TYPE) && (source == Float.class)) || ((dest == Integer.TYPE) && (source == Integer.class)) || ((dest == Long.TYPE) && (source == Long.class)) || ((dest == Short.TYPE) && (source == Short.class))) { return (true); } else { return (false); } }
From source file:ResultSetIterator.java
/** * ResultSet.getObject() returns an Integer object for an INT column. The * setter method for the property might take an Integer or a primitive int. * This method returns true if the value can be successfully passed into * the setter method. Remember, Method.invoke() handles the unwrapping * of Integer into an int.//from w w w. j av a 2s . c o m * * @param value The value to be passed into the setter method. * @param type The setter's parameter type. * @return boolean True if the value is compatible. */ private boolean isCompatibleType(Object value, Class type) { // Do object check first, then primitives if (value == null || type.isInstance(value)) { return true; } else if (type.equals(Integer.TYPE) && Integer.class.isInstance(value)) { return true; } else if (type.equals(Long.TYPE) && Long.class.isInstance(value)) { return true; } else if (type.equals(Double.TYPE) && Double.class.isInstance(value)) { return true; } else if (type.equals(Float.TYPE) && Float.class.isInstance(value)) { return true; } else if (type.equals(Short.TYPE) && Short.class.isInstance(value)) { return true; } else if (type.equals(Byte.TYPE) && Byte.class.isInstance(value)) { return true; } else if (type.equals(Character.TYPE) && Character.class.isInstance(value)) { return true; } else if (type.equals(Boolean.TYPE) && Boolean.class.isInstance(value)) { return true; } else { return false; } }
From source file:com.aliyun.fs.oss.utils.OSSClientAgent.java
@SuppressWarnings("unchecked") private UploadPartResult uploadPart(String uploadId, String bucket, String key, Long partSize, Long beginIndex, int partNumber, File file, Configuration conf, boolean retry) throws IOException, ServiceException, ClientException { InputStream instream = null;// w ww. j av a 2 s.co m try { instream = new FileInputStream(file); instream.skip(beginIndex); Class UploadPartRequestClz = ResourceLoader.getInstance().getUrlClassLoader(conf) .loadClass("com.aliyun.oss.model.UploadPartRequest"); Constructor cons = UploadPartRequestClz.getConstructor(); Object uploadPartRequest = cons.newInstance(); Method method0 = UploadPartRequestClz.getMethod("setBucketName", String.class); method0.invoke(uploadPartRequest, bucket); Method method1 = UploadPartRequestClz.getMethod("setKey", String.class); method1.invoke(uploadPartRequest, key); Method method2 = UploadPartRequestClz.getMethod("setUploadId", String.class); method2.invoke(uploadPartRequest, uploadId); Method method3 = UploadPartRequestClz.getMethod("setInputStream", InputStream.class); method3.invoke(uploadPartRequest, instream); Method method4 = UploadPartRequestClz.getMethod("setPartSize", Long.TYPE); method4.invoke(uploadPartRequest, partSize); Method method5 = UploadPartRequestClz.getMethod("setPartNumber", Integer.TYPE); method5.invoke(uploadPartRequest, partNumber); Method method = this.ossClientClz.getMethod("uploadPart", UploadPartRequestClz); Object ret = method.invoke(this.ossClient, uploadPartRequest); return gson.fromJson(gson.toJson(ret), UploadPartResult.class); } catch (Exception e) { if (retry && updateOSSClient(e)) { return uploadPart(uploadId, bucket, key, partSize, beginIndex, partNumber, file, conf, false); } else { handleException(e); return null; } } finally { if (instream != null) { try { instream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.sun.faces.config.ManagedBeanFactory.java
/** * <li><p> Call the property getter, if it exists.</p></li> * <p/>/*from w w w .j a v a2 s. com*/ * <li><p>If the getter returns null or doesn't exist, create a * java.util.ArrayList(), otherwise use the returned Object (an array or * a java.util.List).</p></li> * <p/> * <li><p>If a List was returned or created in step 2), add all * elements defined by nested <value> elements in the order * they are listed, converting values defined by nested * <value> elements to the type defined by * <value-class>. If a <value-class> is not defined, use * the value as-is (i.e., as a java.lang.String). Add null for each * <null-value> element.</p></li> * <p/> * <li><p> If an array was returned in step 2), create a * java.util.ArrayList and copy all elements from the returned array to * the new List, auto-boxing elements of a primitive type. Add all * elements defined by nested <value> elements as described in step * 3).</p></li> * <p/> * <li><p> If a new java.util.List was created in step 2) and the * property is of type List, set the property by calling the setter * method, or log an error if there is no setter method.</p></li> * <p/> * <li><p> If a new java.util.List was created in step 4), convert * the * List to array of the same type as the property and set the * property by * calling the setter method, or log an error if there * is no setter * method.</p></li> */ private void setArrayOrListPropertiesIntoBean(Object bean, ManagedPropertyBean property) throws Exception { Object result = null; boolean getterIsNull = true, getterIsArray = false; List valuesForBean = null; Class valueType = java.lang.String.class, propertyType = null; String propertyName = property.getPropertyName(); try { // see if there is a getter result = PropertyUtils.getProperty(bean, propertyName); getterIsNull = (null == result) ? true : false; propertyType = PropertyUtils.getPropertyType(bean, propertyName); getterIsArray = propertyType.isArray(); } catch (NoSuchMethodException nsme) { // it's valid to not have a getter. } // the property has to be either a List or Array if (!getterIsArray) { if (null != propertyType && !java.util.List.class.isAssignableFrom(propertyType)) { throw new FacesException( Util.getExceptionMessageString(Util.MANAGED_BEAN_CANNOT_SET_LIST_ARRAY_PROPERTY_ID, new Object[] { propertyName, managedBean.getManagedBeanName() })); } } // // Deal with the possibility of the getter returning existing // values. // // if the getter returned non-null if (!getterIsNull) { // if what it returned was an array if (getterIsArray) { valuesForBean = new ArrayList(); for (int i = 0, len = Array.getLength(result); i < len; i++) { // add the existing values valuesForBean.add(Array.get(result, i)); } } else { // if what it returned was not a List if (!(result instanceof List)) { // throw an exception throw new FacesException( Util.getExceptionMessageString(Util.MANAGED_BEAN_EXISTING_VALUE_NOT_LIST_ID, new Object[] { propertyName, managedBean.getManagedBeanName() })); } valuesForBean = (List) result; } } else { // getter returned null result = valuesForBean = new ArrayList(); } // at this point valuesForBean contains the existing values from // the bean, or no values if the bean had no values. In any // case, we can proceed to add values from the config file. valueType = copyListEntriesFromConfigToList(property.getListEntries(), valuesForBean); // at this point valuesForBean has the values to be set into the // bean. if (getterIsArray) { // convert back to Array result = Array.newInstance(valueType, valuesForBean.size()); for (int i = 0, len = valuesForBean.size(); i < len; i++) { if (valueType == Boolean.TYPE) { Array.setBoolean(result, i, ((Boolean) valuesForBean.get(i)).booleanValue()); } else if (valueType == Byte.TYPE) { Array.setByte(result, i, ((Byte) valuesForBean.get(i)).byteValue()); } else if (valueType == Double.TYPE) { Array.setDouble(result, i, ((Double) valuesForBean.get(i)).doubleValue()); } else if (valueType == Float.TYPE) { Array.setFloat(result, i, ((Float) valuesForBean.get(i)).floatValue()); } else if (valueType == Integer.TYPE) { Array.setInt(result, i, ((Integer) valuesForBean.get(i)).intValue()); } else if (valueType == Character.TYPE) { Array.setChar(result, i, ((Character) valuesForBean.get(i)).charValue()); } else if (valueType == Short.TYPE) { Array.setShort(result, i, ((Short) valuesForBean.get(i)).shortValue()); } else if (valueType == Long.TYPE) { Array.setLong(result, i, ((Long) valuesForBean.get(i)).longValue()); } else { Array.set(result, i, valuesForBean.get(i)); } } } else { result = valuesForBean; } if (getterIsNull || getterIsArray) { PropertyUtils.setProperty(bean, propertyName, result); } }
From source file:net.sourceforge.pmd.typeresolution.ClassTypeResolverTest.java
@Test public void testAssignmentOperators() throws JaxenException { ASTCompilationUnit acu = parseAndTypeResolveForClass15(Operators.class); List<ASTStatementExpression> expressions = convertList(acu.findChildNodesWithXPath( "//Block[preceding-sibling::MethodDeclarator[@Image = 'assignmentOperators']]//StatementExpression"), ASTStatementExpression.class); int index = 0; assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); assertEquals(Long.TYPE, expressions.get(index++).getType()); // Make sure we got them all. assertEquals("All expressions not tested", index, expressions.size()); }
From source file:javadz.beanutils.LazyDynaBean.java
/** * Create a new Instance of a 'Primitive' Property. * @param name The name of the property/*from ww w .ja v a 2 s.c o m*/ * @param type The class of the property * @return The new value */ protected Object createPrimitiveProperty(String name, Class type) { if (type == Boolean.TYPE) { return Boolean.FALSE; } else if (type == Integer.TYPE) { return Integer_ZERO; } else if (type == Long.TYPE) { return Long_ZERO; } else if (type == Double.TYPE) { return Double_ZERO; } else if (type == Float.TYPE) { return Float_ZERO; } else if (type == Byte.TYPE) { return Byte_ZERO; } else if (type == Short.TYPE) { return Short_ZERO; } else if (type == Character.TYPE) { return Character_SPACE; } else { return null; } }
From source file:net.ravendb.client.connection.ServerClient.java
protected Operation directDeleteByIndex(OperationMetadata operationMetadata, String indexName, IndexQuery queryToDelete, BulkOperationOptions options) { BulkOperationOptions notNullOptions = (options != null) ? options : new BulkOperationOptions(); String path = queryToDelete.getIndexQueryUrl(operationMetadata.getUrl(), indexName, "bulk_docs") + "&allowStale=" + notNullOptions.isAllowStale() + "&details=" + notNullOptions.isRetrieveDetails(); if (notNullOptions.getMaxOpsPerSec() != null) { path += "&maxOpsPerSec=" + notNullOptions.getMaxOpsPerSec(); }//from www . ja v a2 s. c o m if (notNullOptions.getStaleTimeout() != null) { path += "&staleTimeout=" + notNullOptions.getStaleTimeout(); } try (HttpJsonRequest request = jsonRequestFactory .createHttpJsonRequest(new CreateHttpJsonRequestParams(this, path, HttpMethods.DELETE, new RavenJObject(), operationMetadata.getCredentials(), convention) .addOperationHeaders(operationsHeaders)) .addReplicationStatusHeaders(url, operationMetadata.getUrl(), replicationInformer, convention.getFailoverBehavior(), new HandleReplicationStatusChangesCallback())) { RavenJToken jsonResponse; try { jsonResponse = request.readResponseJson(); } catch (ErrorResponseException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new IllegalStateException("There is no index named: " + indexName); } throw e; } if (jsonResponse == null || jsonResponse.getType() != JTokenType.OBJECT) { return null; } RavenJToken opId = ((RavenJObject) jsonResponse).get("OperationId"); if (opId == null || opId.getType() != JTokenType.INTEGER) { return null; } return new Operation(this, opId.value(Long.TYPE)); } }
From source file:objenome.util.ClassUtils.java
/** * <p>Checks if one {@code Class} can be assigned to a variable of * another {@code Class}.</p>/* w w w.j a v a2 s . co m*/ * * <p>Unlike the {@link Class#isAssignableFrom(Class)} method, * this method takes into account widenings of primitive classes and * {@code null}s.</p> * * <p>Primitive widenings allow an int to be assigned to a long, float or * double. This method returns the correct result for these cases.</p> * * <p>{@code Null} may be assigned to any reference type. This method * will return {@code true} if {@code null} is passed in and the * toClass is non-primitive.</p> * * <p>Specifically, this method tests whether the type represented by the * specified {@code Class} parameter can be converted to the type * represented by this {@code Class} object via an identity conversion * widening primitive or widening reference conversion. See * <em><a href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>, * sections 5.1.1, 5.1.2 and 5.1.4 for details.</p> * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @param autoboxing whether to use implicit autoboxing/unboxing between primitives and wrappers * @return {@code true} if assignment possible */ public static boolean isAssignable(Class<?> cls, Class<?> toClass, boolean autoboxing) { if (toClass == null) { return false; } // have to check for null, as isAssignableFrom doesn't if (cls == null) { return !toClass.isPrimitive(); } //autoboxing: if (autoboxing) { if (cls.isPrimitive() && !toClass.isPrimitive()) { cls = primitiveToWrapper(cls); if (cls == null) { return false; } } if (toClass.isPrimitive() && !cls.isPrimitive()) { cls = wrapperToPrimitive(cls); if (cls == null) { return false; } } } if (cls.equals(toClass)) { return true; } if (cls.isPrimitive()) { if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(cls)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(cls)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(cls)) { return false; } if (Double.TYPE.equals(cls)) { return false; } if (Float.TYPE.equals(cls)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(cls)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(cls)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(cls); }
From source file:com.sun.faces.config.ManagedBeanFactory.java
private Class getValueClassConsideringPrimitives(String valueClass) throws ClassNotFoundException { Class valueType = java.lang.String.class; if (null != valueClass && 0 < valueClass.length()) { if (valueClass.equals(Boolean.TYPE.getName())) { valueType = Boolean.TYPE; } else if (valueClass.equals(Byte.TYPE.getName())) { valueType = Byte.TYPE; } else if (valueClass.equals(Double.TYPE.getName())) { valueType = Double.TYPE; } else if (valueClass.equals(Float.TYPE.getName())) { valueType = Float.TYPE; } else if (valueClass.equals(Integer.TYPE.getName())) { valueType = Integer.TYPE; } else if (valueClass.equals(Character.TYPE.getName())) { valueType = Character.TYPE; } else if (valueClass.equals(Short.TYPE.getName())) { valueType = Short.TYPE; } else if (valueClass.equals(Long.TYPE.getName())) { valueType = Long.TYPE; } else {/*from w w w . j a va2s. co m*/ valueType = Util.loadClass(valueClass, this); } } return valueType; }