HasSet vs ArrayList and modelling issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    HasSet vs ArrayList and modelling issue

    Hello,

    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:
    Code:
    //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;
    }
    Now, in MySignature I used a Linked hashSet because I want to keep the order of insertion (and I know that I can't have two params with the same ID, here overrivde properly) since the Parser parser the list of parameters in the order they are written.
    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.
Working...