P
Philipp Kraus
Hello,
I need help to create a data structure. I have got a class
class myEdge {
private int m_edgeid = 0;
….
@Override
public int compareTo(myEdgep_edgelink) {
if (m_edgeid > p_edgelink.m_edgeid)
return 1;
if (m_edgeid < p_edgelink.m_edgeid)
return -1;
return 0;
}
@Override
public boolean equals(Object p_object) {
if ( (p_object == null) || (!(p_object instanceof myEdge)) )
return false;
return this.m_edgeid == ((myEdge)p_object).m_edgeid;
}
@Override
public int hashCode() {
return m_edgeid;
}
}
The edge ID is always unique. So I would like to create a collection in
which I can do something like
myEdge x = edgecollection.get( searching edge id )
So the collection stores the edge objects and I can get an object with
the internal id. The collection
should use the the edgeid value to identify the object.
A set should be the correct structure, but I can not get the object
itself of the map without iteration over all
items. A HashMap needs a key, value pair, so I need also a key class
which stores the edge id (redundant data).
I'm a little bit uncertain, which collection is the correct choice.
Thanks a lot
Phil
I need help to create a data structure. I have got a class
class myEdge {
private int m_edgeid = 0;
….
@Override
public int compareTo(myEdgep_edgelink) {
if (m_edgeid > p_edgelink.m_edgeid)
return 1;
if (m_edgeid < p_edgelink.m_edgeid)
return -1;
return 0;
}
@Override
public boolean equals(Object p_object) {
if ( (p_object == null) || (!(p_object instanceof myEdge)) )
return false;
return this.m_edgeid == ((myEdge)p_object).m_edgeid;
}
@Override
public int hashCode() {
return m_edgeid;
}
}
The edge ID is always unique. So I would like to create a collection in
which I can do something like
myEdge x = edgecollection.get( searching edge id )
So the collection stores the edge objects and I can get an object with
the internal id. The collection
should use the the edgeid value to identify the object.
A set should be the correct structure, but I can not get the object
itself of the map without iteration over all
items. A HashMap needs a key, value pair, so I need also a key class
which stores the edge id (redundant data).
I'm a little bit uncertain, which collection is the correct choice.
Thanks a lot
Phil