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.evosuite.testcase.TestCodeVisitor.java
private String getParameterStringForFMthatReturnPrimitive(Class<?> returnType, List<VariableReference> parameters) { assert returnType.isPrimitive(); String parameterString = ""; for (int i = 0; i < parameters.size(); i++) { if (i > 0) { parameterString += ", "; }//from w ww. j a v a 2s. c om String name = getVariableName(parameters.get(i)); Class<?> parameterType = parameters.get(i).getVariableClass(); if (returnType.equals(parameterType)) { parameterString += name; continue; } GenericClass parameterClass = new GenericClass(parameterType); if (parameterClass.isWrapperType()) { boolean isRightWrapper = false; if (Integer.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Integer.TYPE); } else if (Character.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Character.TYPE); } else if (Boolean.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Boolean.TYPE); } else if (Float.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Float.TYPE); } else if (Double.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Double.TYPE); } else if (Long.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Long.TYPE); } else if (Short.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Short.TYPE); } else if (Byte.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Byte.TYPE); } if (isRightWrapper) { parameterString += name; continue; } } //if we arrive here, it means types are different and not a right wrapper (eg Integer for int) parameterString += "(" + returnType.getName() + ")" + name; if (parameterClass.isWrapperType()) { if (Integer.class.equals(parameterClass.getRawClass())) { parameterString += ".intValue()"; } else if (Character.class.equals(parameterClass.getRawClass())) { parameterString += ".charValue()"; } else if (Boolean.class.equals(parameterClass.getRawClass())) { parameterString += ".booleanValue()"; } else if (Float.class.equals(parameterClass.getRawClass())) { parameterString += ".floatValue()"; } else if (Double.class.equals(parameterClass.getRawClass())) { parameterString += ".doubleValue()"; } else if (Long.class.equals(parameterClass.getRawClass())) { parameterString += ".longValue()"; } else if (Short.class.equals(parameterClass.getRawClass())) { parameterString += ".shortValue()"; } else if (Byte.class.equals(parameterClass.getRawClass())) { parameterString += ".byteValue()"; } } } return parameterString; }
From source file:net.ravendb.client.connection.ServerClient.java
@SuppressWarnings("boxing") long directSeedIdentityFor(OperationMetadata operationMetadata, String name, long value) { try (HttpJsonRequest request = jsonRequestFactory .createHttpJsonRequest(new CreateHttpJsonRequestParams(this, operationMetadata.getUrl() + "/identity/seed?name=" + UrlUtils.escapeDataString(name) + "&value=" + value, HttpMethods.POST, new RavenJObject(), operationMetadata.getCredentials(), convention) .addOperationHeaders(operationsHeaders))) { RavenJToken readResponseJson = request.readResponseJson(); return readResponseJson.value(Long.TYPE, "Value"); }//w w w .j a v a 2 s . c o m }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.8 *//*from ww w.j av a2 s . co m*/ private Class<?> unbox(Class<?> sourceType) { if (sourceType == java.lang.Boolean.class) { return java.lang.Boolean.TYPE; } else if (sourceType == java.lang.Byte.class) { return java.lang.Byte.TYPE; } else if (sourceType == java.lang.Short.class) { return java.lang.Short.TYPE; } else if (sourceType == java.lang.Character.class) { return java.lang.Character.TYPE; } else if (sourceType == java.lang.Integer.class) { return java.lang.Integer.TYPE; } else if (sourceType == java.lang.Long.class) { return java.lang.Long.TYPE; } else if (sourceType == java.lang.Float.class) { return java.lang.Float.TYPE; } else if (sourceType == java.lang.Double.class) { return java.lang.Double.TYPE; } else { return null; } }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.FileHarvester.java
private void initializeTika(HarvestContext context, SourcePojo source) { AutoDetectParser autoDetectParser = new AutoDetectParser(); if (null != source.getFileConfig().XmlRootLevelValues) { for (String s : source.getFileConfig().XmlRootLevelValues) { int separator = s.indexOf(':'); String jsonStr = s.substring(separator + 1); if (separator > 0) { String mediaType = s.substring(0, separator); if (mediaType.equalsIgnoreCase("output")) { //special case, just going to configure output if (jsonStr.equalsIgnoreCase("xml") || jsonStr.equalsIgnoreCase("xhtml")) { _tikaXmlFormatWriter = new StringWriter(); _tikaOutputFormat = getTransformerHandler("xml", _tikaXmlFormatWriter); _tikaOutputParseContext = new ParseContext(); }/* w w w. j av a2s. co m*/ if (jsonStr.equalsIgnoreCase("html")) { _tikaXmlFormatWriter = new StringWriter(); _tikaOutputFormat = getTransformerHandler("html", _tikaXmlFormatWriter); _tikaOutputParseContext = new ParseContext(); } continue; } //TESTED else if (mediaType.equalsIgnoreCase("bypass")) { Map<MediaType, Parser> parsers = autoDetectParser.getParsers(); parsers.put(MediaType.parse(jsonStr), new TXTParser()); autoDetectParser.setParsers(parsers); continue; } // Try to get media type parser: Parser p = autoDetectParser.getParsers().get(MediaType.parse(mediaType)); while (p instanceof CompositeParser) { p = ((CompositeParser) p).getParsers().get(MediaType.parse(mediaType)); } if (null == p) { context.getHarvestStatus().logMessage( "Failed to find application type " + mediaType + " in tika option: " + s, true); continue; } //TESTED // Get JSON objects and try to apply try { JsonElement jsonObj = new JsonParser().parse(jsonStr); for (Map.Entry<String, JsonElement> keyVal : jsonObj.getAsJsonObject().entrySet()) { if (keyVal.getValue().getAsJsonPrimitive().isBoolean()) { //boolean try { Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.class); method.invoke(p, (Boolean) keyVal.getValue().getAsJsonPrimitive().getAsBoolean()); } catch (Exception e) { try { Method method = p.getClass().getMethod(keyVal.getKey(), Boolean.TYPE); method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsBoolean()); } catch (Exception e2) { context.getHarvestStatus().logMessage( "Failed to invoke " + keyVal.getKey() + " in tika option: " + s, true); continue; } //TESTED } } //TESTED if (keyVal.getValue().getAsJsonPrimitive().isString()) { //string try { Method method = p.getClass().getMethod(keyVal.getKey(), String.class); method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsString()); } catch (Exception e) { context.getHarvestStatus().logMessage( "Failed to invoke " + keyVal.getKey() + " in tika option: " + s, true); continue; } } //TESTED (cut and paste) if (keyVal.getValue().getAsJsonPrimitive().isNumber()) { // number: int/long/double // Loads of options: Integer.class, Integer.TYPE, Long.class, Long.TYPE, Double.long, Double.TYPE boolean invoked = false; if (!invoked) { // Int.class try { Method method = p.getClass().getMethod(keyVal.getKey(), Integer.class); method.invoke(p, (Integer) keyVal.getValue().getAsJsonPrimitive().getAsInt()); invoked = true; } catch (Exception e) { } } if (!invoked) { // Int.type try { Method method = p.getClass().getMethod(keyVal.getKey(), Integer.TYPE); method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsInt()); invoked = true; } catch (Exception e) { } } if (!invoked) { // Long.class try { Method method = p.getClass().getMethod(keyVal.getKey(), Long.class); method.invoke(p, (Long) keyVal.getValue().getAsJsonPrimitive().getAsLong()); invoked = true; } catch (Exception e) { } } if (!invoked) { // Long.type try { Method method = p.getClass().getMethod(keyVal.getKey(), Long.TYPE); method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsLong()); invoked = true; } catch (Exception e) { } } if (!invoked) { // Double.class try { Method method = p.getClass().getMethod(keyVal.getKey(), Double.class); method.invoke(p, (Double) keyVal.getValue().getAsJsonPrimitive().getAsDouble()); invoked = true; } catch (Exception e) { } } if (!invoked) { // Double.type try { Method method = p.getClass().getMethod(keyVal.getKey(), Double.TYPE); method.invoke(p, keyVal.getValue().getAsJsonPrimitive().getAsDouble()); invoked = true; } catch (Exception e) { } } } //TOTEST (all the different options) } //(end loop over options) } catch (Exception e) { context.getHarvestStatus().logMessage("Failed to parse JSON in tika option: " + s, true); } //TESTED } else { context.getHarvestStatus().logMessage("Failed to parse tika option: " + s, true); } //TESTED } //TESTED } //(end if has options) _tika = new Tika(TikaConfig.getDefaultConfig().getDetector(), autoDetectParser); }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.7 *//*from w ww . j a v a 2s .c om*/ private Class<?> box(Class<?> sourceType) { if (sourceType.isPrimitive()) { if (sourceType == java.lang.Boolean.TYPE) { return java.lang.Boolean.class; } else if (sourceType == java.lang.Byte.TYPE) { return java.lang.Byte.class; } else if (sourceType == java.lang.Short.TYPE) { return java.lang.Short.class; } else if (sourceType == java.lang.Character.TYPE) { return java.lang.Character.class; } else if (sourceType == java.lang.Integer.TYPE) { return java.lang.Integer.class; } else if (sourceType == java.lang.Long.TYPE) { return java.lang.Long.class; } else if (sourceType == java.lang.Float.TYPE) { return java.lang.Float.class; } else if (sourceType == java.lang.Double.TYPE) { return java.lang.Double.class; } return null; // Should never be reached because all primitives are accounted for above. } else { throw new IllegalArgumentException("Cannot box a type that is not a primitive."); } }
From source file:net.ravendb.client.connection.ServerClient.java
protected Operation directUpdateByIndexImpl(OperationMetadata operationMetadata, String indexName, IndexQuery queryToUpdate, BulkOperationOptions options, String requestData, HttpMethods method) { BulkOperationOptions notNullOptions = (options != null) ? options : new BulkOperationOptions(); String path = queryToUpdate.getIndexQueryUrl(operationMetadata.getUrl(), indexName, "bulk_docs") + "&allowStale=" + notNullOptions.isAllowStale() + "&maxOpsPerSec=" + notNullOptions.getMaxOpsPerSec() + "&details=" + notNullOptions.isRetrieveDetails(); if (notNullOptions.getStaleTimeout() != null) { path += "&staleTimeout=" + notNullOptions.getStaleTimeout(); }/* w w w . j a v a 2 s . c om*/ try (HttpJsonRequest request = jsonRequestFactory .createHttpJsonRequest(new CreateHttpJsonRequestParams(this, path, method, new RavenJObject(), operationMetadata.getCredentials(), convention).addOperationHeaders(operationsHeaders)) .addReplicationStatusHeaders(url, operationMetadata.getUrl(), replicationInformer, convention.getFailoverBehavior(), new HandleReplicationStatusChangesCallback())) { RavenJToken jsonResponse; try { request.write(requestData); jsonResponse = request.readResponseJson(); } catch (ErrorResponseException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new IllegalStateException("There is no index named: " + indexName); } throw e; } return new Operation(this, jsonResponse.value(Long.TYPE, "OperationId")); } }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return true iff {@sourceType} can be converted by a widening primitive conversion * following Java Language Specification, 3rd Ed, s5.1.2 *///w w w . j a v a 2s. c o m private boolean isConvertibleToByWideningPrimitive(Class<?> sourceType, Class<?> destType) { // Widening conversion following Java Language Specification, s5.1.2. if (sourceType == java.lang.Byte.TYPE) { return destType == java.lang.Short.TYPE || destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Short.TYPE) { return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Character.TYPE) { return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Integer.TYPE) { return destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Long.TYPE) { return destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Float.TYPE) { return destType == java.lang.Double.TYPE; } return false; }
From source file:org.apache.myfaces.ov2021.application.ApplicationImpl.java
@SuppressWarnings("unchecked") private Converter internalCreateConverter(final Class<?> targetClass) { // Locate a Converter registered for the target class itself. Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass); // Locate a Converter registered for interfaces that are // implemented by the target class (directly or indirectly). // Skip if class is String, for performance reasons // (save 3 additional lookups over a concurrent map per request). if (converterClassOrClassName == null && !String.class.equals(targetClass)) { final Class<?> interfaces[] = targetClass.getInterfaces(); if (interfaces != null) { for (int i = 0, len = interfaces.length; i < len; i++) { // search all superinterfaces for a matching converter, // create it final Converter converter = internalCreateConverter(interfaces[i]); if (converter != null) { return converter; }/*from w w w . jav a2 s . c om*/ } } } // Get EnumConverter for enum classes with no special converter, check // here as recursive call with java.lang.Enum will not work if (converterClassOrClassName == null && targetClass.isEnum()) { converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class); } if (converterClassOrClassName != null) { try { Class<? extends Converter> converterClass = null; if (converterClassOrClassName instanceof Class<?>) { converterClass = (Class<? extends Converter>) converterClassOrClassName; } else if (converterClassOrClassName instanceof String) { converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName); _converterTargetClassToConverterClassMap.put(targetClass, converterClass); } else { //object stored in the map for this id is an invalid type. remove it and return null _converterTargetClassToConverterClassMap.remove(targetClass); } Converter converter = null; // check cached constructor information if (!_noArgConstructorConverterClasses.contains(converterClass)) { // the converter class either supports the one-arg constructor // or has never been processed before try { // look for a constructor that takes a single Class object // See JSF 1.2 javadoc for Converter Constructor<? extends Converter> constructor = converterClass .getConstructor(new Class[] { Class.class }); converter = constructor.newInstance(new Object[] { targetClass }); } catch (Exception e) { // the constructor does not exist // add the class to the no-arg constructor classes cache _noArgConstructorConverterClasses.add(converterClass); // use no-arg constructor converter = converterClass.newInstance(); } } else { // use no-arg constructor converter = converterClass.newInstance(); } setConverterProperties(converterClass, converter); return converter; } catch (Exception e) { log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e); throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(), e); } } // locate converter for primitive types if (targetClass == Long.TYPE) { return internalCreateConverter(Long.class); } else if (targetClass == Boolean.TYPE) { return internalCreateConverter(Boolean.class); } else if (targetClass == Double.TYPE) { return internalCreateConverter(Double.class); } else if (targetClass == Byte.TYPE) { return internalCreateConverter(Byte.class); } else if (targetClass == Short.TYPE) { return internalCreateConverter(Short.class); } else if (targetClass == Integer.TYPE) { return internalCreateConverter(Integer.class); } else if (targetClass == Float.TYPE) { return internalCreateConverter(Float.class); } else if (targetClass == Character.TYPE) { return internalCreateConverter(Character.class); } // Locate a Converter registered for the superclass (if any) of the // target class, // recursively working up the inheritance hierarchy. Class<?> superClazz = targetClass.getSuperclass(); return superClazz != null ? internalCreateConverter(superClazz) : null; }
From source file:org.apache.myfaces.application.ApplicationImpl.java
@SuppressWarnings("unchecked") private Converter internalCreateConverter(final Class<?> targetClass) { // Locate a Converter registered for the target class itself. Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass); // Locate a Converter registered for interfaces that are // implemented by the target class (directly or indirectly). // Skip if class is String, for performance reasons // (save 3 additional lookups over a concurrent map per request). if (converterClassOrClassName == null && !String.class.equals(targetClass)) { final Class<?> interfaces[] = targetClass.getInterfaces(); if (interfaces != null) { for (int i = 0, len = interfaces.length; i < len; i++) { // search all superinterfaces for a matching converter, // create it final Converter converter = internalCreateConverter(interfaces[i]); if (converter != null) { return converter; }/*ww w .j a v a2s . co m*/ } } } // Get EnumConverter for enum classes with no special converter, check // here as recursive call with java.lang.Enum will not work if (converterClassOrClassName == null && targetClass.isEnum()) { converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class); } if (converterClassOrClassName != null) { try { Class<? extends Converter> converterClass = null; if (converterClassOrClassName instanceof Class<?>) { converterClass = (Class<? extends Converter>) converterClassOrClassName; } else if (converterClassOrClassName instanceof String) { converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName); _converterTargetClassToConverterClassMap.put(targetClass, converterClass); } else { //object stored in the map for this id is an invalid type. remove it and return null _converterTargetClassToConverterClassMap.remove(targetClass); } Converter converter = null; // check cached constructor information if (!_noArgConstructorConverterClasses.contains(converterClass)) { // the converter class either supports the one-arg constructor // or has never been processed before try { // look for a constructor that takes a single Class object // See JSF 1.2 javadoc for Converter Constructor<? extends Converter> constructor = converterClass .getConstructor(new Class[] { Class.class }); converter = constructor.newInstance(new Object[] { targetClass }); } catch (Exception e) { // the constructor does not exist // add the class to the no-arg constructor classes cache _noArgConstructorConverterClasses.add(converterClass); // use no-arg constructor converter = createConverterInstance(converterClass); } } else { // use no-arg constructor converter = createConverterInstance(converterClass); } setConverterProperties(converterClass, converter); return converter; } catch (Exception e) { log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e); throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(), e); } } // locate converter for primitive types if (targetClass == Long.TYPE) { return internalCreateConverter(Long.class); } else if (targetClass == Boolean.TYPE) { return internalCreateConverter(Boolean.class); } else if (targetClass == Double.TYPE) { return internalCreateConverter(Double.class); } else if (targetClass == Byte.TYPE) { return internalCreateConverter(Byte.class); } else if (targetClass == Short.TYPE) { return internalCreateConverter(Short.class); } else if (targetClass == Integer.TYPE) { return internalCreateConverter(Integer.class); } else if (targetClass == Float.TYPE) { return internalCreateConverter(Float.class); } else if (targetClass == Character.TYPE) { return internalCreateConverter(Character.class); } // Locate a Converter registered for the superclass (if any) of the // target class, // recursively working up the inheritance hierarchy. Class<?> superClazz = targetClass.getSuperclass(); return superClazz != null ? internalCreateConverter(superClazz) : null; }
From source file:org.evosuite.testcase.TestFactory.java
private List<VariableReference> getCandidatesForReuse(TestCase test, Type parameterType, int position, VariableReference exclude, boolean allowNull, boolean canUseMocks) { //look at all vars defined before pos List<VariableReference> objects = test.getObjects(parameterType, position); //if an exclude var was specified, then remove it if (exclude != null) { objects.remove(exclude);/* w w w .j a v a 2 s.co m*/ if (exclude.getAdditionalVariableReference() != null) objects.remove(exclude.getAdditionalVariableReference()); Iterator<VariableReference> it = objects.iterator(); while (it.hasNext()) { VariableReference v = it.next(); if (exclude.equals(v.getAdditionalVariableReference())) it.remove(); } } List<VariableReference> additionalToRemove = new ArrayList<>(); //no mock should be used more than once Iterator<VariableReference> iter = objects.iterator(); while (iter.hasNext()) { VariableReference ref = iter.next(); if (!(test.getStatement(ref.getStPosition()) instanceof FunctionalMockStatement)) { continue; } //check if current mock var is used anywhere: if so, then we cannot choose it for (int i = ref.getStPosition() + 1; i < test.size(); i++) { Statement st = test.getStatement(i); if (st.getVariableReferences().contains(ref)) { iter.remove(); additionalToRemove.add(ref); break; } } } //check for null if (!allowNull) { iter = objects.iterator(); while (iter.hasNext()) { VariableReference ref = iter.next(); if (ConstraintHelper.isNull(ref, test)) { iter.remove(); additionalToRemove.add(ref); } } } //check for mocks if (!canUseMocks) { iter = objects.iterator(); while (iter.hasNext()) { VariableReference ref = iter.next(); if (test.getStatement(ref.getStPosition()) instanceof FunctionalMockStatement) { iter.remove(); additionalToRemove.add(ref); } } } //check for bounded variables if (Properties.JEE) { iter = objects.iterator(); while (iter.hasNext()) { VariableReference ref = iter.next(); if (ConstraintHelper.getLastPositionOfBounded(ref, test) >= position) { iter.remove(); additionalToRemove.add(ref); } } } //further remove all other vars that have the deleted ones as additionals iter = objects.iterator(); while (iter.hasNext()) { VariableReference ref = iter.next(); VariableReference additional = ref.getAdditionalVariableReference(); if (additional == null) { continue; } if (additionalToRemove.contains(additional)) { iter.remove(); } } //avoid using characters as values for numeric types arguments iter = objects.iterator(); String parCls = parameterType.getTypeName(); if (Integer.TYPE.getTypeName().equals(parCls) || Long.TYPE.getTypeName().equals(parCls) || Float.TYPE.getTypeName().equals(parCls) || Double.TYPE.getTypeName().equals(parCls)) { while (iter.hasNext()) { VariableReference ref = iter.next(); String cls = ref.getType().getTypeName(); if ((Character.TYPE.getTypeName().equals(cls))) iter.remove(); } } return objects; }