Author: mmichaud
Date: 2009-06-09 08:45:30 -0700 (Tue, 09 Jun 2009)
New Revision: 16876
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/SearchActive.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerListener.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BooleanCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BoundedCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/FlexiblyBoundedCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListMultipleSelectionCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListSingleSelectionCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/StringCLHandler.java
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/util/ListMultipleSelection.java
Log:
[]
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/PrintSomething.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,16 +1,16 @@
+package org.example.command;
-package org.example.command;
+import java.util.Map;
+
+import org.example.tunable.Handler;
+import org.example.tunable.HandlerController;
import org.example.tunable.Tunable;
-import org.example.tunable.HandlerController;
-import org.example.tunable.Handler;
+import org.example.tunable.util.BoundedDouble;
import org.example.tunable.util.BoundedInteger;
-import org.example.tunable.util.BoundedDouble;
import org.example.tunable.util.FlexiblyBoundedInteger;
import org.example.tunable.util.ListMultipleSelection;
import org.example.tunable.util.ListSingleSelection;
-import java.util.Map;
-
public class PrintSomething implements Command, HandlerController {
@Tunable(description="your first name", group={"stuff"})
@@ -41,37 +41,100 @@
public ListMultipleSelection<String> lms = new
ListMultipleSelection<String>("one","two","three","four");
- private Integer age = Integer.valueOf(25);
+
+ // test of methods
+ private Integer age = Integer.valueOf(25);
@Tunable(description="to set your age")
public void setAge(Integer a) {
- if ( a == null )
- throw new NullPointerException("age is null");
+ if ( a == null )throw new NullPointerException("age is null");
age = a;
}
@Tunable(description="to get your age")
- public Integer getAge(){
- return age;
+ public Integer getAge(){return age;}
+
+
+ private Boolean booltest = new Boolean(false);
+ @Tunable(description="to set the booleantest")
+ public void setBoolTest(Boolean b){
+ if(b == null) throw new NullPointerException("boolean is null");
+ booltest = b;
}
+ @Tunable(description="to get the booleantest")
+ public Boolean getBoolTest(){return booltest;}
+
+ private String line = new String("cytoscape development");
+ @Tunable(description="to set the line")
+ public void setLine(String st){
+ if(st == null) throw new NullPointerException("line is null");
+ line = st;
+ }
+ @Tunable(description="to get the line")
+ public String getLine(){return line;}
-// test
- public BoundedInteger height = new
BoundedInteger(0,150,200,false,false);;
-// public BoundedInteger test
-//
-// @Tunable(description="to set the Height")
-// public void setHeight(int a) {
-// height.setValue();
-// height = test;
-// }
-
+ //may have to be modified, but is working
+ private BoundedInteger height = new
BoundedInteger(0,150,200,false,false);
+ @Tunable(description="to set the Height")
+ public void setHeight(BoundedInteger bi) {
+ if(bi == null) throw new NullPointerException("height is
null");
+ height = bi;
+ }
+ @Tunable(description="to get the height")
+ public BoundedInteger getHeight(){return height;}
+ private FlexiblyBoundedInteger size = new
FlexiblyBoundedInteger(0,3,78,true,true);
+ @Tunable(description="to set the Size")
+ public void setSize(FlexiblyBoundedInteger fbi){
+ if(fbi == null)throw new NullPointerException("size is null!!");
+ size = fbi;
+ }
+ @Tunable(description="to get the Size")
+ public FlexiblyBoundedInteger getSize(){
+ return size;
+ }
+ private ListSingleSelection<String> colors = new
ListSingleSelection<String>("red","blue","green","yellow");
+ @Tunable(description="to set the colors")
+ public void setColors(ListSingleSelection<String> list){
+ if(list==null) throw new NullPointerException("the list is
null");
+ colors = list;
+ }
+ @Tunable(description="to get the colors")
+ public ListSingleSelection<String> getColors(){return colors;}
+
+
+
+ //DOESN'T work, cause cannot use generic type Integer. just String for
the moment??
+ private ListMultipleSelection<Integer> numbers = new
ListMultipleSelection<Integer>(100,200,300,400,500);
+ @Tunable(description="to set the numbers")
+ public void setNumbers(ListMultipleSelection<Integer> lmsi){
+ if(lmsi==null)throw new NullPointerException("the numbers is
null");
+ numbers = lmsi;
+ }
+ @Tunable(description="to get the numbers")
+ public ListMultipleSelection<Integer> getNumbers(){return numbers;}
+
+
+
+
+
public void execute() {
System.out.println("\t name : " + firstName + " " + lastName +
"\n \t age : " + age + "\n \t foot size : " + footSize.getValue() + "\n \t kids
= " + kids.getValue() + "\n \t income : $" + income.getValue() + "\n \t result
for boolean = " + bool + "\n \t listsingleselection = "+lss.getSelectedValue()
+ "\n \t listmultipleselection = "+lms.getSelectedValues() + "\n \t height =
"+height.getValue());
-// System.out.println("test = " + height.getValue());
+ System.out.println("\n\nRESULT FOR GETSET METHODS = ");
+
+ System.out.println("testBoolean = " + booltest);
+ System.out.println("testString = " + line);
+ System.out.println("testBoundedInteger value = " +
height.getValue());
+ System.out.println("testFlexiblyBoundedInteger value= " +
size.getValue());
+ System.out.println("testFlexiblyBoundedInteger lowerbound= " +
size.getLowerBound());
+ System.out.println("testFlexiblyBoundedInteger upperbound= " +
size.getUpperBound());
+ System.out.println("testListSingleSelection =
"+colors.getPossibleValues());
+ System.out.println("testListSingleSelection =
"+colors.getSelectedValue());
+ System.out.println("testListMultipleSelection =
"+numbers.getPossibleValues());
+ System.out.println("testListMultipleSelection =
"+numbers.getSelectedValues());
}
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/SearchActive.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/SearchActive.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/command/SearchActive.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,11 +1,8 @@
-
-
package org.example.command;
import org.example.tunable.Tunable;
-import org.example.tunable.util.*;
-import java.util.*;
+
public class SearchActive extends AbstractActive {
// search
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/AbstractTunableInterceptor.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -7,7 +7,7 @@
* An abstract implementation of {...@link TunableInterceptor} that should
serve as
* the super class for almost all implementations of {...@link
TunableInterceptor}.
*/
-public abstract class AbstractTunableInterceptor<T extends Handler> implements
TunableInterceptor {
+public abstract class AbstractTunableInterceptor<T extends Handler> implements
TunableInterceptor<T> {
protected HandlerFactory<T> factory;
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerListener.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerListener.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/HandlerListener.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,9 +1,5 @@
-
package org.example.tunable;
-import java.lang.reflect.Method;
-import java.lang.reflect.Field;
-
/**
* Allows an object to listen to changes in a Handler.
*/
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/AbstractCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -11,9 +11,9 @@
super(f,o,t);
}
- public AbstractCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
- }
+// public AbstractCLHandler(Method m, Object o, Tunable t) {
+// super(m,o,t);
+// }
public AbstractCLHandler(Method gmethod, Method smethod, Object o,
Tunable tg, Tunable ts){
super(gmethod,smethod,o,tg,ts);
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BooleanCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BooleanCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BooleanCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,9 +1,13 @@
package org.example.tunable.internal.cl;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
-import org.apache.commons.cli.*;
-import org.example.tunable.*;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.example.tunable.Tunable;
public class BooleanCLHandler extends AbstractCLHandler {
@@ -12,10 +16,17 @@
super(f,o,t);
}
- public BooleanCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
+// public BooleanCLHandler(Method m, Object o, Tunable t) {
+// super(m,o,t);
+// }
+
+ public BooleanCLHandler(Method gmethod,Method smethod,Object o, Tunable
tg, Tunable ts){
+ super(gmethod,smethod,o,tg,ts);
}
+
+
+
public void handleLine( CommandLine line ) {
String n = getName();
int ind = n.lastIndexOf(".")+1;
@@ -29,38 +40,40 @@
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
if ( f != null )
f.set(o,Boolean.parseBoolean(line.getOptionValue(fc)));
- else if ( m != null )
-
m.invoke(o,Boolean.parseBoolean(line.getOptionValue(fc)));
+ else if ( smethod != null )
+
smethod.invoke(o,Boolean.parseBoolean(line.getOptionValue(fc)));
else
throw new Exception("no Field or Method
to set!");
}
} catch(Exception e) {e.printStackTrace();}
}
- public Option getOption() {
- String n = getName();
- int ind = n.lastIndexOf(".")+1;
+
+
+ public Option getOption(){
+ String n = getName();
+ int ind = n.lastIndexOf(".")+1;
String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
+ //if(n.substring(ind).length()<3)fc = n.substring(ind);
//else fc = n.substring(ind,ind+3);
fc = n.substring(ind);
- Boolean currentValue = null;
-
- if( f!=null){
+ Boolean currentValue = null;
+ if (f!=null){
try{
currentValue = (Boolean)f.get(o);
}catch(Exception e){e.printStackTrace();}
- return new Option(fc, true,"-- "+ t.description()+"
--\n current value : " + currentValue);
+ return new Option(fc, true,"-- " + t.description() + "
--\n current value : "+ currentValue);
}
-
- else if(m!=null){
- Type[] types = m.getParameterTypes();
- java.util.List list = new java.util.ArrayList();
- for(int i=0;i<types.length;i++) list.add(i,types[i]);
- return new Option(fc, true,"-- "+ t.description()+"
--\n Method's parameter : "+list);
+ else if (gmethod!=null){
+ try{
+ currentValue = (Boolean)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- " + tg.description() + "
--\n current value : "+ currentValue);
}
else return null;
- }
+
+ }
+
private void displayCmds(String fc){
@@ -70,6 +83,5 @@
formatter.setWidth(100);
System.out.println("\n");
formatter.printHelp("Detailed informations/commands for " + fc
+ " :", options);
- //System.out.println("\nCommands Options for -"+ fc +"\n
(multiple commands can be coupled by inserting \" : \" ) example : -"+fc+"
val.x:up.y:upstrict.true\n\t-"+fc+" val.x : setValue\n\t-"+fc+" up.x :
setUpperBound\n\t-"+fc+" low.x : setLowerBound\n\t-"+fc+" lowstrict.Boolean :
setLowerBoundStrict\n\t-"+fc+" upstrict.Boolean : setUpperBoundStrict\n");
}
}
\ No newline at end of file
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BoundedCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BoundedCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/BoundedCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,25 +1,28 @@
package org.example.tunable.internal.cl;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
-import org.apache.commons.cli.*;
-import org.example.tunable.*;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.example.tunable.Tunable;
import org.example.tunable.util.AbstractBounded;
public class BoundedCLHandler<T extends AbstractBounded<?>> extends
AbstractCLHandler {
- T bo;
+ private T bo;
+ private String lbound="\u2264";
+ private String ubound="\u2264";
+
public BoundedCLHandler(Field f, Object o, Tunable t) {
super(f,o,t);
- try{
- bo = (T) f.get(o);
- }catch (Exception e){e.printStackTrace();}
}
-
- public BoundedCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
+ public BoundedCLHandler(Method gmethod, Method smethod, Object o,
Tunable tg, Tunable ts) {
+ super(gmethod,smethod,o,tg,ts);
}
@@ -27,19 +30,19 @@
String n = getName();
int ind = n.lastIndexOf(".")+1;
String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
fc = n.substring(ind);
+
try {
if ( line.hasOption( fc ) ) {
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
if ( f != null ){
bo.setValue(line.getOptionValue(fc));
f.set(o,bo);}
- else if ( m != null ){
- bo.setValue(line.getOptionValue(fc));
- m.invoke(o,bo);
+ else if (smethod != null && gmethod!=null){
+ bo = (T)gmethod.invoke(o);
+
bo.setValue(line.getOptionValue(fc).toString());
+ smethod.invoke(o,bo);
}
else
throw new Exception("no Field or Method
to set!");
@@ -48,30 +51,27 @@
}
+ @SuppressWarnings("unchecked")
public Option getOption() {
String n = getName();
- String lbound="\u2264";
- String ubound="\u2264";
-
-
- //System.out.println("creating option for: " + n);
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
-
+ String fc = n.substring(ind);
+
+ T currentValue = null;
if( f!=null){
+ try{
+ bo = (T) f.get(o);
+ }catch (Exception e){e.printStackTrace();}
if(bo.isLowerBoundStrict())lbound="<";
if(bo.isUpperBoundStrict())ubound="<";
return new Option(fc, true,"-- " +t.description() +"
--\n current value : "+bo.getValue()+ "\n possible value : (" +
bo.getLowerBound()+ " " + lbound + " x " + ubound + " " + bo.getUpperBound() +
")");
- }
- else if(m!=null){
- Type[] types = m.getParameterTypes();
- java.util.List list = new java.util.ArrayList();
- for(int i=0;i<types.length;i++) list.add(i,types[i]);
- return new Option(fc, true,"-- "+ t.description()+"
--\n Method's parameter : "+list);
}
+ else if(gmethod!=null){
+ try{
+ currentValue = (T)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- " +tg.description() +"
--\n current value : "+currentValue.getValue());
+ }
else return null;
}
@@ -82,6 +82,5 @@
formatter.setWidth(100);
System.out.println("\n");
formatter.printHelp("Detailed informations/commands for " + fc
+ " :", options);
- //System.out.println("\nCommands Options for -"+ fc +"\n
(multiple commands can be coupled by inserting \" : \" ) example : -"+fc+"
val.x:up.y:upstrict.true\n\t-"+fc+" val.x : setValue\n\t-"+fc+" up.x :
setUpperBound\n\t-"+fc+" low.x : setLowerBound\n\t-"+fc+" lowstrict.Boolean :
setLowerBoundStrict\n\t-"+fc+" upstrict.Boolean : setUpperBoundStrict\n");
}
}
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/CLHandlerFactory.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,7 +1,10 @@
package org.example.tunable.internal.cl;
-import java.lang.reflect.*;
-import org.example.tunable.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.example.tunable.HandlerFactory;
+import org.example.tunable.Tunable;
import org.example.tunable.util.BoundedDouble;
import org.example.tunable.util.BoundedInteger;
import org.example.tunable.util.FlexiblyBoundedDouble;
@@ -13,26 +16,7 @@
public class CLHandlerFactory implements HandlerFactory<CLHandler> {
public CLHandler getHandler(Method m, Object o, Tunable t) {
- Class<?>[] paramsTypes = m.getParameterTypes();
- if ( paramsTypes.length != 1 ) {
- System.err.println("found bad method");
- return null;
- }
- Class<?> type = paramsTypes[0];
-
- if ( type == int.class || type == Integer.class )
- return new IntCLHandler(m,o,t);
- else if ( type == String.class )
- return new StringCLHandler(m,o,t);
- else if ( type == boolean.class || type == Boolean.class )
- return new BooleanCLHandler(m,o,t);
- else if ( type == BoundedInteger.class )
- return new BoundedCLHandler<BoundedInteger>(m,o,t);
- else if ( type == BoundedDouble.class )
- return new BoundedCLHandler<BoundedDouble>(m,o,t);
- else
- return null;
-
+ return null;
}
public CLHandler getHandler(Method gmethod, Method smethod, Object o,
Tunable tg, Tunable ts){
@@ -50,13 +34,30 @@
if( type == int.class || type == Integer.class)
return new IntCLHandler(gmethod,smethod,o,tg,ts);
- else
- return null;
+ else if( type == Boolean.class || type == boolean.class)
+ return new BooleanCLHandler(gmethod,smethod,o,tg,ts);
+ else if( type == String.class)
+ return new StringCLHandler(gmethod,smethod,o,tg,ts);
+
+ else if( type == BoundedInteger.class)
+ return new
BoundedCLHandler<BoundedInteger>(gmethod,smethod,o,tg,ts);
+ else if( type == BoundedDouble.class)
+ return new
BoundedCLHandler<BoundedDouble>(gmethod,smethod,o,tg,ts);
+
+ else if(type == FlexiblyBoundedInteger.class)
+ return new
FlexiblyBoundedCLHandler<FlexiblyBoundedInteger>(gmethod,smethod,o,tg,ts);
+ else if(type == FlexiblyBoundedDouble.class)
+ return new
FlexiblyBoundedCLHandler<FlexiblyBoundedDouble>(gmethod,smethod,o,tg,ts);
+ else if(type == ListSingleSelection.class)
+ return new
ListSingleSelectionCLHandler<Object>(gmethod,smethod,o,tg,ts);
+ else if(type == ListMultipleSelection.class)
+ return new
ListMultipleSelectionCLHandler<Object>(gmethod,smethod,o,tg,ts);
+ else
+ return null;
}
-
public CLHandler getHandler(Field f, Object o, Tunable t) {
Class<?> type = f.getType();
@@ -65,8 +66,8 @@
else if ( type == String.class )
return new StringCLHandler(f,o,t);
else if ( type == boolean.class || type == Boolean.class )
-
return new BooleanCLHandler(f,o,t);
+
else if ( type == BoundedDouble.class )
return new BoundedCLHandler<BoundedDouble>(f,o,t);
else if ( type == BoundedInteger.class )
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/FlexiblyBoundedCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/FlexiblyBoundedCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/FlexiblyBoundedCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -19,21 +19,16 @@
fbo = (T) f.get(o);
}catch (Exception e){e.printStackTrace();}
}
-
- public FlexiblyBoundedCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
-
+ public FlexiblyBoundedCLHandler(Method gmethod, Method smethod, Object
o, Tunable tg, Tunable ts){
+ super(gmethod,smethod,o,tg,ts);
}
public void handleLine( CommandLine line ) {
String n = getName();
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
+ String fc = n.substring(ind);
argsMap = new HashMap<String,String>();
try {
@@ -57,21 +52,20 @@
String ubound="\u2264";
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
+ String fc = n.substring(ind);
+
+ T currentValue = null;
if( f!=null){
if(fbo.isLowerBoundStrict())lbound="<";
if(fbo.isUpperBoundStrict())ubound="<";
return new Option(fc, true,"-- "+ t.description() +"
--\n current value : "+fbo.getValue()+ "\n possible value : (" +
fbo.getLowerBound()+ " " + lbound + " x " + ubound + " " + fbo.getUpperBound()
+ ")");//+"\n --cmd : display informations
and available commands");
}
- else if(m!=null){
- Type[] types = m.getParameterTypes();
- java.util.List list = new java.util.ArrayList();
- for(int i=0;i<types.length;i++) list.add(i,types[i]);
- return new Option(fc, true,"-- "+ t.description()+"
--\n Method's parameters : "+list);
+ else if(gmethod!=null){
+ try{
+ currentValue = (T)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- " +tg.description() +"
--\n current value : "+currentValue.getValue());
}
else return null;
}
@@ -80,40 +74,49 @@
private void applyArgsValues(Map<String,String> map){
try{
- if(map.containsKey("val"))fbo.setValue(map.get("val"));
-
if(map.containsKey("up"))fbo.setUpperBound(map.get("up"));
-
if(map.containsKey("low"))fbo.setLowerBound(map.get("low"));
-
if(map.containsKey("lowstrict"))fbo.setLowerBoundStrict(Boolean.parseBoolean(map.get("lowstrict")));
-
if(map.containsKey("upstrict"))fbo.setUpperBoundStrict(Boolean.parseBoolean(map.get("upstrict")));
-
- if( f!= null ) f.set(o, fbo);
- else if( m!= null) m.invoke(o, fbo);
+ if( f!= null ){
+
if(map.containsKey("val"))fbo.setValue(map.get("val"));
+
if(map.containsKey("up"))fbo.setUpperBound(map.get("up"));
+
if(map.containsKey("low"))fbo.setLowerBound(map.get("low"));
+
if(map.containsKey("lowstrict"))fbo.setLowerBoundStrict(Boolean.parseBoolean(map.get("lowstrict")));
+
if(map.containsKey("upstrict"))fbo.setUpperBoundStrict(Boolean.parseBoolean(map.get("upstrict")));
+ f.set(o, fbo);
+ }
+ else if(smethod!= null && gmethod!=null) {
+ fbo = (T)gmethod.invoke(o);
+
if(map.containsKey("val"))fbo.setValue(map.get("val"));
+
if(map.containsKey("up"))fbo.setUpperBound(map.get("up"));
+
if(map.containsKey("low"))fbo.setLowerBound(map.get("low"));
+
if(map.containsKey("lowstrict"))fbo.setLowerBoundStrict(Boolean.parseBoolean(map.get("lowstrict")));
+
if(map.containsKey("upstrict"))fbo.setUpperBoundStrict(Boolean.parseBoolean(map.get("upstrict")));
+ smethod.invoke(o, fbo);
+ }
else throw new Exception("no Field or Method to set!");
}catch(Exception e){e.printStackTrace();}
}
+ @SuppressWarnings("unchecked")
public Option getDetailedOption() {
String n = getName();
String lbound="\u2264";
String ubound="\u2264";
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
+ String fc = n.substring(ind);
+ T currentValue = null;
+
if( f!=null){
if(fbo.isLowerBoundStrict())lbound="<";
if(fbo.isUpperBoundStrict())ubound="<";
return new Option(fc, true,"-- "+ t.description() +"
--\n current value : "+fbo.getValue()+ "\n possible value : (" +
fbo.getLowerBound()+ " " + lbound + " x " + ubound + " " + fbo.getUpperBound()
+ ")\nCommands Options for -"+ fc +" :\n (multiple commands can be coupled by
inserting \":\")\n example : -"+fc+" val.x:up.y:upstrict.true \n-"+fc+" val.x
: setValue \n-"+fc+" up.x : setUpperBound \n-"+fc+" low.x : setLowerBound
\n-"+fc+" lowstrict.Boolean : setLowerBoundStrict \n-"+fc+" upstrict.Boolean :
setUpperBoundStrict\n");
}
- else if(m!=null){
- Type[] types = m.getParameterTypes();
- java.util.List list = new java.util.ArrayList();
- for(int i=0;i<types.length;i++) list.add(i,types[i]);
- return new Option(fc, true,"-- "+ t.description()+"
--\n Method's parameters : "+list);
+ else if(gmethod!=null){
+ try{
+ currentValue = (T)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- " +tg.description() +"
--\n current value : "+currentValue.getValue()+ "\n possible value : (" +
currentValue.getLowerBound()+ " " + lbound + " x " + ubound + " " +
currentValue.getUpperBound() + ")\nCommands Options for -"+ fc +" :\n (multiple
commands can be coupled by inserting \":\")\n example : -"+fc+"
val.x:up.y:upstrict.true \n-"+fc+" val.x : setValue \n-"+fc+" up.x :
setUpperBound \n-"+fc+" low.x : setLowerBound \n-"+fc+" lowstrict.Boolean :
setLowerBoundStrict \n-"+fc+" upstrict.Boolean : setUpperBoundStrict\n");
}
else return null;
}
@@ -126,6 +129,5 @@
formatter.setWidth(100);
System.out.println("\n");
formatter.printHelp("Detailed informations/commands for " + fc
+ " :", options);
- //System.out.println("\nCommands Options for -"+ fc +"\n
(multiple commands can be coupled by inserting \" : \" ) example : -"+fc+"
val.x:up.y:upstrict.true\n\t-"+fc+" val.x : setValue\n\t-"+fc+" up.x :
setUpperBound\n\t-"+fc+" low.x : setLowerBound\n\t-"+fc+" lowstrict.Boolean :
setLowerBoundStrict\n\t-"+fc+" upstrict.Boolean : setUpperBoundStrict\n");
}
}
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/IntCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,24 +1,26 @@
package org.example.tunable.internal.cl;
-import java.lang.reflect.*;
-import org.apache.commons.cli.*;
-import org.example.tunable.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.example.tunable.Tunable;
+
public class IntCLHandler extends AbstractCLHandler {
public IntCLHandler(Field f, Object o, Tunable t) {
super(f,o,t);
}
-
- public IntCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
- }
public IntCLHandler(Method gmethod, Method smethod, Object o, Tunable
tg, Tunable ts){
super(gmethod,smethod,o,tg,ts);
}
+
public void handleLine( CommandLine line ) {
String n = getName();
@@ -27,7 +29,7 @@
//if(n.substring(ind).length()<3)fc = n.substring(ind);
//else fc = n.substring(ind,ind+3);
fc = n.substring(ind);
-
+
try {
if ( line.hasOption( fc ) ) {
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
@@ -75,26 +77,26 @@
//else fc = n.substring(ind,ind+3);
fc = n.substring(ind);
Integer currentValue = null;
- if ( f!=null){
+ if (f!=null){
try{
currentValue = (Integer)f.get(o);
}catch(Exception e){e.printStackTrace();}
return new Option(fc, true,"-- " + t.description() + "
--\n current value : "+ currentValue);
}
- else if ( gmethod!=null){
+ else if (gmethod!=null){
try{
currentValue = (Integer)gmethod.invoke(o);
}catch(Exception e){e.printStackTrace();}
return new Option(fc, true,"-- " + tg.description() + "
--\n current value : "+ currentValue);
- //Type[] type = smethod.getParameterTypes();
- //java.util.List list = new java.util.ArrayList();
- //for(int i=0;i<type.length;i++) list.add(i,type[i]);
- //return new Option(fc,true,"-- "+ tg.description() + "
/ " + ts.description() + " --\n Method's set parameter : "+list);
-
+ //Original Design
+/* Type[] type = smethod.getParameterTypes();
+ java.util.List list = new java.util.ArrayList();
+ for(int i=0;i<type.length;i++) list.add(i,type[i]);
+ return new Option(fc,true,"-- "+ tg.description() + " /
" + ts.description() + " --\n Method's set parameter : "+list);
+*/
}
- else return null;
-
+ else return null;
}
private void displayCmds(String fc){
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListMultipleSelectionCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListMultipleSelectionCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListMultipleSelectionCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -17,28 +17,21 @@
}catch (Exception e){e.printStackTrace();}
}
-
- public ListMultipleSelectionCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
- try{
- lms = (ListMultipleSelection<T>)f.get(o);
- }catch (Exception e){e.printStackTrace();}
+ public ListMultipleSelectionCLHandler(Method gmethod,Method
smethod,Object o,Tunable tg,Tunable ts){
+ super(gmethod,smethod,o,tg,ts);
}
-
+
public void handleLine( CommandLine line ) {
String n = getName();
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
+ String fc = n.substring(ind);
try {
if ( line.hasOption( fc ) ) {
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
if(line.getOptionValue(fc).startsWith("[") &&
line.getOptionValue(fc).endsWith("]")){
- String args =
line.getOptionValue(fc).substring(1,line.getOptionValue(fc).length()-1);
+ String args =
line.getOptionValue(fc).substring(line.getOptionValue(fc).indexOf("[")+1,line.getOptionValue(fc).indexOf("]"));
String[] items = args.split(",");
setSelectedItems(items);
}else throw new IllegalArgumentException("Items
must be set as follow : [item1,...,itemX]");
@@ -50,32 +43,58 @@
public Option getOption() {
String n = getName();
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
- return new Option(fc, true,"-- "+t.description() +" --\n
current selected values : "+lms.getSelectedValues()+"\n available values : "+
lms.getPossibleValues());
+ String fc = n.substring(ind);
+ ListMultipleSelection<Object> currentValue = null;
+
+ if(f!=null){
+ return new Option(fc, true,"-- "+t.description() +"
--\n current selected values : "+lms.getSelectedValues()+"\n available values
: "+ lms.getPossibleValues());
+ }
+ else if(gmethod!=null){
+ try{
+ currentValue =
(ListMultipleSelection<Object>)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- "+tg.description() +"
--\n current selected values : "+currentValue.getSelectedValues()+"\n
available values : "+ currentValue.getPossibleValues());
+ }
+ else
+ return null;
}
+
private void setSelectedItems(String[] items){
java.util.List<T> list = new java.util.ArrayList<T>();
for(String str : items) list.add((T)str);
- lms.setSelectedValues(list);
try{
- if( f!= null) f.set(o, lms);
- else if( m!= null) m.invoke(o, lms);
+ if(f!=null){
+ lms.setSelectedValues(list);
+ f.set(o, lms);
+ }
+ else if(gmethod!=null && smethod!=null){
+ lms = (ListMultipleSelection<T>)
gmethod.invoke(o);
+ lms.setSelectedValues(list);
+ smethod.invoke(o, lms);
+ }
else throw new Exception("no Field or Method to set!");
}catch(Exception e){e.printStackTrace();}
}
+
public Option getDetailedOption() {
String n = getName();
- //System.out.println("creating option for: " + n);
int ind = n.lastIndexOf(".")+1;
String fc;
if(n.substring(ind).length()<3)fc = n.substring(ind);
else fc = n.substring(ind,ind+3);
- return new Option(fc, n, true,"-- "+t.description() +" --\n
current selected values : "+lms.getSelectedValues()+"\n available values : "+
lms.getPossibleValues() +"\n to set items : -"+fc+" [item1,...,itemX]");
+ if(f!=null){
+ return new Option(fc, n, true,"-- "+t.description() +"
--\n current selected values : "+lms.getSelectedValues()+"\n available values
: "+ lms.getPossibleValues() +"\n to set items : -"+fc+" [item1,...,itemX]");
+ }
+ else if(gmethod!=null){
+ try{
+ lms = (ListMultipleSelection<T>)
gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, n, true,"-- "+tg.description() +"
--\n current selected values : "+lms.getSelectedValues()+"\n available values
: "+ lms.getPossibleValues() +"\n to set items : -"+fc+" [item1,...,itemX]");
+ }
+ else
+ return null;
}
private void displayCmds(String fc){
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListSingleSelectionCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListSingleSelectionCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/ListSingleSelectionCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -10,6 +10,7 @@
ListSingleSelection<T> lss;
+
public ListSingleSelectionCLHandler(Field f, Object o, Tunable t) {
super(f,o,t);
try{
@@ -17,32 +18,29 @@
}catch (Exception e){e.printStackTrace();}
}
-
- public ListSingleSelectionCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
- try{
- lss = (ListSingleSelection<T>)f.get(o);
- }catch (Exception e){e.printStackTrace();}
+ public ListSingleSelectionCLHandler(Method gmethod,Method
smethod,Object o, Tunable tg, Tunable ts){
+ super(gmethod,smethod,o,tg,ts);
}
+
public void handleLine( CommandLine line ) {
String n = getName();
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
+ String fc = n.substring(ind);
+
+
try {
if ( line.hasOption( fc ) ) {
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
if( f!= null){
lss.setSelectedValue((T)line.getOptionValue(fc));
- f.set(o, lss);
+ f.set(o,lss);
}
- else if( m!= null){
+ else if(smethod!= null && gmethod!=null){
+ lss =
(ListSingleSelection<T>)gmethod.invoke(o);
lss.setSelectedValue((T)line.getOptionValue(fc));
- m.invoke(o, lss);
+ smethod.invoke(o,lss);
}
else throw new Exception("no Field or Method to
set!");
}
@@ -53,11 +51,19 @@
public Option getOption() {
String n = getName();
int ind = n.lastIndexOf(".")+1;
- String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
- fc = n.substring(ind);
- return new Option(fc, true,"-- "+ t.description()+" --\n
current selected value : "+lss.getSelectedValue()+"\n available values :
"+lss.getPossibleValues());
+ String fc = n.substring(ind);
+ ListSingleSelection<T> currentValue = null;
+
+ if(f!=null){
+ return new Option(fc, true,"-- "+ t.description()+"
--\n current selected value : "+lss.getSelectedValue()+"\n available values :
"+lss.getPossibleValues());
+ }
+ else if (gmethod!=null){
+ try{
+ currentValue = (ListSingleSelection<T>)
gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc, true,"-- "+ tg.description()+"
--\n current selected value : "+currentValue.getSelectedValue()+"\n available
values : "+currentValue.getPossibleValues());
+ }
+ else return null;
}
private void displayCmds(String fc){
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/StringCLHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/StringCLHandler.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/internal/cl/StringCLHandler.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -1,11 +1,18 @@
-
package org.example.tunable.internal.cl;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
-import org.apache.commons.cli.*;
-import org.example.tunable.*;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.example.tunable.Tunable;
+/**
+ * @author Mathieu
+ *
+ */
public class StringCLHandler extends AbstractCLHandler {
@@ -13,8 +20,12 @@
super(f,o,t);
}
- public StringCLHandler(Method m, Object o, Tunable t) {
- super(m,o,t);
+// public StringCLHandler(Method m, Object o, Tunable t) {
+// super(m,o,t);
+// }
+
+ public StringCLHandler(Method gmethod, Method smethod, Object o,
Tunable tg, Tunable ts){
+ super(gmethod,smethod,o,tg,ts);
}
public void handleLine( CommandLine line ) {
@@ -29,8 +40,8 @@
if(line.getOptionValue(fc).equals("--cmd")){displayCmds(fc);System.exit(1);}
if ( f != null )
f.set(o,line.getOptionValue(fc) );
- else if ( m != null )
- m.invoke(o,line.getOptionValue(fc));
+ else if ( smethod != null )
+
smethod.invoke(o,line.getOptionValue(fc).toString());
else
throw new Exception("no Field or Method
to set!");
}
@@ -41,12 +52,9 @@
public Option getOption() {
String n = getName();
- //System.out.println("creating option for: " + n);
int ind = n.lastIndexOf(".")+1;
String fc;
- //if(n.substring(ind).length()<3)fc = n.substring(ind);
- //else fc = n.substring(ind,ind+3);
fc = n.substring(ind);
String currentValue = null;
@@ -56,11 +64,11 @@
}catch(Exception e){e.printStackTrace();}
return new Option(fc, true,"-- " + t.description()+"
--\n current value : "+ currentValue);
}
- else if(m!=null){
- Type[] types = m.getParameterTypes();
- java.util.List list = new java.util.ArrayList();
- for(int i=0;i<types.length;i++) list.add(i,types[i]);
- return new Option(fc, true,"-- "+ t.description()+"
--\n Method's parameters : "+list);
+ else if(gmethod!=null){
+ try{
+ currentValue=(String)gmethod.invoke(o);
+ }catch(Exception e){e.printStackTrace();}
+ return new Option(fc,true,"-- "+tg.description()+" --\n
current value : "+currentValue);
}
else return null;
}
Modified:
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/util/ListMultipleSelection.java
===================================================================
---
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/util/ListMultipleSelection.java
2009-06-09 02:56:16 UTC (rev 16875)
+++
csplugins/trunk/ucsd/mes/anntun/src/main/java/org/example/tunable/util/ListMultipleSelection.java
2009-06-09 15:45:30 UTC (rev 16876)
@@ -87,10 +87,10 @@
if (vals == null)
throw new NullPointerException("value list is null");
- for (T v : vals)
+ for (T v : vals){
if (!values.contains(v))
throw new IllegalArgumentException("value not
contained in list of possible values\n possible items =
"+this.getPossibleValues());
-
+ }
selected = new ArrayList<T>(vals);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---