HashMap Issue

J

jagadesh

Hi Guys,

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

is there any alternates for this approach or can i make a hashmap like
this ?
 
D

dimka

Hi Guys,

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

is there any alternates for this approach or can i make a hashmap like
this ?

Map should contains key, that must be unique.
 
M

Mark Space

jagadesh said:
Hi Guys,

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>


You have to provide a lookup of some sort to "get" your information.
Let's say for example your information is "pages" and your ArrayList and
Status represent the state of a page. You want to look up by page number:

class PageStatus {
int pageNumber;
ArrayList text;
String status;
}


HashMap<Integer, PageStatus> document;

This will let you look up all three in one go, by page number.
Obviously, if you need a different sort of look-up, you'll need to make
a different HashMap.
 
S

Seamus MacRae

Mark said:
You have to provide a lookup of some sort to "get" your information.
Let's say for example your information is "pages" and your ArrayList and
Status represent the state of a page. You want to look up by page number:

class PageStatus {
int pageNumber;
ArrayList text;
String status;
}


HashMap<Integer, PageStatus> document;

This will let you look up all three in one go, by page number.
Obviously, if you need a different sort of look-up, you'll need to make
a different HashMap.

Eh. For that scenario, doesn't an array of PageStatus make more sense?
Page numbers tend to be contiguous. Also, PageStatus may not need to
include the pageNumber field. And the text field should be
List<Something> (String?) rather than raw ArrayList.
 
M

Mark Space

Seamus said:
Eh. For that scenario, doesn't an array of PageStatus make more sense?

I'm not assuming that page numbers are contiguous in this case. He may
be only working with a subset of pages at a time, with the rest held on
disc or something.

Page numbers tend to be contiguous. Also, PageStatus may not need to
include the pageNumber field.

Maybe, but if the page number is required to be passed around as part of
the PageStatus, it costs little to add it to the class. Passing around
page number as a separate parameter is going to get redundant and
tedious, so adding it to the class makes sense to me.

And the text field should be
List<Something> (String?) rather than raw ArrayList.


Should be parameterized, yes. The OP didn't parameterize his List, so I
don't know what type he wants in there. And I matched his type,
ArrayList, just to cause the smallest amount of disruption while
translating his example.
 
S

Seamus MacRae

Peter said:
The OP didn't provide nearly enough information for you to come to those
conclusions. We don't even know what the key for the HashMap is, never
mind that it is the "page Number" he describes.

The post to which I was replying said:

"Let's say for example your information is "pages" and your ArrayList
and Status represent the state of a page. You want to look up by page
number..."

In that context, nothing in my post is unreasonable. Your attitude, on
the other hand, is.
Even the assumption that "text" is a suitable description for the
ArrayList is just that: an assumption.

Perhaps, but if so, it is not an assumption that I made. It was named
that in the post to which I was replying.

If you think that post was jumping to conclusions, take it up with that
post's author and leave me out of it please.
 
L

lord.zoltar

Hi Guys,

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

is there any alternates for this approach or can i make a hashmap like
this ?

Assuming that for everything with the same page number, the status can
be a unique identifier you could do this:

HashMap<int, HashMap<String, ArrayList<SomeOtherType>>>

where the outer hashmap uses pagenumber as a unique key to find status-
list pairs in the inner hashmap...

But I don't know enough about the problem to know if this solution
will work.
 
M

Mark Space

HashMap<int, HashMap<String, ArrayList<SomeOtherType>>>


Just a small quibble: you can't parameterize with a type of int. Use
Integer instead.

But I don't know enough about the problem to know if this solution
will work.


That's kind of the issue we are all struggling with here.
 
M

Mark Rafn

jagadesh said:
i want my own implementation of hashMap.

Not advised, unless you know a lot about it and have a very specific reason.
You may want a class that functions kind of like HashMap, or a class that
extends or uses HashMap, but that's very different than having your own
implementation of HashMap.
get 3 values
1. page Number
2. ArrayList
3. String "status"

Ok, how do you get these values? Are they all unique, and any of them can get
the other? Or is page number a key to get the others?

My guess is the latter.
so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

The normal approach is to make a class PageStatus or somesuch that has all
three values, then use HashMap<Integer, PageStatus> to map page number to the
structure that has all 3.
 
R

Roedy Green

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

is there any alternates for this approach or can i make a hashmap like
this ?

You would use a traditional HashMap with keys as before and objects a
new class with a page number a reference to an array list and a String
Status. This is a standard HashMap implementation. You don't need to
re implement it.

--
Roedy Green Canadian Mind Products
http://mindprod.com

"It wasn’t the Exxon Valdez captain’s driving that caused the Alaskan oil spill. It was yours."
~ Greenpeace advertisement New York Times 1990-02-25
 
T

Tom Anderson

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

You need to explain more clearly what you want to do - we don't understand
the problem.

I assume you want to be able to put entries in like this:

int pageNumber;
List myList;
String status;

JagadeshMap<Integer, List, String> map = new JagadeshMap<Integer, List, String>();
map.put(pageNumber, myList, status);

But how do you want to get entries out? Do you want to look up just by
page number:

map.get(pageNumber);

By any of the values:

map.get(pageNumber);
map.get(status);

Or by some combination of the values:

map.get(pageNumber, status);

?

tom
 
R

Roedy Green

i want my own implementation of hashMap . my requirement is i want to
get 3 values
1. page Number
2. ArrayList
3. String "status"

so i want to make a hashMap with 3 like HashMap<int
PageNumber,ArrayList myList,String status>

see http://mindprod.com/jgloss/hashmap.html#MODIFYING
--
Roedy Green Canadian Mind Products
http://mindprod.com

"It wasn’t the Exxon Valdez captain’s driving that caused the Alaskan oil spill. It was yours."
~ Greenpeace advertisement New York Times 1990-02-25
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top