List of usage examples for org.springframework.util ObjectUtils isArray
public static boolean isArray(@Nullable Object obj)
From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCreator.java
protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part, Iterator<Object> iterator) { if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS)) throw new UnsupportedOperationException("Case insensitivity not supported"); Class<?> leafNodePropertyType = part.getProperty().getLeafProperty().getType(); PropertyPath leafNodePropertyPath = part.getProperty().getLeafProperty(); String leafNodePropertyName = leafNodePropertyPath.toDotPath(); if (leafNodePropertyName.indexOf(".") != -1) { int index = leafNodePropertyName.lastIndexOf("."); leafNodePropertyName = leafNodePropertyName.substring(index); }/*from w w w . j av a 2s .c o m*/ switch (part.getType()) { case IN: Object in = iterator.next(); Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '" + leafNodePropertyName + "'"); boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class); boolean isArray = ObjectUtils.isArray(in); Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters"); Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in)); return criteria.withPropertyIn(leafNodePropertyName, iterable, leafNodePropertyType); case CONTAINING: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.CONTAINS, iterator.next(), leafNodePropertyType); case STARTING_WITH: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.BEGINS_WITH, iterator.next(), leafNodePropertyType); case BETWEEN: Object first = iterator.next(); Object second = iterator.next(); return criteria.withPropertyBetween(leafNodePropertyName, first, second, leafNodePropertyType); case AFTER: case GREATER_THAN: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GT, iterator.next(), leafNodePropertyType); case BEFORE: case LESS_THAN: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LT, iterator.next(), leafNodePropertyType); case GREATER_THAN_EQUAL: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.GE, iterator.next(), leafNodePropertyType); case LESS_THAN_EQUAL: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.LE, iterator.next(), leafNodePropertyType); case IS_NULL: return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NULL); case IS_NOT_NULL: return criteria.withNoValuedCriteria(leafNodePropertyName, ComparisonOperator.NOT_NULL); case TRUE: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.TRUE, leafNodePropertyType); case FALSE: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.EQ, Boolean.FALSE, leafNodePropertyType); case SIMPLE_PROPERTY: return criteria.withPropertyEquals(leafNodePropertyName, iterator.next(), leafNodePropertyType); case NEGATING_SIMPLE_PROPERTY: return criteria.withSingleValueCriteria(leafNodePropertyName, ComparisonOperator.NE, iterator.next(), leafNodePropertyType); default: throw new IllegalArgumentException("Unsupported keyword " + part.getType()); } }
From source file:io.github.moosbusch.lumpi.gui.form.editor.io.spi.ListButtonStoreValueDelegate.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a va2 s .c om*/ public void storeValue(Object context) { if (context != null) { ListButton listButton = getFormEditor().getComponent(); String propertyName = listButton.getListDataKey(); ListView.ListDataBindMapping bindMapping = listButton.getListDataBindMapping(); Object newPropertyValue = bindMapping.valueOf(listButton.getListData()); if (PropertyUtils.isWriteable(context, propertyName)) { listButton.store(context); } else { Object oldPropertyValue = null; try { oldPropertyValue = PropertyUtils.getProperty(context, propertyName); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(AbstractDynamicForm.class.getName()).log(Level.SEVERE, null, ex); } finally { if ((newPropertyValue != null) && (oldPropertyValue != null)) { if ((newPropertyValue instanceof java.util.Collection) && (oldPropertyValue instanceof java.util.Collection)) { java.util.Collection<Object> newColl = (java.util.Collection<Object>) newPropertyValue; java.util.Collection<Object> oldColl = (java.util.Collection<Object>) oldPropertyValue; newColl.stream().filter((obj) -> (!oldColl.contains(obj))).forEach((obj) -> { oldColl.add(obj); }); } else if ((newPropertyValue instanceof Sequence) && (oldPropertyValue instanceof Sequence)) { Sequence<Object> newSeq = (Sequence<Object>) newPropertyValue; Sequence<Object> oldSeq = (Sequence<Object>) oldPropertyValue; for (int cnt = 0; cnt < newSeq.getLength(); cnt++) { Object obj = newSeq.get(cnt); if (oldSeq.indexOf(obj) == -1) { oldSeq.add(obj); } } } else if ((newPropertyValue instanceof org.apache.pivot.collections.Set) && (oldPropertyValue instanceof org.apache.pivot.collections.Set)) { org.apache.pivot.collections.Set<Object> newColl = (org.apache.pivot.collections.Set<Object>) newPropertyValue; org.apache.pivot.collections.Set<Object> oldColl = (org.apache.pivot.collections.Set<Object>) oldPropertyValue; for (Object obj : newColl) { if (!oldColl.contains(obj)) { oldColl.add(obj); } } } else if ((ObjectUtils.isArray(newPropertyValue)) && (ObjectUtils.isArray(oldPropertyValue))) { Object[] newArray = (Object[]) newPropertyValue; Object[] oldArray = (Object[]) oldPropertyValue; for (Object obj : newArray) { if (!ArrayUtils.contains(oldArray, obj)) { oldArray = ArrayUtils.add(oldArray, obj); } } } } } } } }
From source file:org.synyx.hera.si.PluginRegistryAwareMessageHandler.java
/** * Returns the actual arguments to be used for the plugin method invocation. Will apply the configured invocation * argument expression to the given {@link Message}. * //from ww w . ja v a 2s. c o m * @param message * @return */ private Object[] getInvocationArguments(Message<?> message) { if (invocationArgumentsExpression == null) { return new Object[] { message }; } StandardEvaluationContext context = new StandardEvaluationContext(message); Object result = delimiterExpression.getValue(context); return ObjectUtils.isArray(result) ? ObjectUtils.toObjectArray(result) : new Object[] { result }; }
From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java
public static <T> org.apache.pivot.collections.List<T> toListData(Object value) { org.apache.pivot.collections.List<T> result = new ArrayList<>(); if (value != null) { if (value instanceof java.util.Collection) { java.util.Collection<T> coll = (java.util.Collection<T>) value; for (T obj : coll) { result.add(obj);// w w w. j a v a 2 s.co m } } else if (value instanceof Sequence) { Sequence<T> seq = (Sequence<T>) value; for (int cnt = 0; cnt < seq.getLength(); cnt++) { T obj = seq.get(cnt); result.add(obj); } } else if (value instanceof org.apache.pivot.collections.Set) { org.apache.pivot.collections.Set<T> set = (org.apache.pivot.collections.Set<T>) value; for (T obj : set) { result.add(obj); } } else if (ObjectUtils.isArray(value)) { T[] array = (T[]) value; for (T obj : array) { array = ArrayUtils.add(array, obj); } } else { result.add((T) value); } } return result; }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBQueryCreator.java
protected DynamoDBQueryCriteria<T, ID> addCriteria(DynamoDBQueryCriteria<T, ID> criteria, Part part, Iterator<Object> iterator) { if (part.shouldIgnoreCase().equals(IgnoreCaseType.ALWAYS)) throw new UnsupportedOperationException("Case insensitivity not supported"); Class<?> propertyType = part.getProperty().getType(); switch (part.getType()) { case IN://from w ww. ja va 2s . c o m Object in = iterator.next(); Assert.notNull(in, "Creating conditions on null parameters not supported: please specify a value for '" + part.getProperty().getSegment() + "'"); boolean isIterable = ClassUtils.isAssignable(in.getClass(), Iterable.class); boolean isArray = ObjectUtils.isArray(in); Assert.isTrue(isIterable || isArray, "In criteria can only operate with Iterable or Array parameters"); Iterable<?> iterable = isIterable ? ((Iterable<?>) in) : Arrays.asList(ObjectUtils.toObjectArray(in)); return criteria.withPropertyIn(part.getProperty().getSegment(), iterable, propertyType); case CONTAINING: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.CONTAINS, iterator.next(), propertyType); case STARTING_WITH: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.BEGINS_WITH, iterator.next(), propertyType); case BETWEEN: Object first = iterator.next(); Object second = iterator.next(); return criteria.withPropertyBetween(part.getProperty().getSegment(), first, second, propertyType); case AFTER: case GREATER_THAN: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GT, iterator.next(), propertyType); case BEFORE: case LESS_THAN: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LT, iterator.next(), propertyType); case GREATER_THAN_EQUAL: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.GE, iterator.next(), propertyType); case LESS_THAN_EQUAL: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.LE, iterator.next(), propertyType); case IS_NULL: return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NULL); case IS_NOT_NULL: return criteria.withNoValuedCriteria(part.getProperty().getSegment(), ComparisonOperator.NOT_NULL); case TRUE: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ, Boolean.TRUE, propertyType); case FALSE: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.EQ, Boolean.FALSE, propertyType); case SIMPLE_PROPERTY: return criteria.withPropertyEquals(part.getProperty().getSegment(), iterator.next(), propertyType); case NEGATING_SIMPLE_PROPERTY: return criteria.withSingleValueCriteria(part.getProperty().getSegment(), ComparisonOperator.NE, iterator.next(), propertyType); default: throw new IllegalArgumentException("Unsupported keyword " + part.getType()); } }
From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java
/** * Apply the given property values, resolving any runtime references * to other beans in this bean factory. Must use deep copy, so we * don't permanently modify this property. * @param beanName the bean name passed for better exception information * @param mbd the merged bean definition * @param bw the BeanWrapper wrapping the target object * @param pvs the new property values//from w w w . ja v a 2 s .com */ protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) { if (pvs.isEmpty()) { return; } if (System.getSecurityManager() != null && bw instanceof BeanWrapperImpl) { ((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext()); } MutablePropertyValues mpvs = null; List<PropertyValue> original; if (pvs instanceof MutablePropertyValues) { mpvs = (MutablePropertyValues) pvs; if (mpvs.isConverted()) { // Shortcut: use the pre-converted values as-is. try { bw.setPropertyValues(mpvs); return; } catch (BeansException ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Error setting property values", ex); } } original = mpvs.getPropertyValueList(); } else { original = Arrays.asList(pvs.getPropertyValues()); } TypeConverter converter = getCustomTypeConverter(); if (converter == null) { converter = bw; } BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter); // Create a deep copy, resolving any references for values. List<PropertyValue> deepCopy = new ArrayList<>(original.size()); boolean resolveNecessary = false; for (PropertyValue pv : original) { if (pv.isConverted()) { deepCopy.add(pv); } else { String propertyName = pv.getName(); Object originalValue = pv.getValue(); Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue); Object convertedValue = resolvedValue; boolean convertible = bw.isWritableProperty(propertyName) && !PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName); if (convertible) { convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter); } // Possibly store converted value in merged bean definition, // in order to avoid re-conversion for every created bean instance. if (resolvedValue == originalValue) { if (convertible) { pv.setConvertedValue(convertedValue); } deepCopy.add(pv); } else if (convertible && originalValue instanceof TypedStringValue && !((TypedStringValue) originalValue).isDynamic() && !(convertedValue instanceof Collection || ObjectUtils.isArray(convertedValue))) { pv.setConvertedValue(convertedValue); deepCopy.add(pv); } else { resolveNecessary = true; deepCopy.add(new PropertyValue(pv, convertedValue)); } } } if (mpvs != null && !resolveNecessary) { mpvs.setConverted(); } // Set our (possibly massaged) deep copy. try { bw.setPropertyValues(new MutablePropertyValues(deepCopy)); } catch (BeansException ex) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Error setting property values", ex); } }
From source file:org.springframework.cloud.stream.app.field.value.counter.sink.FieldValueCounterSinkConfiguration.java
protected void processValue(String counterName, Object value) { if ((value instanceof Collection) || ObjectUtils.isArray(value)) { Collection<?> c = (value instanceof Collection) ? (Collection<?>) value : Arrays.asList(ObjectUtils.toObjectArray(value)); for (Object val : c) { fieldValueCounterWriter.increment(counterName, val.toString(), 1.0); }//from w ww . ja v a2 s .c o m } else { fieldValueCounterWriter.increment(counterName, value.toString(), 1.0); } }
From source file:org.springframework.cloud.stream.app.http.source.DefaultMixedCaseContentTypeHttpHeaderMapper.java
private void setMessageHeader(Map<String, Object> target, String name, Object value) { if (ObjectUtils.isArray(value)) { Object[] values = ObjectUtils.toObjectArray(value); if (!ObjectUtils.isEmpty(values)) { if (values.length == 1) { target.put(name, values); } else { target.put(name, values[0]); }//from w w w . j a v a 2 s . c o m } } else if (value instanceof Collection<?>) { Collection<?> values = (Collection<?>) value; if (!CollectionUtils.isEmpty(values)) { if (values.size() == 1) { target.put(name, values.iterator().next()); } else { target.put(name, values); } } } else if (value != null) { target.put(name, value); } }
From source file:org.springframework.data.gemfire.function.PojoFunctionWrapper.java
private void sendResults(ResultSender<Object> resultSender, Object result) { if (result == null) { resultSender.lastResult(null);/* w ww. j av a 2s . c o m*/ } else { if (ObjectUtils.isArray(result)) { new BatchingResultSender(batchSize, resultSender).sendArrayResults(result); } else if (Iterable.class.isAssignableFrom(result.getClass())) { new BatchingResultSender(batchSize, resultSender).sendResults((Iterable<?>) result); } else { resultSender.lastResult(result); } } }
From source file:org.springframework.github.GithubDataListener.java
public void processValue(String counterName, Object value) { if ((value instanceof Collection) || ObjectUtils.isArray(value)) { Collection<?> c = (value instanceof Collection) ? (Collection<?>) value : Arrays.asList(ObjectUtils.toObjectArray(value)); for (Object val : c) { this.fieldValueCounterRepository.increment(counterName, val.toString(), 1.0); }/*w w w. j ava2s. c o m*/ } else if (value != null) { this.fieldValueCounterRepository.increment(counterName, value.toString(), 1.0); } counter.put(counterName, value); }