storing multiple vectors

Discussion in 'Java' started by chewie54, Feb 20, 2008.

  1. chewie54

    chewie54 Guest

    Hi All,

    I'm implementing an Undo/Redo architecture for a graphical CAD type of
    application. I save each command or group of commands the user
    executes in a Vector. In some cases, I will have multiple vectors of
    commands saved that need to be saved in some kind of container or
    list.

    My question is, how can I store multiple vectors (each storing a list
    of commands, 1 or more commands) in some kind of list?


    Thanks in advance,
    Dan
    chewie54, Feb 20, 2008
    #1
    1. Advertising

  2. In article
    <>,
    chewie54 <> wrote:

    > Hi All,
    >
    > I'm implementing an Undo/Redo architecture for a graphical CAD type of
    > application. I save each command or group of commands the user
    > executes in a Vector. In some cases, I will have multiple vectors of
    > commands saved that need to be saved in some kind of container or
    > list.
    >
    > My question is, how can I store multiple vectors (each storing a list
    > of commands, 1 or more commands) in some kind of list?
    >
    >
    > Thanks in advance,
    > Dan


    Have you investigated whether you can make use of the UndoManager and
    related classes?
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Feb 20, 2008
    #2
    1. Advertising

  3. chewie54

    Lord Zoltar Guest

    On Feb 20, 11:31 am, chewie54 <> wrote:
    > Hi All,
    >
    > I'm implementing an Undo/Redo architecture for a graphical CAD type of
    > application.  I save each command or group of commands the user
    > executes in a Vector.  In some cases,  I will have multiple vectors of
    > commands saved that need to be saved in some kind of container or
    > list.
    >
    > My question is,  how can I store multiple vectors (each storing a list
    > of commands, 1 or more commands) in some kind of list?
    >
    > Thanks in advance,
    > Dan



    You want to have a Vector storing other Vectors?
    It should be as simple as:
    Vector v1 = new Vector();
    Vector v2 = new Vector();
    v2.add(v1);

    Do you *NEED* to use Vectors, such as for compatibility with old JVM?
    It seems most people here will recommend you to use List or ArrayList
    instead.
    Lord Zoltar, Feb 20, 2008
    #3
  4. chewie54

    Daniel Pitts Guest

    chewie54 wrote:
    > Hi All,
    >
    > I'm implementing an Undo/Redo architecture for a graphical CAD type of
    > application. I save each command or group of commands the user
    > executes in a Vector. In some cases, I will have multiple vectors of
    > commands saved that need to be saved in some kind of container or
    > list.
    >
    > My question is, how can I store multiple vectors (each storing a list
    > of commands, 1 or more commands) in some kind of list?
    >
    >
    > Thanks in advance,
    > Dan

    You want to look into the Momento Pattern. It is often implemented in
    Java using serialization.

    BTW, Don't use Vectors, there are much more appropriate data structures
    to use, such as the ArrayList implementation of List

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Feb 20, 2008
    #4
  5. Daniel Pitts wrote:
    > chewie54 wrote:
    >> Hi All,
    >>
    >> I'm implementing an Undo/Redo architecture for a graphical CAD type of
    >> application. I save each command or group of commands the user
    >> executes in a Vector. In some cases, I will have multiple vectors of
    >> commands saved that need to be saved in some kind of container or
    >> list.
    >>
    >> My question is, how can I store multiple vectors (each storing a list
    >> of commands, 1 or more commands) in some kind of list?
    >>
    >>
    >> Thanks in advance,
    >> Dan

    > You want to look into the Momento Pattern. It is often implemented in
    > Java using serialization.


    That's "memento".
    --
    John W. Kennedy
    "Information is light. Information, in itself, about anything, is light."
    -- Tom Stoppard. "Night and Day"
    John W. Kennedy, Feb 20, 2008
    #5
  6. chewie54

    Mark Space Guest

    chewie54 wrote:

    > My question is, how can I store multiple vectors (each storing a list
    > of commands, 1 or more commands) in some kind of list?


    Command Pattern:

    http://en.wikipedia.org/wiki/Command_pattern

    "Some kind of list:"

    <http://java.sun.com/javase/6/docs/api/java/util/List.html>

    On that page, on the top part, note that the links to ArrayList and
    LinkedList will probably be the most useful.

    Using Vectors (also a type of List) is possible but Vectors actually
    might not be quite what you want.
    Mark Space, Feb 20, 2008
    #6
  7. chewie54

    Lew Guest

    chewie54 wrote:
    >> My question is, how can I store multiple vectors (each storing a list
    >> of commands, 1 or more commands) in some kind of list?


    Lord Zoltar wrote:
    > Do you *NEED* to use Vectors, such as for compatibility with old JVM?
    > It seems most people here will recommend you to use List or ArrayList
    > instead.


    Well, the OP did say, "vector", not "Vector", so they might not have meant the
    class 'java.util.Vector', though if they did, you're absolutely right. The
    java.util.Vector class was supplanted a decade ago with the various
    implementations of java.util.List.

    To the OP: What you want is a List of Lists of Commands, expressed in Java as:

    List < List <Command>> commandMegaList = new ArrayList <List <Command>> ();

    where List and ArrayList are the standard Java Collections and Command is your
    custom type.

    --
    Lew
    Lew, Feb 21, 2008
    #7
  8. chewie54

    chewie54 Guest

    On Feb 20, 7:30 pm, Lew <> wrote:
    > chewie54 wrote:
    > >> My question is, how can I store multiple vectors (each storing a list
    > >> of commands, 1 or more commands) in some kind of list?

    > Lord Zoltar wrote:
    > > Do you *NEED* to use Vectors, such as for compatibility with old JVM?
    > > It seems most people here will recommend you to use List or ArrayList
    > > instead.

    >
    > Well, the OP did say, "vector", not "Vector", so they might not have meant the
    > class 'java.util.Vector', though if they did, you're absolutely right. The
    > java.util.Vector class was supplanted a decade ago with the various
    > implementations of java.util.List.
    >
    > To the OP: What you want is a List of Lists of Commands, expressed in Java as:
    >
    > List < List <Command>> commandMegaList = new ArrayList <List <Command>> ();
    >
    > where List and ArrayList are the standard Java Collections and Command is your
    > custom type.
    >
    > --
    > Lew


    This is exactly what I have been looking for. My code is very old
    ( started in 1999 )and uses lots of java.util.Vectors, so I guess I
    should change all of them to Lists and ArrayLists. I have been
    reading the Java Tutorial to learn about the Collections Framework.
    Are there any other good references that would help? I'm also
    updating the application to use all the new language features that
    occurred in jdk1.5. Someday, when the Mac gets an official jdk1.6,
    I will use it.


    Thanks everyone for you help.
    Dan
    chewie54, Feb 21, 2008
    #8
  9. chewie54

    Lew Guest

    chewie54 wrote:
    > My code is very old
    > ( started in 1999 )and uses lots of java.util.Vectors, so I guess I
    > should change all of them to Lists and ArrayLists. I have been


    You can change to Lists without abandoning Vector, but ArrayList is the
    drop-in replacement for Vector when the class doesn't need to be inherently
    synchronized.

    Since ArrayList replaced Vector in 1998, "started in 1999" doesn't explain it.

    > reading the Java Tutorial to learn about the Collections Framework.
    > Are there any other good references that would help? I'm also


    The API Javadocs are the obvious starting place, except for your favorite
    search engine ("GIYF"). The Sun tutorial is an excellent starting place; good
    choice.

    > updating the application to use all the new language features that
    > occurred in jdk1.5. Someday, when the Mac gets an official jdk1.6,
    > I will use it.


    AFAIK there were no language changes between Java 5 and Java 6.

    ArrayList and the Collection classes were introduced in Java 1.2. They're not
    "new". (Ten years in I.T. is an eternity.)

    --
    Lew
    Lew, Feb 21, 2008
    #9
  10. chewie54

    Daniel Pitts Guest

    John W. Kennedy wrote:
    > Daniel Pitts wrote:
    >> chewie54 wrote:
    >>> Hi All,
    >>>
    >>> I'm implementing an Undo/Redo architecture for a graphical CAD type of
    >>> application. I save each command or group of commands the user
    >>> executes in a Vector. In some cases, I will have multiple vectors of
    >>> commands saved that need to be saved in some kind of container or
    >>> list.
    >>>
    >>> My question is, how can I store multiple vectors (each storing a list
    >>> of commands, 1 or more commands) in some kind of list?
    >>>
    >>>
    >>> Thanks in advance,
    >>> Dan

    >> You want to look into the Momento Pattern. It is often implemented in
    >> Java using serialization.

    >
    > That's "memento".

    Thank you English Major :)
    I never clammed eye kould spel.

    --
    Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
    Daniel Pitts, Feb 21, 2008
    #10
  11. Daniel Pitts wrote:
    > John W. Kennedy wrote:
    >> Daniel Pitts wrote:
    >>> chewie54 wrote:
    >>>> Hi All,
    >>>>
    >>>> I'm implementing an Undo/Redo architecture for a graphical CAD type of
    >>>> application. I save each command or group of commands the user
    >>>> executes in a Vector. In some cases, I will have multiple vectors of
    >>>> commands saved that need to be saved in some kind of container or
    >>>> list.
    >>>>
    >>>> My question is, how can I store multiple vectors (each storing a list
    >>>> of commands, 1 or more commands) in some kind of list?
    >>>>
    >>>>
    >>>> Thanks in advance,
    >>>> Dan
    >>> You want to look into the Momento Pattern. It is often implemented
    >>> in Java using serialization.

    >>
    >> That's "memento".

    > Thank you English Major :)
    > I never clammed eye kould spel.


    Didn't want to send the poor slob on a wild goose google.


    --
    John W. Kennedy
    "The first effect of not believing in God is to believe in anything...."
    -- Emile Cammaerts, "The Laughing Prophet"
    John W. Kennedy, Feb 22, 2008
    #11
  12. Lew wrote:
    > Since ArrayList replaced Vector in 1998, "started in 1999" doesn't
    > explain it.


    December 8th 1998 according to Wikipedia.

    It may be a bit optimistic to assume that all people switched
    in 4 weeks.

    Arne
    Arne Vajhøj, Feb 23, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordon Beaton
    Replies:
    6
    Views:
    500
  2. Alfonso Morra
    Replies:
    6
    Views:
    297
    Jonathan Mcdougall
    Jul 18, 2005
  3. Mike Jolley
    Replies:
    8
    Views:
    332
    Mike Jolley
    Dec 13, 2006
  4. Replies:
    3
    Views:
    673
    Shadowman
    Mar 26, 2008
  5. Guest
    Replies:
    0
    Views:
    422
    Guest
    Sep 14, 2005
Loading...

Share This Page