I must implement a class MyMethod; read a method declaration from a file with a parser, and while parsing I must fill that MyMethod Object.
Now, at the moment this my objects are in this fashion:
Expand|Select|Wrap|Line Numbers
- //allow me all public to reduce code verbosity
- class MyMethod {
- public Signature s;
- public String returnedType;
- }
- class MySignature {
- public String name;
- //public List<MyVar> vars = new ArrayList<Var>();
- public Set<MyVar> vars = new LinkedHashSet<MyVar>(); //eg, (int x, String s, int y)'
- }
- class MyVar { //eg. 'int x'
- public String id;
- public String type;
- }
I want to keep a position field because I would like, given an id (eg, 'x'), find its position within a certain signature WITHOUT iterate over all list of parameters (I suppose this is slower). So:
- was it better to iterate on it (and better declare it as ArrayList) ? using arrayList I could avoid the position "problem", since I can retrieve it from iterating on the List.
- assuming to really need the position, where could I put it ? Within MyVar?
- assuming to use the Set, how can I override equals in MyVar to cope this situation (ie. no at most one MyVar with a certain Id)
thanks.