Java Doc for Arguments.java in  » Science » Cougaar12_4 » org » cougaar » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Cougaar12_4 » org.cougaar.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.cougaar.util.Arguments

Arguments
final public class Arguments extends AbstractMap> implements Serializable(Code)
A "name=value" parser.

Note that Arguments instances are unmodifiable, like Strings.

Example use:

 Arguments args = new Arguments("x=y, q=one, q=two, z=99");
 String x = args.getString("x");
 assert "y".equals(x);
 int z = args.getInt("z", 1234);
 assert z == 99;
 List<String> q = args.getStrings("q");
 assert q != null && q.size() == 2;
 

The Cougaar component model includes built-in support to invoke an optional "setArguments" method. Here's an example:

 package org;
 public class MyPlugin ... {
 private Arguments args;
 // The "setArguments" method is special -- it's an optional method
 // that's found by the component model via reflection.  The passed-in
 // arguments instance is created via:
 //    new Arguments(listOfStrings, classname);
 public void setArguments(Arguments args) { this.args = args; }
 public void load() {
 super.load();
 // Get the value of our "foo" argument
 //
 // First looks for a plugin XML argument named "foo",
 // next looks for a "-Dorg.MyPlugin.foo=" system property,
 // otherwise the value will be the 1234 default.
 int foo = args.getInt("foo", 1234);
 System.out.println("foo is "+foo);
 }
 }
 

The Arguments.callSetters method supports "setter" reflection, for example:

 package org;
 public class MyPlugin ... {
 private int foo = 1234;
 public void setArguments(Arguments args) { args.callSetters(this); }
 // This "setNAME(TYPE)" method is found by reflection.
 // The args class will only invoke the setters for which it has values.
 public void setFoo(int i) { this.foo = i; }
 public void load() {
 super.load();
 System.out.println("foo is "+foo);
 }
 }
 

Inner Class :interface OptimizedMap extends Map<String, List<String>>

Field Summary
final public static  ArgumentsEMPTY_INSTANCE
    

Constructor Summary
public  Arguments(Object o)
    
public  Arguments(Object o, Object propertyPrefix)
    
public  Arguments(Object o, Object propertyPrefix, Object deflt)
    
public  Arguments(Object o, Object propertyPrefix, Object deflt, Object keys)
    
Parameters:
  o - the optional input object, e.g.

Method Summary
public  Set<String>callSetters(Object o)
     Call the given object's setter methods or fields for every name=value pair in the Arguments.entrySet , return the Set of unknown String keys.
public  booleancontainsKey(Object key)
    
public  Set<Map.Entry<String, List<String>>>entrySet()
    
public  List<String>get(String key)
    
public  booleangetBoolean(String key)
    
public  booleangetBoolean(String key, boolean deflt)
    
public  List<Boolean>getBooleans(String key)
    
public  List<Boolean>getBooleans(String key, List<Boolean> deflt)
    
public  doublegetDouble(String key)
    
public  doublegetDouble(String key, double deflt)
    
public  List<Double>getDoubles(String key)
    
public  List<Double>getDoubles(String key, List<Double> deflt)
    
public  intgetInt(String key)
    
public  intgetInt(String key, int deflt)
    
public  List<Integer>getInts(String key)
    
public  List<Integer>getInts(String key, List<Integer> deflt)
    
public  longgetLong(String key)
    
public  longgetLong(String key, long deflt)
    
public  List<Long>getLongs(String key)
    
public  List<Long>getLongs(String key, List<Long> deflt)
    
public  StringgetString(String key)
    
public  StringgetString(String key, String deflt)
     Get the first value, or the specified default if there is no value.
public  List<String>getStrings(String key, List<String> deflt)
     All the other "get*" methods call this method.
public  List<String>getStrings(String key)
    
public  ArgumentssetString(String key, String value)
    
public  ArgumentssetStrings(String key, List<String> values)
    
public  intsize()
    
public  List<Arguments>split()
     Split this arguments instance of String-to-List[N] pairs into a List of "flattened" Arguments with String-to-List[1] pairs.
public  Argumentsswap(String key1, String key2)
     Return an Arguments instance where the values for key1 and key2 are swapped.
public  StringtoString()
    
