Wednesday, 15 July 2015

java - Casting Issues with a WritableList -



java - Casting Issues with a WritableList -

i using writablelist store dataset info user adds application.

public class aplotdatamodel { iobservablelist observablelist = new writablelist(); private static aplotdatamodel instance = null; ////////////////////////////////////////////////////////////////////////// // constructor // ////////////////////////////////////////////////////////////////////////// private aplotdatamodel() { }// end constructor ////////////////////////////////////////////////////////////////////////// // singletonselecttable getinstance() // ////////////////////////////////////////////////////////////////////////// public static aplotdatamodel getinstance() { if (instance == null) { instance = new aplotdatamodel(); } homecoming instance; } ////////////////////////////////////////////////////////////////////////// // add() // ////////////////////////////////////////////////////////////////////////// public void add(tccomponentitemrevision tcrevision, tccomponentdataset selecteddataset) { aplotdatasetdata pp = new aplotdatasetdata(tcrevision, selecteddataset); if (!observablelist.contains(pp)) { observablelist.add(pp); } } ////////////////////////////////////////////////////////////////////////// // cleartablearray() // ////////////////////////////////////////////////////////////////////////// public void cleartablearray() { observablelist.clear(); } }// end class

in add together method, using class format info add together writable list

aplotdatasetdata pp = etc.....

class

public class aplotdatasetdata { tccomponentitemrevision rev; tccomponentdataset componentdataset; string markup = "no"; ////////////////////////////////////////////////////////////////////////// // constructor // ////////////////////////////////////////////////////////////////////////// public aplotdatasetdata(tccomponentitemrevision tcrevision, tccomponentdataset selecteddataset) { rev = tcrevision; componentdataset = selecteddataset; }// end constructor ////////////////////// // getdataset() // ////////////////////// public tccomponent getdataset() { homecoming componentdataset; } ////////////////// // getrev() // ////////////////// public tccomponent getrev() { homecoming rev; } ////////////////// // equals() // ////////////////// @override public boolean equals(object o) { aplotdatasetdata p = (aplotdatasetdata) o; if (rev.equals(p.getrev()) && componentdataset.equals(p.getdataset())) { homecoming true; } else { homecoming false; } }// end equals()

my code compiles - run operation involving writable list. next error.

error: 11:31:00,591 - tclogger$ic_loglistener.logging:? org.eclipse.core.runtime - org.eclipse.ui - 0 - unhandled event loop exception org.eclipse.swt.swtexception: failed execute runnable (java.lang.classcastexc eption: org.eclipse.core.databinding.observable.list.writablelist cannot cast com.lexmark.aplot.datamodels.aplotdatamodel$aplotdatasetdata) etc .....

caused by: java.lang.classcastexception: org.eclipse.core.databinding.observable .list.writablelist cannot cast com.lexmark.aplot.datamodels.aplotdatamodel $aplotdatasetdata @ com.lexmark.aplot.datamodels.aplotdatamodel$aplotdatasetdata.equals(a plotdatamodel.java:167)

i know issue in equals method, not sure how alter it, work writable list.

edit

i traced issue this

arraylist<aplotdatamodel.aplotdatasetdata> tabledata = new arraylist<aplotdatamodel.aplotdatasetdata>(aplotdatamodel.getinstance().getobservablelist());

i trying create new arraylist using info writablelist

the problem in equals method. had create method more robust.

//////////////////// // hashcode() // /////////////////// @override public int hashcode() { final int prime = 31; int result = 1; result = prime * result + getoutertype().hashcode(); result = prime * result + ((componentdataset == null) ? 0 : componentdataset.hashcode()); result = prime * result + ((rev == null) ? 0 : rev.hashcode()); homecoming result; } //////////////////// // equals() // //////////////////// @override public boolean equals(object obj) { if (this == obj) homecoming true; if (obj == null) homecoming false; if (getclass() != obj.getclass()) homecoming false; aplotdatasetdata other = (aplotdatasetdata) obj; if (!getoutertype().equals(other.getoutertype())) homecoming false; if (componentdataset == null) { if (other.componentdataset != null) homecoming false; } else if (!componentdataset.equals(other.componentdataset)) homecoming false; if (rev == null) { if (other.rev != null) homecoming false; } else if (!rev.equals(other.rev)) homecoming false; homecoming true; } private aplotdatamodel getoutertype() { homecoming aplotdatamodel.this; }

java list swt observable

No comments:

Post a Comment