List of usage examples for java.lang Void TYPE
Class TYPE
To view the source code for java.lang Void TYPE.
Click Source Link
From source file:ch.ralscha.extdirectspring.controller.ControllerUtil.java
public static Object sendAndReceive(MockMvc mockMvc, boolean withSession, HttpHeaders headers, List<Cookie> cookies, Map<String, Object> metadata, String bean, String method, boolean namedParameters, Object expectedResultOrType, Object... requestData) { int tid = (int) (Math.random() * 1000); MvcResult result = null;/*from w w w .j ava2s . c o m*/ try { result = performRouterRequest(mockMvc, createEdsRequest(bean, method, namedParameters, tid, requestData, metadata), null, headers, cookies, withSession); } catch (JsonProcessingException e) { fail("perform post to /router" + e.getMessage()); return null; } catch (Exception e) { fail("perform post to /router" + e.getMessage()); return null; } List<ExtDirectResponse> responses = readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse edResponse = responses.get(0); assertThat(edResponse.getAction()).isEqualTo(bean); assertThat(edResponse.getMethod()).isEqualTo(method); assertThat(edResponse.getTid()).isEqualTo(tid); assertThat(edResponse.getWhere()).isNull(); if (expectedResultOrType == null) { assertThat(edResponse.getType()).isEqualTo("exception"); assertThat(edResponse.getResult()).isNull(); assertThat(edResponse.getMessage()).isEqualTo("Server Error"); } else { assertThat(edResponse.getType()).isEqualTo("rpc"); assertThat(edResponse.getMessage()).isNull(); if (expectedResultOrType == Void.TYPE) { assertThat(edResponse.getResult()).isNull(); } else if (expectedResultOrType instanceof Class<?>) { return ControllerUtil.convertValue(edResponse.getResult(), (Class<?>) expectedResultOrType); } else if (expectedResultOrType instanceof TypeReference) { return ControllerUtil.convertValue(edResponse.getResult(), (TypeReference<?>) expectedResultOrType); } else { assertThat(edResponse.getResult()).isEqualTo(expectedResultOrType); } } return edResponse.getResult(); }
From source file:Classes.java
/** * This method acts equivalently to invoking classLoader.loadClass(className) * but it also supports primitive types and array classes of object types or * primitive types./*from w w w. j ava 2 s .co m*/ * * @param className * the qualified name of the class or the name of primitive type or * array in the same format as returned by the * java.lang.Class.getName() method. * @param classLoader * the ClassLoader used to load classes * @return the Class object for the requested className * * @throws ClassNotFoundException * when the <code>classLoader</code> can not find the requested * class */ public static Class loadClass(String className, ClassLoader classLoader) throws ClassNotFoundException { // ClassLoader.loadClass() does not handle primitive types: // // B byte // C char // D double // F float // I int // J long // S short // Z boolean // V void // if (className.length() == 1) { char type = className.charAt(0); if (type == 'B') return Byte.TYPE; if (type == 'C') return Character.TYPE; if (type == 'D') return Double.TYPE; if (type == 'F') return Float.TYPE; if (type == 'I') return Integer.TYPE; if (type == 'J') return Long.TYPE; if (type == 'S') return Short.TYPE; if (type == 'Z') return Boolean.TYPE; if (type == 'V') return Void.TYPE; // else throw... throw new ClassNotFoundException(className); } // Check for a primative type if (isPrimitive(className) == true) return (Class) Classes.PRIMITIVE_NAME_TYPE_MAP.get(className); // Check for the internal vm format: Lclassname; if (className.charAt(0) == 'L' && className.charAt(className.length() - 1) == ';') return classLoader.loadClass(className.substring(1, className.length() - 1)); // first try - be optimistic // this will succeed for all non-array classes and array classes that have // already been resolved // try { return classLoader.loadClass(className); } catch (ClassNotFoundException e) { // if it was non-array class then throw it if (className.charAt(0) != '[') throw e; } // we are now resolving array class for the first time // count opening braces int arrayDimension = 0; while (className.charAt(arrayDimension) == '[') arrayDimension++; // resolve component type - use recursion so that we can resolve primitive // types also Class componentType = loadClass(className.substring(arrayDimension), classLoader); // construct array class return Array.newInstance(componentType, new int[arrayDimension]).getClass(); }
From source file:org.springframework.integration.handler.support.MessagingMethodInvokerHelper.java
private MessagingMethodInvokerHelper(Object targetObject, Class<? extends Annotation> annotationType, Method method, Class<?> expectedType, boolean canProcessMessageList) { this.annotationType = annotationType; this.canProcessMessageList = canProcessMessageList; Assert.notNull(method, "method must not be null"); this.method = method; this.requiresReply = expectedType != null; if (expectedType != null) { Assert.isTrue(method.getReturnType() != Void.class && method.getReturnType() != Void.TYPE, "method must have a return type"); this.expectedType = TypeDescriptor.valueOf(expectedType); } else {// w w w . j a v a 2 s.c o m this.expectedType = null; } Assert.notNull(targetObject, "targetObject must not be null"); this.targetObject = targetObject; try { InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory .createInvocableHandlerMethod(targetObject, method); this.handlerMethod = new HandlerMethod(invocableHandlerMethod, canProcessMessageList); this.defaultHandlerMethod = null; checkSpelInvokerRequired(getTargetClass(targetObject), method, this.handlerMethod); } catch (IneligibleMethodException e) { throw new IllegalArgumentException(e); } this.handlerMethods = null; this.handlerMessageMethods = null; this.handlerMethodsList = null; setDisplayString(targetObject, method); JsonObjectMapper<?, ?> mapper; try { mapper = JsonObjectMapperProvider.newInstance(); } catch (IllegalStateException e) { mapper = null; } this.jsonObjectMapper = mapper; }
From source file:org.xmlsh.util.JavaUtils.java
public static boolean isWrappedOrPrimativeNumber(Class<?> c) { if (c == null) return false; if (c.isPrimitive() && !(c == Void.TYPE || c == Boolean.TYPE)) return true; for (Class<?> w : mNumberWrappers) if (c.isAssignableFrom(w)) return true; return false; }
From source file:org.echocat.jemoni.jmx.support.CacheDynamicMBean.java
@Nonnull protected MBeanOperationInfo[] getOperations() { final List<MBeanOperationInfo> result = new ArrayList<>(); result.add(new MBeanOperationInfo("get", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, String.class.getName(), ACTION)); result.add(new MBeanOperationInfo("remove", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, Void.TYPE.getName(), ACTION)); result.add(new MBeanOperationInfo("contains", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, Boolean.TYPE.getName(), ACTION)); if (_cache instanceof KeysEnabledCache) { result.add(new MBeanOperationInfo("getKeys", null, new MBeanParameterInfo[] { new MBeanParameterInfo("limit", Integer.class.getName(), null) }, String.class.getName(), ACTION)); }// w w w . j ava 2s . co m if (_cache instanceof ClearableCache) { result.add( new MBeanOperationInfo("clear", null, new MBeanParameterInfo[0], Void.TYPE.getName(), ACTION)); } if (_cache instanceof StatisticsEnabledCache) { result.add(new MBeanOperationInfo("resetStatistics", null, new MBeanParameterInfo[0], Void.TYPE.getName(), ACTION)); } if (_cache instanceof ListenerEnabledCache) { result.add(new MBeanOperationInfo("getListeners", null, new MBeanParameterInfo[0], String.class.getName(), ACTION)); } return result.toArray(new MBeanOperationInfo[result.size()]); }
From source file:org.grouplens.grapht.solver.DependencySolver.java
/** * Rewrite a dependency graph using the rules in this solver. The accumulated global graph and * back edges are ignored and not modified. * <p>Graph rewrite walks the graph, looking for nodes to rewrite. If the desire that leads * to a node is matched by a trigger binding function, then it is resolved using the binding * functions and replaced with the resulting (merged) node. Rewriting proceeds from the root * down, but does not consider the children of nodes generated by the rewriting process.</p> * * @param graph The graph to rewrite./*from w w w .j av a 2s. co m*/ * @return A rewritten version of the graph. */ public DAGNode<Component, Dependency> rewrite(DAGNode<Component, Dependency> graph) throws ResolutionException { if (!graph.getLabel().getSatisfaction().getErasedType().equals(Void.TYPE)) { throw new IllegalArgumentException("only full dependency graphs can be rewritten"); } logger.debug("rewriting graph with {} nodes", graph.getReachableNodes().size()); // We proceed in three stages. Map<DAGEdge<Component, Dependency>, DAGEdge<Component, Dependency>> replacementSubtrees = Maps.newHashMap(); walkGraphForReplacements(graph, InjectionContext.singleton(graph.getLabel().getSatisfaction()), replacementSubtrees); DAGNode<Component, Dependency> stage2 = graph.transformEdges(Functions.forMap(replacementSubtrees, null)); logger.debug("merging rewritten graph"); // Now we have a graph (stage2) with rewritten subtrees based on trigger rules // We merge this graph with the original to deduplicate. MergePool<Component, Dependency> pool = MergePool.create(); pool.merge(graph); return pool.merge(stage2); }
From source file:org.springframework.richclient.util.ClassUtils.java
private static Method getReadMethod(Class theClass, String propertyName) { // handle "embedded/dotted" properties if (propertyName.indexOf('.') > -1) { final int index = propertyName.indexOf('.'); final String firstPropertyName = propertyName.substring(0, index); final String restOfPropertyName = propertyName.substring(index + 1, propertyName.length()); final Class firstPropertyClass = getPropertyClass(theClass, firstPropertyName); return getReadMethod(firstPropertyClass, restOfPropertyName); }/*from w ww . j a va 2s.co m*/ final String getterName = "get" + propertyName.substring(0, 1).toUpperCase() + (propertyName.length() == 1 ? "" : propertyName.substring(1)); Method method = getMethod(theClass, getterName); if (method == null) { final String isserName = "is" + propertyName.substring(0, 1).toUpperCase() + (propertyName.length() == 1 ? "" : propertyName.substring(1)); method = getMethod(theClass, isserName); } if (method == null) { logger.info("There is not a getter for " + propertyName + " in " + theClass); return null; } if (!Modifier.isPublic(method.getModifiers())) { logger.warn("The getter for " + propertyName + " in " + theClass + " is not public: " + method); return null; } if (Void.TYPE.equals(method.getReturnType())) { logger.warn("The getter for " + propertyName + " in " + theClass + " returns void: " + method); return null; } if (method.getName().startsWith("is") && !(Boolean.class.equals(method.getReturnType()) || Boolean.TYPE.equals(method.getReturnType()))) { logger.warn("The getter for " + propertyName + " in " + theClass + " uses the boolean naming convention but is not boolean: " + method); return null; } return method; }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//*from w w w .j ava 2 s . c o m*/ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:org.xmlsh.util.JavaUtils.java
public static Class<?> fromPrimativeName(String name) { switch (name) { case "boolean": return java.lang.Boolean.TYPE; case "char": return java.lang.Character.TYPE; case "byte": return java.lang.Byte.TYPE; case "short": return java.lang.Short.TYPE; case "int": return java.lang.Integer.TYPE; case "long": return java.lang.Long.TYPE; case "float": return java.lang.Float.TYPE; case "double": return java.lang.Double.TYPE; case "void": return java.lang.Void.TYPE; default://from www .j av a2 s . c o m return null; } }
From source file:com.hortonworks.registries.schemaregistry.avro.AvroSchemaRegistryClientTest.java
@Test public void testAvroSerDePrimitives() throws Exception { Map<String, String> config = Collections .singletonMap(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), rootUrl); AvroSnapshotSerializer avroSnapshotSerializer = new AvroSnapshotSerializer(); avroSnapshotSerializer.init(config); AvroSnapshotDeserializer avroSnapshotDeserializer = new AvroSnapshotDeserializer(); avroSnapshotDeserializer.init(config); Object[] objects = generatePrimitivePayloads(); for (Object obj : objects) { String name = obj != null ? obj.getClass().getName() : Void.TYPE.getName(); SchemaMetadata schemaMetadata = createSchemaMetadata(name, SchemaCompatibility.BOTH); byte[] serializedData = avroSnapshotSerializer.serialize(obj, schemaMetadata); Object deserializedObj = avroSnapshotDeserializer.deserialize(new ByteArrayInputStream(serializedData), schemaMetadata, null);/*from ww w . ja va 2s. co m*/ if (obj instanceof byte[]) { Assert.assertArrayEquals((byte[]) obj, (byte[]) deserializedObj); } else { Assert.assertEquals(obj, deserializedObj); } } }