473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems getting an object from hashmap

1
hi,

I am troubled by a small problem. I am now using a graph metod which uses edge to connect various places in a map. So i created a hashmap which takes in String
and an arraylist (edge) which states the destinations from that string along with the travel time.

But how to find connections between two places?

t.ex, a to b takes 15mins by buss , b to c takes 10mins by train,
so if i want to find connection between a to c, it should show me exactly that and the total time.

To add new places and to connect them works. Only to find connections is the problem..

Thanks in forehand

pasting the java codes.

Expand|Select|Wrap|Line Numbers
  1. class PlaceGraph<N> implements Graph <N> {
  2.  
  3.     private Map<N, List<Edge<N>>> allp = new HashMap <N, List<Edge<N>>>();
  4.  
  5.  
  6.     public void addNode(N node){
  7.     if (!allp.containsKey(node))
  8.         allp.put(node, new ArrayList<Edge<N>>());
  9.     else 
  10.         System.out.println ("Same name found");
  11.     }
  12.  
  13.  
  14.     public void connect (N from, N to, String med, int traveltime){
  15.  
  16.     List<Edge<N>> flist = allp.get(from);
  17.     List<Edge<N>> tlist = allp.get(to);
  18.  
  19.     if (flist == null || tlist ==null)
  20.         throw new NoSuchElementException();
  21.     if (traveltime<0)
  22.         throw new IllegalArgumentException();
  23.  
  24.  
  25.     Edge<N> e1 = new Edge<N> (to, med, traveltime);
  26.     flist.add(e1);
  27.     Edge<N> e2 = new Edge<N> (from, med, traveltime);
  28.     tlist.add(e2);
  29.     }
  30.  
  31.  
  32.     PROBLEM HERE/public void find(N b, N d){
  33.  
  34.     }
  35.  
  36.       public String toString(){
  37.       String str = " ";
  38.     for (Map.Entry<N, List<Edge<N>>> p : allp.entrySet()){
  39.         str+=p.getKey() + " : ";
  40.         for (Edge e : p.getValue())
  41.         str += e.toString()+ " ";
  42.         str += "\n";
  43.     }
  44.     return str ;
  45.       }
  46. }
  47.  
  48. //Edge class contains three variables. Destination, medium of travel and traveltime.
  49.  
Mar 20 '08 #1
0 1140

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christian Gollwitzer | last post by:
Hi, I'm trying to loop over the elements in a hashmap of the STL-implementation by SGI. The point is, that because the key/value pair is stored as std::pair in the COntainer, the code becomes...
4
by: David | last post by:
Hi, I have created the following HashMap class. class HashMap: public hash_map<string, string, HashString, HashStringCompare> { public: HashMap(): hash_map<string, string, HashString,...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
2
by: xor | last post by:
I'm doing up a school project using java, and am a little new to it (I've worked with other languages for years though). I've seen code posted by the instructor using HashMap like this... ...
4
by: panos100m | last post by:
Hi these are the conents of my hashmap printing out the entrySet. entrySet1: OrderDate=10/30/2007, entrySet2: Level_0={Item_0={ItemTotal= 3.99, ItemName=test® in, ShipDate=10/31/2007,...
15
by: lbrtchx | last post by:
Hi, ~ I have found myself in need of some code resembling a Hashmap ~ This is easily done in Java this way: ~ import java.util.*; // __ public class JMith00Test{
1
by: viswanathtvs | last post by:
java.util.NoSuchElementException javax.faces.el.EvaluationException: java.util.NoSuchElementException at...
3
dlite922
by: dlite922 | last post by:
I could have this done in php in three lines of code but in Java here's what I need to do: English Looping through list of words I call a function that returns a HashSet of movie titles that...
1
by: evelina | last post by:
Hello, I need help. I have the following hashmap: HashMap<HashMap<Dimension, Integer>, String> mapList = new HashMap<HashMap<Dimension, Integer>, String>(); I want to extract Dimesion from the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.