• R/O
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision242 (tree)
Time2016-04-23 23:09:05
Authort_nakayama1971

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/framework/pjWeb/WEB-INF/src/project/web/InstanceFactory.java (revision 241)
+++ trunk/framework/pjWeb/WEB-INF/src/project/web/InstanceFactory.java (revision 242)
@@ -3,16 +3,18 @@
33 import java.lang.reflect.Method;
44 import java.lang.reflect.Modifier;
55 import java.sql.Timestamp;
6+import java.util.Arrays;
67 import java.util.Date;
78 import java.util.Locale;
89 import java.util.Map;
10+import java.util.stream.Stream;
911
12+import core.config.Factory;
1013 import online.model.ModelUtil;
1114 import online.model.UniModel;
1215 import online.model.session.ActionParameter;
1316 import online.model.session.SessionUser;
1417 import online.struts.action.UniForm;
15-import core.config.Factory;
1618
1719
1820 /**
@@ -39,12 +41,8 @@
3941 * @return インスタンス
4042 */
4143 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;
4846 return create(cls, model, ap, su);
4947 }
5048
@@ -105,25 +103,36 @@
105103 * @param prop プロパティ
106104 */
107105 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);
125133 }
126134 }
135+ return obj;
127136 }
128137
129138 /**
--- trunk/framework/pjWeb2/WEB-INF/src/project/web/InstanceFactory.java (revision 241)
+++ trunk/framework/pjWeb2/WEB-INF/src/project/web/InstanceFactory.java (revision 242)
@@ -3,16 +3,18 @@
33 import java.lang.reflect.Method;
44 import java.lang.reflect.Modifier;
55 import java.sql.Timestamp;
6+import java.util.Arrays;
67 import java.util.Date;
78 import java.util.Locale;
89 import java.util.Map;
10+import java.util.stream.Stream;
911
12+import core.config.Factory;
1013 import online.model.ModelUtil;
1114 import online.model.UniModel;
1215 import online.model.session.ActionParameter;
1316 import online.model.session.SessionUser;
1417 import online.struts.action.UniForm;
15-import core.config.Factory;
1618
1719
1820 /**
@@ -39,12 +41,8 @@
3941 * @return インスタンス
4042 */
4143 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;
4846 return create(cls, model, ap, su);
4947 }
5048
@@ -105,25 +103,36 @@
105103 * @param prop プロパティ
106104 */
107105 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);
125133 }
126134 }
135+ return obj;
127136 }
128137
129138 /**