Skip to main content

Conversion of Java Generics to JavaFX sequence in Java Program

2 replies [Last post]
krsheth
Offline
Joined: 2009-04-18
Points: 0

I have created a TwitterFetcher.java which collects the latest 20 tweets and generates a List
I know that I have to convert this Java List into a JavaFX Sequence using Sequences.
Have tried quite a few variations with Sequences.make(...) but to no avail.

following is the code:
import com.sun.javafx.runtime.sequence.Sequence;
import com.sun.javafx.runtime.sequence.Sequences;
import java.util.Iterator;
import org.w3c.dom.TypeInfo;...
..
List ltu = new ArrayList();
TwitterUpdate tu = new TwitterUpdate();
Sequence<? extends TwitterUpdate> stu;
..
.
public Sequence getUpdates()
{
for (Status status : api.getFriendsTimeline())
{
tu.setName(status.getUser().getName());
tu.setScreenName(status.getUser().getScreenName());
tu.setImgURL(status.getUser().getProfileImageUrl());
tu.setTweet(status.getText());
tu.setDate(status.getCreatedAt().toDate().toString());
ltu.add(tu);
}

//convert the List to a Sequence
//return the sequence

Am I missing a step or two or doing something completed wrong.??
I really have to get this done..

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
krsheth
Offline
Joined: 2009-04-18
Points: 0

We are actually following MVC architecture, where in our back end is totally in Java and the rendering is handled in JavaFX..
Hence interop between the two was extremely important..
and the problem was that...
in our JavaFX project...we have packages with only java files and other packages with only JavaFX package..
So whilst importing packages in a JavaFX classes..we can recognize our own java and javafx files...
But whilst in Java classes..recognition of Javafx packages is not possible....
Hence sharing Data structures between the two was difficult...
So we ended up making POJOs..and ported that in JavaFX classes as it was able to recognize Java objects...
We are now using concept of Array of objects and passing it to JavaFX classes as return type..

Regards
Kaustubh

cjmurphy
Offline
Joined: 2003-06-12
Points: 0

That last line really helped:
"We are now using concept of Array of objects and passing it to JavaFX classes as return type..."

Example

Call to Java object metricCalculator, that returns a bunch of HeatAtInterval, where HeatAtInterval is also a Java object:
[code]
def objArray: Object[] = metricCalculator.collectDataForGraph();
[/code]
Can be directly converted to JavaFX sequence:
[code]
objArray as HeatAtInterval[]
[/code]

In collectDataForGraph() (which is Java code):
[code]
public Object[] collectDataForGraph( SporadicList.ErrorOn errorOn)
{
List result = new ArrayList();
....
return result.toArray();
}
[/code]