I have a connector which has two ports. Two ports have a common root as Resource
. I am trying to find that common root for those two ports.
I need a set of elements for one port(p1) which can be found via getParent
method. For the other port (p2) I need to check if any of p2's element does exist in the set. Although I need this method to return an object of type Resource
, I am bit stuck at this point. I am getting the following error.
Unexpected problem while loading: 'java.lang.ClassCastException: policy.vddl.model.Resource cannot be cast to java.lang.Comparable' java.lang.ClassCastException: vddl.model.Resource cannot be cast to java.lang.Comparable at java.util.TreeMap.compare(Unknown Source) at java.util.TreeMap.put(Unknown Source) at java.util.TreeSet.add(Unknown Source) at vddl.product.Product.findCommonRoot(Product.java:357)
private Element findCommonRoot(Connector connector)
{
List<Port> portList = getListOfPort(connector);
Port p1 = portList.get(0);
Set<Element> portElementSet = new TreeSet<Element>();
Element pathElement = p1.getParent();
while (pathElement != null)
{
portElementSet.add(pathElement);
pathElement = pathElement.getParent();
}
Port p2 = portList.get(1);
Element pathElement2 = p2.getParent();
for(Element e: portElementSet)
{
if(portElementSet.contains(pathElement2))
pathElement2 = e;
}
return pathElement2;
}
Use HashSet
instead TreeSet
if don't need the elements to be sorted. HashSet
is not sorted and doesn't need the elements to be comparable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With