List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:com.fitbur.testify.system.SystemTestVerifier.java
@Override public void configuration() { doPrivileged((PrivilegedAction<Object>) () -> { String testClassName = testContext.getTestClassName(); CutDescriptor cutDescriptor = testContext.getCutDescriptor(); Collection<FieldDescriptor> fieldDescriptors = testContext.getFieldDescriptors().values(); if (testContext.getCutCount() == 1) { checkState(testContext.getConstructorCount() == 1, "Class under test '%s' defined in test class '%s' has %s constructors. " + "Please insure that the class under test has one and only one constructor.", cutDescriptor.getTypeName(), testClassName, testContext.getConstructorCount()); }/*from w w w .java 2s. c o m*/ // insure that only one field has Cut annotation on it. if (testContext.getCutCount() > 1) { checkState(false, "Found more than one class under test in %s. Please insure " + "that only one field is annotated with @Cut.", testClassName); } //insure that there is a field annotated with @Cut defined or one or more //fields annotated with @Real or @Inject if (testContext.getCutCount() == 0 && fieldDescriptors.isEmpty()) { checkState(false, "Test class '%s' does not define a field annotated with @Cut " + "nor does it define field(s) annotated with @Real or @Inject. " + "Please insure the test class defines a single field annotated " + "with @Cut or defines at least one field annotated with @Real " + "or @Inject.", testClassName); } //insure need providers have default constructors. testContext.getAnnotations(Need.class).parallelStream().map(Need::value).forEach(p -> { try { p.getDeclaredConstructor(); } catch (NoSuchMethodException e) { checkState(false, "Need provider '%s' defined in test class '%s' does not have a " + "zero argument default constructor. Please insure that the need " + "provider defines an accessible zero argument default constructor.", testClassName, p.getSimpleName()); } }); fieldDescriptors.parallelStream().forEach(p -> { Field field = p.getField(); Class<?> fieldType = p.getType(); String fieldName = p.getName(); String fieldTypeName = p.getTypeName(); checkState(!fieldType.isArray(), "Field '%s' in test class '%s' can not be configured because '%s'" + " is an array. Please consider using a List instead of arrays.", fieldName, testClassName, fieldTypeName); Fake fake = field.getDeclaredAnnotation(Fake.class); if (fake != null) { checkState(!isFinal(fieldType.getModifiers()), "Can not fake field '%s' in test class '%s' because '%s'" + " is a final class.", fieldName, testClassName, fieldTypeName); } Real real = field.getDeclaredAnnotation(Real.class); if (real != null && real.value()) { checkState(!isFinal(fieldType.getModifiers()), "Can not create delegated fake of field '%s' in test class '%s' " + "because '%s' is a final class.", fieldName, testClassName, fieldTypeName); } }); return null; }); }
From source file:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java
private void writeObject(JsonGenerator jg, Object value) throws IOException { if (value == null) { jg.writeNull();/*from w w w. j av a 2s. c o m*/ } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if (value instanceof Number) { Number n = (Number) value; if (value instanceof Double && (((Double) value).isInfinite() || ((Double) value).isNaN())) { jg.writeString(n.toString()); } else { jg.writeNumber(n.toString()); } } else if (value instanceof Boolean) { Boolean b = (Boolean) value; jg.writeBoolean(b); } else if (value instanceof CompositeData) { CompositeData cds = (CompositeData) value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for (String key : keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if (value instanceof TabularData) { TabularData tds = (TabularData) value; jg.writeStartArray(); for (Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else if (value instanceof GaugeValue) { ((GaugeValue) value).serialize(jg); } else { jg.writeString(value.toString()); } } }
From source file:com.bstek.dorado.data.type.EntityDataTypeSupport.java
protected void doCreatePropertyDefinitons() throws Exception { Class<?> type = getMatchType(); if (type == null) { type = getCreationType();/*w w w . j a va 2 s . co m*/ } if (type == null || type.isPrimitive() || type.isArray() || Map.class.isAssignableFrom(type)) { return; } PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); if (!BeanPropertyUtils.isValidProperty(type, name)) continue; PropertyDef propertyDef = getPropertyDef(name); DataType dataType = null; Class<?> propertyType = propertyDescriptor.getPropertyType(); if (Collection.class.isAssignableFrom(propertyType)) { ParameterizedType parameterizedType = (ParameterizedType) propertyDescriptor.getReadMethod() .getGenericReturnType(); if (parameterizedType != null) { dataType = DataUtils.getDataType(parameterizedType); } } if (dataType == null) { dataType = DataUtils.getDataType(propertyType); } if (propertyDef == null) { if (dataType != null) { propertyDef = new BasePropertyDef(name); propertyDef.setDataType(dataType); addPropertyDef(propertyDef); if (dataType instanceof EntityDataType || dataType instanceof AggregationDataType) { propertyDef.setIgnored(true); } } } else if (propertyDef.getDataType() == null) { if (dataType != null) propertyDef.setDataType(dataType); } } }
From source file:org.gvnix.web.json.BindingResultSerializer.java
/** * {@inheritDoc}//from w ww. j a va 2 s . c o m */ @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { try { // Cast to BindingResult BindingResult result = (BindingResult) value; // Create the result map Map<String, Object> allErrorsMessages = new HashMap<String, Object>(); // Get field errors List<FieldError> fieldErrors = result.getFieldErrors(); if (fieldErrors.isEmpty()) { // Nothing to do jgen.writeNull(); return; } // Check if target type is an array or a bean @SuppressWarnings("rawtypes") Class targetClass = result.getTarget().getClass(); if (targetClass.isArray() || Collection.class.isAssignableFrom(targetClass)) { loadListErrors(result.getFieldErrors(), allErrorsMessages); } else { loadObjectErrors(result.getFieldErrors(), allErrorsMessages); } jgen.writeObject(allErrorsMessages); } catch (JsonProcessingException e) { LOGGER.warn(ERROR_WRITTING_BINDING, e); throw e; } catch (IOException e) { LOGGER.warn(ERROR_WRITTING_BINDING, e); throw e; } catch (Exception e) { LOGGER.warn(ERROR_WRITTING_BINDING, e); throw new IOException(ERROR_WRITTING_BINDING, e); } }
From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoader.java
/** * Returns the value associated with the given configuration class and field type. * //from www .j a v a 2 s . c o m * @param name * @param config * @param fieldClass * @return the value */ @SuppressWarnings("unchecked") private <T> T getValue(String key, Class<T> fieldClass, org.apache.commons.configuration.Configuration config) { Object value; if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) { value = config.getStringArray(key); } else if (fieldClass.equals(Properties.class)) { value = getProperty(key, config); } else { value = getBasic(key, fieldClass, config); } return (T) value; }
From source file:com.streamsets.datacollector.http.JMXJsonServlet.java
private void writeObject(JsonGenerator jg, Object value) throws IOException { if (value == null) { jg.writeNull();// w ww . ja va2 s.c om } else { Class<?> c = value.getClass(); if (c.isArray()) { jg.writeStartArray(); int len = Array.getLength(value); for (int j = 0; j < len; j++) { Object item = Array.get(value, j); writeObject(jg, item); } jg.writeEndArray(); } else if (value instanceof Number) { Number n = (Number) value; jg.writeNumber(n.toString()); } else if (value instanceof Boolean) { Boolean b = (Boolean) value; jg.writeBoolean(b); } else if (value instanceof CompositeData) { CompositeData cds = (CompositeData) value; CompositeType comp = cds.getCompositeType(); Set<String> keys = comp.keySet(); jg.writeStartObject(); for (String key : keys) { writeAttribute(jg, key, cds.get(key)); } jg.writeEndObject(); } else if (value instanceof TabularData) { TabularData tds = (TabularData) value; jg.writeStartArray(); for (Object entry : tds.values()) { writeObject(jg, entry); } jg.writeEndArray(); } else if (value instanceof GaugeValue) { ((GaugeValue) value).serialize(jg); } else { jg.writeString(value.toString()); } } }
From source file:com.liferay.portal.jsonwebservice.JSONWebServiceConfigurator.java
private boolean _isJSONWebServiceClass(Class<?> clazz) { if (!clazz.isAnonymousClass() && !clazz.isArray() && !clazz.isEnum() && !clazz.isLocalClass() && !clazz.isPrimitive() && !(clazz.isMemberClass() ^ Modifier.isStatic(clazz.getModifiers()))) { return true; }/*w ww. j av a2 s . c o m*/ return false; }
From source file:org.brekka.phalanx.core.services.impl.AbstractCryptoService.java
@SuppressWarnings("unchecked") protected <T> T toType(byte[] data, Class<T> expectedType, UUID idOfData, CryptoProfile cryptoProfile) { if (expectedType == null) { throw new NullPointerException("An expected type is required"); }/*from w w w . j av a2 s.c om*/ Object retVal; if (expectedType.isArray() && expectedType.getComponentType() == Byte.TYPE) { retVal = data; } else if (expectedType == InternalPrivateKeyToken.class) { retVal = decodePrivateKey(data, idOfData, cryptoProfile); } else if (expectedType == InternalSecretKeyToken.class) { retVal = decodeSecretKey(data, idOfData); } else { throw new IllegalArgumentException( String.format("Unsupport type conversion to '%s'", expectedType.getName())); } return (T) retVal; }
From source file:net.sf.json.util.DynaBeanToBeanMorpher.java
/** * DOCUMENT ME!/*from ww w . jav a 2s . c o m*/ * * @param clazz DOCUMENT ME! */ private void validateClass(Class clazz) { if (clazz == null) { throw new IllegalArgumentException("target class is null"); } else if (clazz.isPrimitive()) { throw new IllegalArgumentException("target class is a primitive"); } else if (clazz.isArray()) { throw new IllegalArgumentException("target class is an array"); } else if (clazz.isInterface()) { throw new IllegalArgumentException("target class is an interface"); } else if (DynaBean.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a DynaBean"); } else if (Number.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a wrapper"); } else if (String.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a String"); } else if (Collection.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a Collection"); } else if (Map.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a Map"); } }
From source file:io.konik.utils.RandomInvoiceGenerator.java
private Object createNewInstance(Class<?> root) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { try {/* www. j a v a2 s . c o m*/ if (root.isArray()) { Object[] array = (Object[]) Array.newInstance(root.getComponentType(), 1); Class<?> componentType = root.getComponentType(); array[0] = populteData(componentType, componentType.getName()); return array; } return root.newInstance(); } catch (IllegalAccessException e) { Constructor<?> biggestConstructor = findBiggestConstructor(root); //for each parameter populate data Class<?>[] constructorParameters = biggestConstructor.getParameterTypes(); Object[] constructorParameterObjects = new Object[constructorParameters.length]; for (int i = 0; i < constructorParameters.length; i++) { Class<?> cp = constructorParameters[i]; constructorParameterObjects[i] = populteData(cp, biggestConstructor.getName()); } return biggestConstructor.newInstance(constructorParameterObjects); } catch (InstantiationException e) { if (root.equals(CommonTax.class)) { // return ZfDateFactory.create(supportedDateFormatts[random.nextInt(3)]); } // throw e; e.printStackTrace(); return null; } }