| Revision | 242 (tree) |
|---|---|
| Time | 2016-04-23 23:09:05 |
| Author | t_nakayama1971 |
(empty log message)
| @@ -3,16 +3,18 @@ | ||
| 3 | 3 | import java.lang.reflect.Method; |
| 4 | 4 | import java.lang.reflect.Modifier; |
| 5 | 5 | import java.sql.Timestamp; |
| 6 | +import java.util.Arrays; | |
| 6 | 7 | import java.util.Date; |
| 7 | 8 | import java.util.Locale; |
| 8 | 9 | import java.util.Map; |
| 10 | +import java.util.stream.Stream; | |
| 9 | 11 | |
| 12 | +import core.config.Factory; | |
| 10 | 13 | import online.model.ModelUtil; |
| 11 | 14 | import online.model.UniModel; |
| 12 | 15 | import online.model.session.ActionParameter; |
| 13 | 16 | import online.model.session.SessionUser; |
| 14 | 17 | import online.struts.action.UniForm; |
| 15 | -import core.config.Factory; | |
| 16 | 18 | |
| 17 | 19 | |
| 18 | 20 | /** |
| @@ -39,12 +41,8 @@ | ||
| 39 | 41 | * @return インスタンス |
| 40 | 42 | */ |
| 41 | 43 | public static <T> T create(final Class<T> cls, final UniForm model) { |
| 42 | - ActionParameter ap = null; | |
| 43 | - SessionUser su = null; | |
| 44 | - if (model != null) { | |
| 45 | - ap = model.getActionParameter(); | |
| 46 | - su = model.getSessionUser(); | |
| 47 | - } | |
| 44 | + ActionParameter ap = (model != null) ? model.getActionParameter() : null; | |
| 45 | + SessionUser su = (model != null) ? model.getSessionUser() : null; | |
| 48 | 46 | return create(cls, model, ap, su); |
| 49 | 47 | } |
| 50 | 48 |
| @@ -105,25 +103,36 @@ | ||
| 105 | 103 | * @param prop プロパティ |
| 106 | 104 | */ |
| 107 | 105 | private static void setPropertiesTo(final Object bean, final Map<String, String> prop) { |
| 108 | - for (final Method mt : bean.getClass().getMethods()) { | |
| 109 | - if (Modifier.isPublic(mt.getModifiers()) && mt.getName().startsWith("set") | |
| 110 | - && !Modifier.isStatic(mt.getModifiers()) && !mt.isBridge() | |
| 111 | - && !mt.isSynthetic() && mt.getParameterCount() == 1 | |
| 112 | - && !Object.class.equals(mt.getDeclaringClass())) { | |
| 113 | - Object obj = getPropertyValue(prop, mt.getName().substring("set".length())); | |
| 114 | - if (obj != null) { | |
| 115 | - Class<?> cls = mt.getParameterTypes()[0]; | |
| 116 | - if (String.class.equals(cls)) { | |
| 117 | - Factory.invoke(bean, mt, obj); | |
| 118 | - } else { | |
| 119 | - obj = Factory.construct(Factory.getConstructor(cls, String.class), obj); | |
| 120 | - if (obj != null) { | |
| 121 | - Factory.invoke(bean, mt, obj); | |
| 122 | - } | |
| 123 | - } | |
| 124 | - } | |
| 106 | + Arrays.stream(bean.getClass().getMethods()). | |
| 107 | + filter(mt -> mt.getName().startsWith("set")). | |
| 108 | + filter(mt -> Modifier.isPublic(mt.getModifiers())). | |
| 109 | + filter(mt -> !Modifier.isStatic(mt.getModifiers())). | |
| 110 | + filter(mt -> !mt.isBridge()). | |
| 111 | + filter(mt -> !mt.isSynthetic()). | |
| 112 | + filter(mt -> mt.getParameterCount() == 1). | |
| 113 | + filter(mt -> !Object.class.equals(mt.getDeclaringClass())). | |
| 114 | + forEach(mt -> { | |
| 115 | + Stream.of(getObject(prop, mt)). | |
| 116 | + filter(o -> o != null). | |
| 117 | + forEach(o -> Factory.invoke(bean, mt, o)); | |
| 118 | + }); | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * プロパティオブジェクト取得 | |
| 123 | + * @param prop プロパティマップ | |
| 124 | + * @param mt メソッド | |
| 125 | + * @return プロパティオブジェクト | |
| 126 | + */ | |
| 127 | + private static Object getObject(final Map<String, String> prop, final Method mt) { | |
| 128 | + Object obj = getPropertyValue(prop, mt.getName().substring("set".length())); | |
| 129 | + if (obj != null) { | |
| 130 | + Class<?> cls = mt.getParameterTypes()[0]; | |
| 131 | + if (!String.class.equals(cls)) { | |
| 132 | + obj = Factory.construct(Factory.getConstructor(cls, String.class), obj); | |
| 125 | 133 | } |
| 126 | 134 | } |
| 135 | + return obj; | |
| 127 | 136 | } |
| 128 | 137 | |
| 129 | 138 | /** |
| @@ -3,16 +3,18 @@ | ||
| 3 | 3 | import java.lang.reflect.Method; |
| 4 | 4 | import java.lang.reflect.Modifier; |
| 5 | 5 | import java.sql.Timestamp; |
| 6 | +import java.util.Arrays; | |
| 6 | 7 | import java.util.Date; |
| 7 | 8 | import java.util.Locale; |
| 8 | 9 | import java.util.Map; |
| 10 | +import java.util.stream.Stream; | |
| 9 | 11 | |
| 12 | +import core.config.Factory; | |
| 10 | 13 | import online.model.ModelUtil; |
| 11 | 14 | import online.model.UniModel; |
| 12 | 15 | import online.model.session.ActionParameter; |
| 13 | 16 | import online.model.session.SessionUser; |
| 14 | 17 | import online.struts.action.UniForm; |
| 15 | -import core.config.Factory; | |
| 16 | 18 | |
| 17 | 19 | |
| 18 | 20 | /** |
| @@ -39,12 +41,8 @@ | ||
| 39 | 41 | * @return インスタンス |
| 40 | 42 | */ |
| 41 | 43 | public static <T> T create(final Class<T> cls, final UniForm model) { |
| 42 | - ActionParameter ap = null; | |
| 43 | - SessionUser su = null; | |
| 44 | - if (model != null) { | |
| 45 | - ap = model.getActionParameter(); | |
| 46 | - su = model.getSessionUser(); | |
| 47 | - } | |
| 44 | + ActionParameter ap = (model != null) ? model.getActionParameter() : null; | |
| 45 | + SessionUser su = (model != null) ? model.getSessionUser() : null; | |
| 48 | 46 | return create(cls, model, ap, su); |
| 49 | 47 | } |
| 50 | 48 |
| @@ -105,25 +103,36 @@ | ||
| 105 | 103 | * @param prop プロパティ |
| 106 | 104 | */ |
| 107 | 105 | private static void setPropertiesTo(final Object bean, final Map<String, String> prop) { |
| 108 | - for (final Method mt : bean.getClass().getMethods()) { | |
| 109 | - if (Modifier.isPublic(mt.getModifiers()) && mt.getName().startsWith("set") | |
| 110 | - && !Modifier.isStatic(mt.getModifiers()) && !mt.isBridge() | |
| 111 | - && !mt.isSynthetic() && mt.getParameterCount() == 1 | |
| 112 | - && !Object.class.equals(mt.getDeclaringClass())) { | |
| 113 | - Object obj = getPropertyValue(prop, mt.getName().substring("set".length())); | |
| 114 | - if (obj != null) { | |
| 115 | - Class<?> cls = mt.getParameterTypes()[0]; | |
| 116 | - if (String.class.equals(cls)) { | |
| 117 | - Factory.invoke(bean, mt, obj); | |
| 118 | - } else { | |
| 119 | - obj = Factory.construct(Factory.getConstructor(cls, String.class), obj); | |
| 120 | - if (obj != null) { | |
| 121 | - Factory.invoke(bean, mt, obj); | |
| 122 | - } | |
| 123 | - } | |
| 124 | - } | |
| 106 | + Arrays.stream(bean.getClass().getMethods()). | |
| 107 | + filter(mt -> mt.getName().startsWith("set")). | |
| 108 | + filter(mt -> Modifier.isPublic(mt.getModifiers())). | |
| 109 | + filter(mt -> !Modifier.isStatic(mt.getModifiers())). | |
| 110 | + filter(mt -> !mt.isBridge()). | |
| 111 | + filter(mt -> !mt.isSynthetic()). | |
| 112 | + filter(mt -> mt.getParameterCount() == 1). | |
| 113 | + filter(mt -> !Object.class.equals(mt.getDeclaringClass())). | |
| 114 | + forEach(mt -> { | |
| 115 | + Stream.of(getObject(prop, mt)). | |
| 116 | + filter(o -> o != null). | |
| 117 | + forEach(o -> Factory.invoke(bean, mt, o)); | |
| 118 | + }); | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * プロパティオブジェクト取得 | |
| 123 | + * @param prop プロパティマップ | |
| 124 | + * @param mt メソッド | |
| 125 | + * @return プロパティオブジェクト | |
| 126 | + */ | |
| 127 | + private static Object getObject(final Map<String, String> prop, final Method mt) { | |
| 128 | + Object obj = getPropertyValue(prop, mt.getName().substring("set".length())); | |
| 129 | + if (obj != null) { | |
| 130 | + Class<?> cls = mt.getParameterTypes()[0]; | |
| 131 | + if (!String.class.equals(cls)) { | |
| 132 | + obj = Factory.construct(Factory.getConstructor(cls, String.class), obj); | |
| 125 | 133 | } |
| 126 | 134 | } |
| 135 | + return obj; | |
| 127 | 136 | } |
| 128 | 137 | |
| 129 | 138 | /** |