storing multiple vectors

C

chewie54

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
 
S

Steve W. Jackson

chewie54 said:
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?
 
L

Lord Zoltar

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.
 
D

Daniel Pitts

chewie54 said:
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
 
M

Mark Space

chewie54 said:
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.
 
L

Lew

Lord said:
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.
 
C

chewie54

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.

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
 
L

Lew

chewie54 said:
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.)
 
A

Arne Vajhøj

Lew said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top