Skip to content

Commit

Permalink
#163: various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Jan 5, 2016
1 parent 6b72775 commit 0ba177d
Show file tree
Hide file tree
Showing 21 changed files with 1,108 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
* http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.bean.api;

import java.util.ArrayList;
import java.util.List;

import net.sf.mmm.util.exception.api.ObjectMismatchException;
import net.sf.mmm.util.pojo.descriptor.api.PojoPropertyNotFoundException;
import net.sf.mmm.util.property.api.GenericProperty;
import net.sf.mmm.util.reflect.api.GenericType;
import net.sf.mmm.util.reflect.base.ReflectionUtilImpl;
import net.sf.mmm.util.validation.api.ValidationFailure;
import net.sf.mmm.util.validation.api.ValueValidator;
import net.sf.mmm.util.validation.base.ComposedValidationFailure;
import net.sf.mmm.util.validation.base.ValidationFailureComposer;

/**
* This is the interface for all generic operations on a {@link Bean}.
Expand Down Expand Up @@ -55,28 +52,12 @@ default GenericProperty<?> getRequiredProperty(String name) throws PojoPropertyN
*/
default ValidationFailure validate() {

ValidationFailure result = null;
List<ValidationFailure> failureList = null;
ValidationFailureComposer composer = new ValidationFailureComposer();
for (GenericProperty<?> property : getProperties()) {
ValidationFailure failure = property.validate();
if (failure != null) {
if (failureList == null) {
if (result == null) {
result = failure;
} else {
failureList = new ArrayList<>();
failureList.add(result);
}
}
if (failureList != null) {
failureList.add(failure);
}
}
}
if (failureList != null) {
result = new ComposedValidationFailure(this, failureList.toArray(new ValidationFailure[failureList.size()]));
composer.add(failure);
}
return result;
return composer.get(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public BeanAccessMutable(BeanAccessPrototype<?> prototype) {
protected GenericProperty<?> createProperty(BeanPrototypeProperty prototypeProperty) {

GenericPropertyImpl<?> property = prototypeProperty.getProperty();
return property.createFor(getBean());
return property.copy(getBean());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import net.sf.mmm.util.property.api.GenericProperty;
import net.sf.mmm.util.property.impl.BooleanPropertyImpl;
import net.sf.mmm.util.property.impl.GenericPropertyImpl;
import net.sf.mmm.util.property.impl.IntegerPropertyImpl;
import net.sf.mmm.util.property.impl.LongPropertyImpl;
import net.sf.mmm.util.property.impl.StringPropertyImpl;
import net.sf.mmm.util.reflect.api.AccessFailedException;
import net.sf.mmm.util.reflect.api.GenericType;
import net.sf.mmm.util.reflect.api.InstantiationFailedException;
import net.sf.mmm.util.reflect.api.InvocationFailedException;
import net.sf.mmm.util.reflect.api.ReflectionUtil;
import net.sf.mmm.util.reflect.api.ReflectionUtilLimited;
import net.sf.mmm.util.reflect.base.ReflectionUtilImpl;
import net.sf.mmm.util.validation.base.AbstractValidator;
import net.sf.mmm.util.validation.base.ValidatorNone;
Expand Down Expand Up @@ -187,8 +190,9 @@ private GenericPropertyImpl<?> createProperty(BeanMethod beanMethod, GenericType
Method method = beanMethod.getMethod();
GenericPropertyImpl<?> property = null;
if (method.isDefault()) {
property = (GenericPropertyImpl<?>) LookupHelper.INSTANCE.invokeDefaultMethod(method,
ReflectionUtil.NO_ARGUMENTS);
property = (GenericPropertyImpl<?>) LookupHelper.INSTANCE.invokeDefaultMethod(bean, method,
ReflectionUtilLimited.NO_ARGUMENTS);
property = property.copy(beanMethod.getPropertyName(), bean);
}
if (property == null) {
GenericType<?> propertyType = this.reflectionUtil.createGenericType(beanMethod.getPropertyType(), beanType);
Expand All @@ -207,7 +211,9 @@ protected <V> GenericPropertyImpl<V> createProperty(String name, GenericType<V>
* @param <V> the generic property type.
* @param name the {@link GenericPropertyImpl#getName() property name}.
* @param type the {@link GenericPropertyImpl#getType() property type}.
* @param bean
* @param bean the {@link GenericPropertyImpl#getBean() bean}.
* @param propertyClass the {@link Class} reflecting the {@link GenericProperty} or <code>null</code> if no property
* method exists and this method is called for plain getter or setter.
* @return the new instance of {@link GenericPropertyImpl}.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
Expand All @@ -223,6 +229,10 @@ protected <V> GenericPropertyImpl<V> createProperty(String name, GenericType<V>
result = new StringPropertyImpl(name, bean);
} else if (valueClass == Boolean.class) {
result = new BooleanPropertyImpl(name, bean);
} else if (valueClass == Integer.class) {
result = new IntegerPropertyImpl(name, bean);
} else if (valueClass == Long.class) {
result = new LongPropertyImpl(name, bean);
} else {
result = new GenericPropertyImpl<>(name, type, bean);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package net.sf.mmm.util.bean.impl;

import java.lang.reflect.Method;
import java.util.Objects;

import net.sf.mmm.util.bean.api.Bean;
import net.sf.mmm.util.property.api.GenericProperty;
Expand All @@ -27,6 +28,9 @@ public abstract class BeanPrototypeOperationOnProperty extends BeanPrototypeOper
public BeanPrototypeOperationOnProperty(BeanAccessPrototype<?> prototype, Method method,
BeanPrototypeProperty property) {
super(prototype, method);
if (property == null) {
Objects.requireNonNull(property, "property");
}
this.prototypeProperty = property;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public MethodHandle newMethodHandle(Method method) {
}
}

public Object invokeDefaultMethod(Method method, Object... args) {
public Object invokeDefaultMethod(Object instance, Method method, Object... args) {

MethodHandle methodHandle = newMethodHandle(method);
try {
return methodHandle.invoke(args);
return methodHandle.bindTo(instance).invokeWithArguments(args);
} catch (Throwable e) {
throw new InvocationFailedException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.property.api;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.FloatBinding;
import javafx.beans.binding.IntegerBinding;
import javafx.beans.binding.LongBinding;
import javafx.beans.value.ObservableIntegerValue;
import javafx.beans.value.WritableIntegerValue;

/**
* This is the interface for a {@link GenericProperty} of the {@link #getValue() value}-{@link #getType() type}
* {@link Integer}.
*
* @author hohwille
* @since 7.1.0
*/
public interface IntegerProperty extends NumberProperty, ObservableIntegerValue, WritableIntegerValue {

@Override
default int get() {

Number value = getValue();
if (value == null) {
return 0;
}
return value.intValue();
}

@Override
default void set(int value) {

setValue(Integer.valueOf(value));
}

@Override
default IntegerBinding negate() {

return (IntegerBinding) Bindings.negate(this);
}

@Override
default FloatBinding add(float other) {

return (FloatBinding) Bindings.add(this, other);
}

@Override
default LongBinding add(long other) {

return (LongBinding) Bindings.add(this, other);
}

@Override
default IntegerBinding add(int other) {

return (IntegerBinding) Bindings.add(this, other);
}

@Override
default FloatBinding subtract(float other) {

return (FloatBinding) Bindings.subtract(this, other);
}

@Override
default LongBinding subtract(long other) {

return (LongBinding) Bindings.subtract(this, other);
}

@Override
default IntegerBinding subtract(int other) {

return (IntegerBinding) Bindings.subtract(this, other);
}

@Override
default FloatBinding multiply(float other) {

return (FloatBinding) Bindings.multiply(this, other);
}

@Override
default LongBinding multiply(long other) {

return (LongBinding) Bindings.multiply(this, other);
}

@Override
default IntegerBinding multiply(int other) {

return (IntegerBinding) Bindings.multiply(this, other);
}

@Override
default FloatBinding divide(float other) {

return (FloatBinding) Bindings.divide(this, other);
}

@Override
default LongBinding divide(long other) {

return (LongBinding) Bindings.divide(this, other);
}

@Override
default IntegerBinding divide(int other) {

return (IntegerBinding) Bindings.divide(this, other);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0 */
package net.sf.mmm.util.property.api;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.FloatBinding;
import javafx.beans.binding.LongBinding;
import javafx.beans.value.ObservableLongValue;
import javafx.beans.value.WritableLongValue;

/**
* This is the interface for a {@link GenericProperty} of the {@link #getValue() value}-{@link #getType() type}
* {@link Integer}.
*
* @author hohwille
* @since 7.1.0
*/
public interface LongProperty extends NumberProperty, ObservableLongValue, WritableLongValue {

@Override
default long get() {

Number value = getValue();
if (value == null) {
return 0;
}
return value.longValue();
}

@Override
default void set(long value) {

setValue(Long.valueOf(value));
}

@Override
default LongBinding negate() {

return (LongBinding) Bindings.negate(this);
}

@Override
default FloatBinding add(float other) {

return (FloatBinding) Bindings.add(this, other);
}

@Override
default LongBinding add(long other) {

return (LongBinding) Bindings.add(this, other);
}

@Override
default LongBinding add(int other) {

return (LongBinding) Bindings.add(this, other);
}

@Override
default FloatBinding subtract(float other) {

return (FloatBinding) Bindings.subtract(this, other);
}

@Override
default LongBinding subtract(long other) {

return (LongBinding) Bindings.subtract(this, other);
}

@Override
default LongBinding subtract(int other) {

return (LongBinding) Bindings.subtract(this, other);
}

@Override
default FloatBinding multiply(float other) {

return (FloatBinding) Bindings.multiply(this, other);
}

@Override
default LongBinding multiply(long other) {

return (LongBinding) Bindings.multiply(this, other);
}

@Override
default LongBinding multiply(int other) {

return (LongBinding) Bindings.multiply(this, other);
}

@Override
default FloatBinding divide(float other) {

return (FloatBinding) Bindings.divide(this, other);
}

@Override
default LongBinding divide(long other) {

return (LongBinding) Bindings.divide(this, other);
}

@Override
default LongBinding divide(int other) {

return (LongBinding) Bindings.divide(this, other);
}

}
Loading

0 comments on commit 0ba177d

Please sign in to comment.