Hello.
I got bunch of active objects, which I request via my service. Then I would like to put them exactly in that order to map (as keys).
I tryed HashMap and LinkedHashMap - both throw me an exception
java.lang.ClassCastException: $Proxy1473 cannot be cast to java.lang.Comparable
I tryed to implement my entity's interface (@Implementation(OptionEntityImpl.class)) and add compareTo method, but it didn't helped.
How can I make my active objects Comparable?
Thanks in advance.
Community moderators have prevented the ability to post new answers.
I would think that provided your Entity interface extends Comparable it would work. Something like this
@Implementation(OptionEntityImpl.class) public interface OptionEntity extends Entity, Comparable<OptionEntity> { } class OptionEntityImpl implements Comparable<OptionEntity> { private final OptionEntity delegate; public OptionEntityImpl(OptionEntity delegate) { this.delegate = delegate; } public int compareTo(OptionEntity delegate) { // add compareTo implementation here } }
This doesn't seem to work for me - I don't understand how, if I implement that interface, it will make AO use my implementation - it uses dynamic proxies.
I tried having my interface implement comparable as well as entity and now I get NPEs from AO when it initializes:
Interface looks like:
public interface AttachmentInfo extends Entity, Comparable<AttachmentInfo> {
Exceptions look like:
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at net.java.ao.types.TypeManager.getType(TypeManager.java:51)
at net.java.ao.types.TypeManager.getType(TypeManager.java:45)
at net.java.ao.Common.getValueFields(Common.java:486)
at net.java.ao.EntityManager.create(EntityManager.java:425)
at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.create(EntityManagedActiveObjects.java:89)
at <Method where I try to create an object>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FWIW, I figured out that I probably don't want that anyways. The objects didn't really have a natural sorting. I wanted to preserve the order I inserted them, but also deduplicate them (using set semantics). I don't think TreeSet is the right thing for that here, and I'm not aware of a data structure good for that, so I used two. I kept a list to preserve order I wanted, and a set to dedupe. I consulted the set first, to see if the object was "already had", then inserted it into both if it wasn't seen before, so the list kept order preserved.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.