Mercurial > hg > Database > Christie
changeset 3:e3bb0eea73f2
resolve Annotation error and TestCodeGear is working
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 13 Dec 2017 17:24:14 +0900 |
parents | bacdcb5e6dcf |
children | 605f1b0576c2 |
files | .idea/uiDesigner.xml src/main/java/christie/annotation/Take.java src/main/java/christie/codegear/CodeGear.java src/main/java/christie/codegear/InputDataGear.java src/main/java/christie/codegear/OutputDataGear.java src/main/java/christie/codegear/StartCodeGear.java src/main/java/christie/datagear/DataGear.java src/main/java/christie/datagear/DataGearManager.java src/main/java/christie/datagear/LocalDataGearManager.java src/main/java/christie/datagear/RemoteDataGearManager.java src/main/java/christie/datagear/StringData.java src/main/java/christie/test/StartTest.java src/main/java/christie/test/TestCodeGear.java |
diffstat | 13 files changed, 227 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.idea/uiDesigner.xml Wed Dec 13 17:24:14 2017 +0900 @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project> \ No newline at end of file
--- a/src/main/java/christie/annotation/Take.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/annotation/Take.java Wed Dec 13 17:24:14 2017 +0900 @@ -1,8 +1,15 @@ package christie.annotation; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** * Created by e125769 on 12/7/17. */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) public @interface Take { String value(); }
--- a/src/main/java/christie/codegear/CodeGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/codegear/CodeGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -3,7 +3,6 @@ import christie.annotation.Take; import christie.datagear.DataGear; import christie.datagear.DataGearManager; -import christie.datagear.StringData; import java.lang.reflect.Field; import java.util.ArrayList; @@ -13,27 +12,27 @@ * Created by e125769 on 12/7/17. * Annotationからのinputコマンドの生成、揃ったDataGearの値を返す */ -public interface CodeGear extends Runnable{ - InputDataGear idg = new InputDataGear(); - OutputDataGear odg = new OutputDataGear(); - ArrayList<Command> commandList = new ArrayList<Command>(); +public abstract class CodeGear implements Runnable { + public InputDataGear idg = new InputDataGear(); + public OutputDataGear odg = new OutputDataGear(); + public ArrayList<Command> commandList = new ArrayList<Command>(); + public CodeGearManager cgm; - default void start(CodeGearManager cgm){//AnnotationからInputDataGearをセット + public CodeGear(CodeGearManager cgm){//AnnotationからInputDataGearをセット + this.cgm = cgm; odg.initODG(cgm, this); + for (Field field : this.getClass().getDeclaredFields()) { - if (field.isAnnotationPresent(Take.class)){//何故かここに入らない - if (!field.getType().isInterface()){ - System.out.println("DataGearではありません"); - } + if (field.isAnnotationPresent(Take.class)){ Take ano = field.getAnnotation(Take.class); - System.out.println(ano.value()); commandList.add(new Command(this, null, "local", ano.value(), CommandType.TAKE)); } } - idg.finishInput(cgm, this, commandList); + + idg.finishInput(this.cgm, this, commandList); } - default void setInputValue(){//Annotationから揃ったInputDataGearの値をキャスト + public void setInputValue(){//Annotationから揃ったInputDataGearの値をキャスト for (Field field : this.getClass().getDeclaredFields()) { field.setAccessible(true); if (field.isAnnotationPresent(Take.class)){ @@ -47,12 +46,6 @@ } } - default void put(String key, Object data){ - odg.put(key, data); - } - - default void put(String dist, String key, Object data){ - odg.put(dist, key, data); - } + public void run(){} }
--- a/src/main/java/christie/codegear/InputDataGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/codegear/InputDataGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -25,11 +25,7 @@ } for(Command cm : commandList){ - if (cgm.getDGM(cm.dest).dataGears.containsKey(cm.key)) { - this.cgm.getDGM(cm.dest).runCommand(cm); - } else { - this.cgm.getDGM(cm.dest).addWaitList(cm); - } + cgm.getDGM(cm.dest).take(cm); } }
--- a/src/main/java/christie/codegear/OutputDataGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/codegear/OutputDataGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -6,8 +6,8 @@ * Created by e125769 on 12/7/17. */ public class OutputDataGear { - CodeGearManager cgm; - CodeGear cg; + public CodeGearManager cgm; + public CodeGear cg; public void initODG(CodeGearManager cgm, CodeGear cg){ this.cgm = cgm; @@ -15,10 +15,10 @@ } public void put(String key, Object dg){ - cgm.getDGM("local").put(key, dg);//interfaceはnewできない + cgm.getDGM("local").put(key, new DataGear(dg)); } public void put(String dist, String key, Object dg){ - cgm.getDGM(dist).put(key, dg); + cgm.getDGM(dist).put(key, new DataGear(dg)); } }
--- a/src/main/java/christie/codegear/StartCodeGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/codegear/StartCodeGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -1,25 +1,28 @@ package christie.codegear; import java.util.HashMap; +import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -public interface StartCodeGear { - HashMap<String, CodeGearManager> cgms = new HashMap<String, CodeGearManager>(); - ThreadPoolExecutor threadPool = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads +public abstract class StartCodeGear { + static HashMap<String, CodeGearManager> cgms = new HashMap<String, CodeGearManager>(); + static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<Runnable>(); + static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), // initial number of threads Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE, // keepAliveTime TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>()); + taskQueue); - static CodeGearManager createCGM(String name){ + + public static CodeGearManager createCGM(String name){ CodeGearManager cgm = new CodeGearManager(threadPool); cgms.put(name, cgm); return cgm; } - static CodeGearManager getCGM(String name){ + public static CodeGearManager getCGM(String name){ return cgms.get(name); } }
--- a/src/main/java/christie/datagear/DataGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/datagear/DataGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -1,11 +1,33 @@ package christie.datagear; -/** - * Created by e125769 on 12/7/17. - */ -public interface DataGear<T> { - Class getClazz(); - void setClazz(Class clazz); - T getData(); - void setData(T data); +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class DataGear<T>{ + T data; + byte[] byteData; + Class<T> clazz; + + public DataGear(T data){ + this.data = data; + setClazz(data.getClass()); + } + + public void setData(T data) { + this.data = data; + } + + public void setClazz(Class clazz){ + this.clazz = clazz; + }; + + public Class getClazz(){ + return clazz; + }; + + public T getData(){ + return data; + }; + }
--- a/src/main/java/christie/datagear/DataGearManager.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/datagear/DataGearManager.java Wed Dec 13 17:24:14 2017 +0900 @@ -15,11 +15,8 @@ public interface DataGearManager { TreeMap<String, DataGear> dataGears = new TreeMap<String, DataGear>(); HashMap<String, Command> waitList = new HashMap<String, Command>(); - void take(String key); + void take(Command cm); void put(String key, DataGear data); void runCommand(Command cm); - - default void addWaitList(Command command){ - waitList.put(command.key, command); - } + void addWaitList(Command command); }
--- a/src/main/java/christie/datagear/LocalDataGearManager.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/datagear/LocalDataGearManager.java Wed Dec 13 17:24:14 2017 +0900 @@ -1,5 +1,6 @@ package christie.datagear; +import christie.codegear.CodeGear; import christie.codegear.Command; /** @@ -8,8 +9,12 @@ public class LocalDataGearManager implements DataGearManager { - public void take(String key) { - + public void take(Command cm) { + if (dataGears.containsKey(cm.key)) { + runCommand(cm); + } else { + addWaitList(cm); + } } public void put(String key, DataGear data) { @@ -30,4 +35,9 @@ } waitList.remove(cm.key); } + + @Override + public void addWaitList(Command command) { + waitList.put(command.key, command); + } }
--- a/src/main/java/christie/datagear/RemoteDataGearManager.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/datagear/RemoteDataGearManager.java Wed Dec 13 17:24:14 2017 +0900 @@ -3,8 +3,9 @@ import christie.codegear.Command; public class RemoteDataGearManager implements DataGearManager{ + @Override - public void take(String key) { + public void take(Command cm) { } @@ -17,4 +18,9 @@ public void runCommand(Command cm) { } + + @Override + public void addWaitList(Command command) { + + } }
--- a/src/main/java/christie/datagear/StringData.java Tue Dec 12 16:48:30 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -package christie.datagear; - -/** - * Created by e125769 on 12/7/17. - */ -public class StringData<T> implements DataGear { - - Class<T> clazz; - T data; - - public StringData(String s){ - setData(s); - setClazz(String.class); - } - - - public Class getClazz() { - return clazz; - } - - public void setClazz(Class clazz) { - this.clazz = clazz; - } - - public T getData() { - return data; - } - - public void setData(Object data) { - this.data = (T) data; - } -}
--- a/src/main/java/christie/test/StartTest.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/test/StartTest.java Wed Dec 13 17:24:14 2017 +0900 @@ -1,12 +1,13 @@ package christie.test; import christie.codegear.StartCodeGear; -import christie.datagear.StringData; -public class StartTest implements StartCodeGear{ +public class StartTest extends StartCodeGear{ + public static void main(String args[]){ - TestCodeGear test = new TestCodeGear(); - test.start(StartCodeGear.createCGM("first")); - test.put("hoge", new StringData("hogehogehoge")); + TestCodeGear test = new TestCodeGear(createCGM("first")); + test.odg.put("hoge", "hogehogehoge"); + test.odg.put("huga", 100); } + }
--- a/src/main/java/christie/test/TestCodeGear.java Tue Dec 12 16:48:30 2017 +0900 +++ b/src/main/java/christie/test/TestCodeGear.java Wed Dec 13 17:24:14 2017 +0900 @@ -3,19 +3,28 @@ import christie.annotation.Take; import christie.codegear.CodeGear; import christie.codegear.CodeGearManager; -import christie.datagear.StringData; +import christie.datagear.DataGear; /** * Created by e125769 on 12/7/17. */ -public class TestCodeGear implements CodeGear { +public class TestCodeGear extends CodeGear { @Take("hoge") - StringData hoge; + DataGear hoge; + + @Take("huga") + DataGear huga; + public TestCodeGear(CodeGearManager cgm){ + super(cgm); + } + + @Override public void run() { System.out.println("in run!"); System.out.println(hoge.getData()); + System.out.println(huga.getData()); } }