public  StringtoString(String format)
    
public  StringtoString(String format, String separator)
     Create a string representation of this map using the given format.
 For example, if our map contains:
 A=B
 X=V0,V1,V2
 then:
 toString("the_$key is the_$value", " * ");
 would return:
 the_A is the_B * the_X is the_V0
 and:
 toString("($key eq $vals)", " +\n");
 would return:
 (A eq B) +
 (X eq [V0, V1, V2])
 and:
 toString("$key=$veach", "&");
 would return a URL-like string:
 A=B&X=V0&X=V1&X=V2
 and:
 "{" + toString("$key=$vlist", ", ") + "}";
 would return the standard 
Map.toString  format:
 {A=[B], X=[V0, V1, V2]}
 
The supported variables are:
  • "$key" is the string key name (e.g.

Field Detail
EMPTY_INSTANCE
final public static Arguments EMPTY_INSTANCE(Code)
A singleton instance for an empty arguments




Constructor Detail
Arguments
public Arguments(Object o)(Code)



Arguments
public Arguments(Object o, Object propertyPrefix)(Code)



Arguments
public Arguments(Object o, Object propertyPrefix, Object deflt)(Code)



Arguments
public Arguments(Object o, Object propertyPrefix, Object deflt, Object keys)(Code)

Parameters:
  o - the optional input object, e.g. a List of name=value Strings, oranother Arguments instance.
Parameters:
  propertyPrefix - the optional SystemProperties property prefix, e.g."org.MyPlugin.", for "-Dorg.MyPlugin.name=value" lookups. If aclass is specified, that class's name+. and its parent'snames+. will be used.
Parameters:
  deflt - the optional default values, e.g. a List of name=valueStrings, or another Arguments instance.
Parameters:
  keys - the optional filter on which keys are allowed, e.g. onlyallow (A, B, C)




Method Detail
callSetters
public Set<String> callSetters(Object o)(Code)
Call the given object's setter methods or fields for every name=value pair in the Arguments.entrySet , return the Set of unknown String keys.

For example, the name=value pair "x=y" will look for:

 public void setX(type) {..}
 
and field:
 public type x;
 
If neither are found then "x" will be included in the returned Set.
Parameters:
  o - Object that has the setter methods & fields Subset of the Arguments.keySet that could not be set



containsKey
public boolean containsKey(Object key)(Code)



entrySet
public Set<Map.Entry<String, List<String>>> entrySet()(Code)



get
public List<String> get(String key)(Code)



getBoolean
public boolean getBoolean(String key)(Code)
the value, or false if not set



getBoolean
public boolean getBoolean(String key, boolean deflt)(Code)
the first value, or the deflt if not set



getBooleans
public List<Boolean> getBooleans(String key)(Code)
the values, or null if not set



getBooleans
public List<Boolean> getBooleans(String key, List<Boolean> deflt)(Code)
the values, or the deflt if not set



getDouble
public double getDouble(String key)(Code)
the value, or Double.NaN if not set



getDouble
public double getDouble(String key, double deflt)(Code)
the first value, or the deflt if not set



getDoubles
public List<Double> getDoubles(String key)(Code)
the value, or null if not set



getDoubles
public List<Double> getDoubles(String key, List<Double> deflt)(Code)
the values, or the deflt if not set



getInt
public int getInt(String key)(Code)
the value, or -1 if not set



getInt
public int getInt(String key, int deflt)(Code)
the first value, or the deflt if not set



getInts
public List<Integer> getInts(String key)(Code)
the values, or null if not set



getInts
public List<Integer> getInts(String key, List<Integer> deflt)(Code)
the values, or the deflt if not set



getLong
public long getLong(String key)(Code)
the value, or -1 if not set



getLong
public long getLong(String key, long deflt)(Code)
the first value, or the deflt if not set



getLongs
public List<Long> getLongs(String key)(Code)
the value, or null if not set



getLongs
public List<Long> getLongs(String key, List<Long> deflt)(Code)
the values, or the deflt if not set



getString
public String getString(String key)(Code)
the value, or null if not set



getString
public String getString(String key, String deflt)(Code)
Get the first value, or the specified default if there is no value.

Equivalent to:

 List<String> l = get(key);
 return (l == null ? deflt : l.get(0));
 
the first value, or the deflt if not set



getStrings
public List<String> getStrings(String key, List<String> deflt)(Code)
All the other "get*" methods call this method.

Equivalent to:

 List<String> l = get(key);
 return (l == null ? deflt : l);
 
the non-empty values or the deflt



getStrings
public List<String> getStrings(String key)(Code)
same as Arguments.get(String)



setString
public Arguments setString(String key, String value)(Code)

See Also:   Arguments.setStrings
See Also:   



setStrings
public Arguments setStrings(String key, List<String> values)(Code)

Parameters:
  key - the non-null key
Parameters:
  values - the values, which can be null or empty to remove thespecified key's entry returns a possibly new Arguments instance (likeString.trim and similar copy-on-modify classes) where"getStrings(key)" will be equal to the specified "values"



size
public int size()(Code)



split
public List<Arguments> split()(Code)
Split this arguments instance of String-to-List[N] pairs into a List of "flattened" Arguments with String-to-List[1] pairs.

This is useful to group together same-named arguments.

 For example, the constructor input:
 "foo=f1, bar=b1, qux=q1,
 foo=f2, bar=b2, qux=q2,
 foo=f3, bar=b3, qux=q3"
 will be parsed as:
 {foo=[f1,f2,f3], bar=[b1,b2,b3], qux=[q1,q2,q3]}
 and can be split into:
 [{foo=[f1], bar=[b1], qux=[q1]},
 {foo=[f2], bar=[b2], qux=[q2]},
 {foo=[f3], bar=[b3], qux=[q3]}}
 This simplifies iteration:
 for (Arguments a : args.split()) {
 System.out.println("foo is "+a.getString("foo"));
 }
 which will print:
 foo is f1
 foo is f2
 foo is f3
 
a List of Arguments.



swap
public Arguments swap(String key1, String key2)(Code)
Return an Arguments instance where the values for key1 and key2 are swapped.

In other words:

 // given:
 List<String> v1 = args.getStrings(key1);
 List<String> v2 = args.getStrings(key2);
 // do swap:
 Arguments ret = args.swap(key1, key2);
 // validate:
 assert(ret.size() == args.size());
 List<String> x1 = ret.getStrings(key1);
 List<String> x2 = ret.getStrings(key2);
 assert(v1 == null ? x2 == null : v1.equals(x2));
 assert(v2 == null ? x1 == null : v2.equals(x1));
 
returns a new Arguments instance



toString
public String toString()(Code)

See Also:   Arguments.toString(String)
See Also:    Same as "{"+toString(null)+"}"



toString
public String toString(String format)(Code)

See Also:   Arguments.toString(String,String)
See Also:    Same as "toString(format, null)"



toString
public String toString(String format, String separator)(Code)
Create a string representation of this map using the given format.
 For example, if our map contains:
 A=B
 X=V0,V1,V2
 then:
 toString("the_$key is the_$value", " * ");
 would return:
 the_A is the_B * the_X is the_V0
 and:
 toString("($key eq $vals)", " +\n");
 would return:
 (A eq B) +
 (X eq [V0, V1, V2])
 and:
 toString("$key=$veach", "&");
 would return a URL-like string:
 A=B&X=V0&X=V1&X=V2
 and:
 "{" + toString("$key=$vlist", ", ") + "}";
 would return the standard 
Map.toString  format:
 {A=[B], X=[V0, V1, V2]}
 
The supported variables are:
  • "$key" is the string key name (e.g. "X")
  • "$value" is the first value (e.g. "V0"), as defined in Arguments.getString(String)
  • "$vals" is the first value if there is only one value (e.g. "B"), otherwise the list of values prefixed with "[" and "]" if there are multiple values (e.g. "[V0, V1, V2]").
  • "$veach" is current value in the list (e.g. "V1")
  • "$vlist" is the "[]" wrapped list (e.g. "[B]" or "[V0, V1, V2]")

Parameters:
  format - optional format, defaults to "$key=$vlist"
Parameters:
  separator - optional separator, defaults to ", " a string with each entry in the given format, where every "$key"is replaced with the map key and every "$value" is replaced withthe map value.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.