Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > storing multiple vectors

Reply
Thread Tools

storing multiple vectors

 
 
chewie54
Guest
Posts: n/a
 
      02-20-2008
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
 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      02-20-2008
In article
<a08a122a-4d5c-442b-adfb->,
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
 
Reply With Quote
 
 
 
 
Lord Zoltar
Guest
Posts: n/a
 
      02-20-2008
On Feb 20, 11:31*am, chewie54 <dfabrizi...@gmail.com> 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.
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      02-20-2008
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/>
 
Reply With Quote
 
John W. Kennedy
Guest
Posts: n/a
 
      02-20-2008
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"
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      02-20-2008
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.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      02-21-2008
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
 
Reply With Quote
 
chewie54
Guest
Posts: n/a
 
      02-21-2008
On Feb 20, 7:30 pm, Lew <l...@lewscanon.com> 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



 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      02-21-2008
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
 
Reply With Quote
 
Daniel Pitts
Guest
Posts: n/a
 
      02-21-2008
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/>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ primer statement about vectors containing vectors pauldepstein@att.net C++ 3 03-26-2008 06:22 PM
Beginner's problem: inheritence and vectors storing bookings Mike Jolley C++ 8 12-13-2006 09:56 PM
Ruby, SWIG and C++: how to properly wrap vector of vectors of doubles (2D vectors)? Ruby 0 09-14-2005 05:47 PM
Storing objects in vectors - what's wrong with this code? Alfonso Morra C++ 6 07-18-2005 01:54 AM
Storing Sockets in Vectors causes loss of connection Gordon Beaton Java 6 10-30-2003 10:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57