Hello I just want to ask how should i get the codes function into a method which is run by the main at the moment! Basically so that I can activate the working method from the main instead. I am new to programming so I am having quite a bit of trouble grasping everything properly
package bla_bla;
import java.io.IOException;
import java.util.ArrayList;
import java.util.*;
import javax.swing.text.html.parser.Element;
import org.codehaus.jackson.map.ObjectMapper;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.select.Evaluator.Id;
import org.json.*;
import argo.saj.InvalidSyntaxException;
public class supermonkey {
private static ArrayList<BugsList> bugsList;
private static ArrayList<BugsList> bugbug;
public static void main(String args[]) throws IOException {
bugsList = new ArrayList<BugsList>();
bugbug = new ArrayList<BugsList>();
Document doc = Jsoup.connect("https://bugzilla.mozilla.org/rest/bug?product=Input&f1=bug_mentor&o1=isnotempty").get();
String rawData = doc.body().text();
// System.out.println(title);
JSONObject obj = new JSONObject(rawData);
// System.out.println(obj);
System.out.println(obj.get("bugs"));
JSONArray jsonMainArr = new JSONArray(obj.get("bugs").toString());
for (int i = 0; i < jsonMainArr.length(); i++) { // **line 2**
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
JSONObject assigned = childJSONObject.getJSONObject("assigned_to_detail");
// JSONObject assigned2 = childJSONObject.getJSONObject("assigned_to_detail");
int id = assigned.getInt("id");
BugsList bug = new BugsList();
BugsList bug2 = new BugsList();
bug.setId(id);
String severity = childJSONObject.getString("severity");
String resolution = childJSONObject.getString("resolution");
String summary = childJSONObject.getString("summary");
String component = childJSONObject.getString("component");
bug.setSeverity(severity);
bug.setResolution(resolution);
bug.setSummary(summary);
bug.setComponent(component);
bugsList.add(bug);
// String severity = assigned.getString();
// System.out.println("sss "+ assigned);
}
getComponent("Code Quality");
// getSeverity(524276);
// getResolution(524276);
// getSummary(524276);
}
public static void getSeverity(int id){
for(int i =0;i<bugsList.size(); i++){
if(bugsList.get(i).getId() == id){
System.out.println("The id exists in the list " + bugsList.get(i).getSeverity());
}
}
}
public static void getResolution(int id){
for(int i =0;i<bugsList.size(); i++){
if(bugsList.get(i).getId() == id){
System.out.println("The id exists in the list and The resolution is" + bugsList.get(i).getResolution());
}
}
}
public static void getSummary(int id){
for(int i =0;i<bugsList.size(); i++){
if(bugsList.get(i).getId() == id){
System.out.println("The comp.. exists in the list and The summary is " + bugsList.get(i).getSummary());
}
}
}
// Current used method
public static ArrayList<BugsList> getComponent(String component){
for(int i =0;i<bugsList.size(); i++){
if(bugsList.get(i).getComponent().equals(component)){
System.out.println("(Code Quality) component contains summary " + bugsList.get(i).getSummary() +" /The resolution is " +
bugsList.get(i).getResolution() + " /Severity is " + bugsList.get(i).getSeverity());
bugbug.add(bugsList.get(i));
}
}
return bugbug;
}
}
package bla_bla;
public class BugsList {
private String severity;
private int id;
private String resolution;
private String summary;
private String component;
public String getComponent() {
return component;
}
public void setComponent(String component) {
this.component = component;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getResolution() {
return resolution;
}
public void setResolution(String resolution) {
this.resolution = resolution;
}
public String getSeverity() {
return severity;
}
public void setSeverity(String severity) {
this.severity = severity;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
I think I understand you problem. You write your code into the main function and that not the solution.
Your main function should look something like that:
public static void main(String args[]) throws IOException {
Supermonkey supermonkey = new Supermonkey();
supermonkey.getComponent("componennt name ");
}
Your Class is Supermonkey and you create an instance call supermonkey (sometime people use mySupermonkey) . There is only one instance of this class that will use.
Then into the constructor method you can create everything to build your instance supermonkey as :
public class Supermonkey {
private ArrayList<BugsList> bugsList;
private ArrayList<BugsList> bugbug;
public Supermonkey(){
bugsList = new ArrayList<BugsList>();
bugbug = new ArrayList<BugsList>();
Document doc = Jsoup
.connect(
"https://bugzilla.mozilla.org/rest/bug?product=Input&f1=bug_mentor&o1=isnotempty")
.get();
String rawData = doc.body().text(); // ... partial code add everything about initialisation of your instance
Then you can have a method of this Class Supermonkey
// Current used method
public ArrayList<BugsList> getComponent(String component) {
for (int i = 0; i < bugsList.size(); i++) {
if (bugsList.get(i).getComponent().equals(component)) {
System.out
.println("(Code Quality) component contains summary "
+ bugsList.get(i).getSummary()
+ " /The resolution is "
+ bugsList.get(i).getResolution()
+ " /Severity is "
+ bugsList.get(i).getSeverity());
bugbug.add(bugsList.get(i));
}
}
return bugbug;
}
A this method is call from the public static void main(String args[]) with supermonkey.getComponent("componennt name ");
Also I think about to change the name of Class BugsList it seems to be a BugItem , may be ?
Related
I've been having some issues with this program. I have to test out using a driver class each method, but I can't seem to understand what I should do when the parameters are strings.
I had an example for int parameters but the example never showed anything on string parameters and how to convert. Using null makes my driver class run but putting an int or string won't.
What can I do to convert this correctly, so it can display whatever I have in the no parameter constructor?
public class StudentListing
{
private String name;
private String number;
public StudentListing(String n, String num)
{
name = n;
number = num;
}
public StudentListing()
{
name = null;
number = null;
}
public String toString()
{
return("Name is " + name +
"\nNumber is " + number + "\n");
}
public void show()
{
System.out.println(toString());
}
public StudentListing Clone()
{
StudentListing clone = new StudentListing (name, number);
return clone;
}
public int compareTo(String targetKey)
{
return (name.compareTo(targetKey));
}
public void input()
{
name = JOptionPane.showInputDialog("Enter a name");
number = JOptionPane.showInputDialog("Enter a number");
}// end of StudentListing
}//end of class
public class StudentListingDriver
{
public static void main(String[] args)
{
StudentListing s1 = new StudentListing();
StudentListing s2 = new StudentListing(null,null);
System.out.println(s1);
s1.input();
StudentListing s3 = s2.clone();
s1.show();
}
}
You can have default values and make the no-args constructor call the other constructor.
Use Integer.parseInt(); to convert from a String to an Integer.
You also need to check the conversion for exceptions.
Like this:
public class StudentListing {
private String name;
private int number;
public StudentListing(String n, int num) {
name = n;
number = num;
}
public StudentListing() {
this("defaultName", 0);
}
public String toString() {
return ("Name is " + name + "\nNumber is " + number + "\n");
}
public void show() {
System.out.println(toString());
}
public StudentListing Clone() {
StudentListing clone = new StudentListing(name, number);
return clone;
}
public int compareTo(String targetKey) {
return (name.compareTo(targetKey));
}
public void input() {
name = JOptionPane.showInputDialog("Enter a name");
number = Integer
.parseInt(JOptionPane.showInputDialog("Enter a number"));
}
}
The tester:
public class StudentListingDriver {
public static void main(String[] args) {
StudentListing s1 = new StudentListing();
StudentListing s2 = new StudentListing(null, 0);
System.out.println(s1);
s1.input();
StudentListing s3 = s2.Clone();
s1.show();
}
}
I know this must be a fundamental design problem because I clearly can't do this. I want to call the ownGrokk, ownTyce, etc methods from another class depending on the value of the integer assigned to OwnedSpirits(int). This in turn fills arrays.
The problem is, I do this multiple times, and doing it from another class it seems like I have to make a new object every time to pass the new int argument, and doing so resets the value of spiritInstance. And, since that resets to zero, the arrays don't fill properly. I try to print out my array values later and I get an "ArrayIndexOutOfBoundsException".
public class OwnedSpirits {
private int spiritTypeInt = 0;
public static int spiritInstance=0;
public static int[] spiritarray = new int[9];
public static String[] spiritName = new String[9];
public static int[] party = new int[3];
public OwnedSpirits(int spiritcall){
if(spiritcall == 1){
ownGrokk();
}
if(spiritcall == 2){
ownRisp();
}
if(spiritcall == 3){
ownTyce();
}
if(spiritcall == 4){
ownDaem();
}
if(spiritcall == 5){
ownCeleste();
}
}
private void ownGrokk(){
spiritName[spiritInstance] = "Grokk";
spiritInstance++;
}
private void ownRisp(){
spiritName[spiritInstance] = "Risp";
spiritInstance++;
}
private void ownDaem(){
spiritName[spiritInstance] = "Daem";
spiritInstance++;
}
private void ownCeleste(){
spiritName[spiritInstance] = "Celeste";
spiritInstance++;
}
private void ownTyce(){
spiritName[spiritInstance] = "Tyce";
spiritInstance++;
}
and this code is in another class, where it attempts to call the methods to fill the array
buttonConfirm.addListener(new ClickListener(){
#Override
public void clicked(InputEvent event, float x, float y) {
if(xcounter==3){
for(x=0; x<3; x++){
if(setdaemtrue == true){
new OwnedSpirits(4);
}
if(setrisptrue == true){
new OwnedSpirits(2);
}
if(setcelestetrue == true){
new OwnedSpirits(5);
}
if(settycetrue == true){
new OwnedSpirits(3);
}
if(setgrokktrue == true){
new OwnedSpirits(1);
}
}
}
}
});
and finally in yet another class:
System.arraycopy(OwnedSpirits.spiritName, 0, partylist, 0, 3);
#Override
public void show() {
System.out.println(partylist[0]);
System.out.println(partylist[1]);
System.out.println(partylist[2]);
spiritlist.setItems(partylist);
table.add(spiritlist);
table.setFillParent(true);
stage.addActor(table);
}
If the last part is confusing, it's because I am using libgdx. the print statements are there just to try to figure out why my list was having an error
I can show you what I would do to handle Spirits, and Parties.
The Spirit class, contains name and current party its assigned to:
package com.stackoverflow.spirit;
public class Spirit {
private String name;
private Party party;
private SpiritType type;
private static int id = 0;
public static enum SpiritType {
Grokk, Risp, Tyce, Daem, Celeste
};
public Spirit(String name, SpiritType type) {
create(name, type);
}
public Spirit(SpiritType type) {
create(null, type);
}
// This is to handle Java inexistance of default parameter values.
private void create(String name, SpiritType type)
{
Spirit.id++;
this.name = (name == null) ? (type.name() + " " + id) : name;
this.type = type;
}
public String getName() {
return name;
}
public Party getParty() {
return party;
}
public SpiritType getType() {
return type;
}
/**
* Used internally by #see Party
* #param party the party this Spirit belongs
*/
public void setParty(Party party) {
this.party = party;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString()
{
return this.name;
}
}
Finally the Party class, contains a set of Spirits, you can add and remove Spirits from the party.
package com.stackoverflow.spirit;
import java.util.HashSet;
public class Party {
private HashSet<Spirit> spirits = new HashSet<Spirit>();
private static int id = 0;
private String name = "Party " + Party.id++;;
public Party() {
}
public Party(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void add(Spirit spirit) {
if (!spirits.contains(spirit)) {
spirits.add(spirit);
if (spirit.getParty() != null) {
//Remove from previous party to update the other party set
spirit.getParty().remove(spirit);
}
spirit.setParty(this);
} else {
// throw new SpiritAlreadyOnParty();
}
}
public void remove(Spirit spirit)
{
if (spirits.contains(spirit))
{
spirit.setParty(null); // You could create a default empty party for "Nature/Neutral" Spirits perhaps :)
spirits.remove(spirit);
}
else {
//throw new SpiritNotInParty();
}
}
public boolean isOnParty(Spirit spirit) {
return spirits.contains(spirit);
}
public ArrayList<Spirit> getSpirits()
{
return new ArrayList<Spirit>(spirits);
}
public int getPartySize() {
return spirits.size();
}
public String getPartyInfo()
{
StringBuilder builder = new StringBuilder();
builder.append("Party:" + this.name + " Size:" + this.spirits.size() + "\n");
for (Spirit s : spirits)
{
builder.append(s.getName() + "\n");
}
return builder.toString();
}
#Override
public String toString()
{
return this.name;
}
}
Here I use the Spirit and Party classes, you could add more functionality, like properties for party strength, magic buffs on the party, etc:
package com.stackoverflow.spirit;
import com.stackoverflow.spirit.Spirit.SpiritType;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
Party griffindor = new Party("Griffindor"), slytherin = new Party(
"Slytherin");
// You can also do for (SpiritType type : SpiritType.values() then
// type.ordinal()
for (int i = 0; i < SpiritType.values().length; i++) {
griffindor.add(new Spirit(SpiritType.values()[i]));
slytherin.add(new Spirit(SpiritType.values()[i]));
}
Spirit mySpirit = new Spirit("NotAHPFan", SpiritType.Celeste);
slytherin.add(mySpirit);
System.out.println("Name of party:" + mySpirit.getParty().getName());
System.out.println("Is on griffindor?:"
+ griffindor.isOnParty(mySpirit));
// What now?
griffindor.add(mySpirit);
System.out.println("Is " + mySpirit.getName() + " on "
+ slytherin.getName() + "?:" + slytherin.isOnParty(mySpirit));
System.out.println(mySpirit.getName() + " is now on "
+ mySpirit.getParty() + "\n");
System.out.println(griffindor.getPartyInfo());
System.out.println(slytherin.getPartyInfo());
}
}
P.D: I'm not a HP fan.
I am attempting to write a program that will output data received from a csv file. The CSV file is composed of 28 or so strings/lines with each data in the line separated by a comma into 5 categories (Team name, League, Coaches, Division and Full Time).
I actually have a couple of issues...
When i run my program, i receive a random sequence of characters (such as: [Ljava.lang.String;#5e34d46a) in my coaches category instead of a name that i am expecting. Does this have something to do with it being in an array? How would i solve it.
The categories for each string are displayed in the output as a list, i would like to output the data of strings into a line. For example, instead of the output displaying:
Team name: Team A
League: Western Conference
Coaches: [Ljava.lang.String;#1c751d58
Division: 2
Full Time: true
I would like it to be displayed as a line.
The last category of a single instance of a string in the output is attached to the first category of the next string. Like so: Full Time: trueTeam name: Team A. How would i separate this?
My Team.java code:
public class Team
{
private String name;
private String league;
private String[] coaches;
private String division;
private boolean fullTime;
public Team(String dataLine)
{
String[] data = dataLine.split(",");
this.name = data[0];
this.coaches = getStringAsArray(data[1], ":");
this.league = data[2];
this.division = data[3];
this.fullTime = data[4].equals("yes");
}
public Team(){
}
private String[] getStringAsArray(String t, String delimiter)
{
String[] result = t.split(delimiter);
return result;
}
private String getArrayAsString(String[] coaches)
{
coaches = this.getCoaches();
String result = "";
for(int i = 0; i<coaches.length; i++)
{
result += coaches[i] +" ";
}
result = result.trim();
return result;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setCoaches(String coaches)
{
this.coaches = getStringAsArray(coaches, ":");
}
public String getCoachesAsString()
{
String result = getArrayAsString(coaches);
return result;
}
public boolean isFullTime() {
return fullTime;
}
public void setFullTime(boolean fullTime) {
this.fullTime = fullTime;
}
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public String[] getCoaches() {
return coaches;
}
public void setCoaches(String[] coaches) {
this.coaches = coaches;
}
public String getLeague() {
return league;
}
public void setLeague(String league) {
this.league = league;
}
#Override
public String toString() {
return "Team name: " + name + "\nLeague: " + this.league + "\nCoaches: " + this.coaches + "\nDivision: " + this.division + "\nFull Time: " + this.fullTime;
}
}
My StoreData.java code:
import shiftershape.model.Team;
import java.util.ArrayList;
public class StoreData {
public static ArrayList<Team> teams = new ArrayList<Team>();
public static String getTeams()
{
String s = "";
for(int i = 0; i < teams.size(); i++){
s += teams.get(i);
}
return s;
}
public static ArrayList<Team> TeamListFromArray(String[] as)
{
ArrayList<Team> teams = new ArrayList<Team>();
// for( int i= 0 ; i < as.length; i++){
for (String s: as){
teams.add(new Team(s));
}
return teams;
}
}
My ReadCSV.java code:
import Utilities.StoreData;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import shiftershape.model.Team;
public class ReadCsv {
public void readCsv() {
String csvFileToRead = "C:/Users/Fryyy/Desktop/FootballRepo/TestData/football_teams_phase1.csv";
BufferedReader br = null;
String line = "";
try {
br = new BufferedReader(new FileReader(csvFileToRead));
int i = 0;
while ((line = br.readLine()) != null) {
Team one = new Team(line);
if(i > 0){
StoreData.teams.add(new Team(line));
}else{
i++;
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static ArrayList<Team> getTeams() {
return StoreData.teams;
}
public static void setTeams(ArrayList<Team> teams) {
StoreData.teams = teams;
}
}
My FootballC.java code:
import Utilities.StoreData;
import shiftershape.model.Team;
public class FootballC {
public static void main(String[] args)
{
ReadCsv junk = new ReadCsv();
junk.readCsv();
System.out.println(StoreData.getTeams());
}
}
System.out.println(StoreData.getTeams()); will call toString() on String[]
try this:
for (String s : StoreData.getTeams()) {
System.out.println(s);
}
[Ljava.lang.String;#5e34d46a) is the resource code for an object when printed to standard out. In this case being a string, so somewhere it looks like you're printing an array instead of the value within the array, causing the resource ID to be shown instead of the values within, as Java doesn't print array contents by default.
[Ljava.lang.String;#1c751d58 is the String version of an array. Arrays don't have a nice toString() method. If you used Lists in stead of Arrays it will print better.
The quick conversion of an array to a list is Arrays.asList(array);
I've got a problem with my programm. When i try to compile following i just receive the message:
Tutorium.java:15: error: <identifier> expected
public void settName(vorlesung.lectureName) {
^
So my Code:
Tutorium.java
public class Tutorium {
private Vorlesung vorlesung;
public String tName;
private int tNumber;
public int gettNumber() {
return this.tNumber;
}
public String gettName() {
return this.tName;
}
public void settName(vorlesung.lectureName) {
this.tName = vorlesung.lectureName;
}
public String toString() {
return (this.tName + ", " + this.tNumber);
}
public Tutorium(int tNumber){
this.tNumber = tNumber; } }
Vorlesung.java
public class Vorlesung {
public String lectureName;
private int lectureNumber;
private int lecture;
private Dozent dozent;
private String lecturerlName;
public String getlectureName(){
return this.lectureName;
}
public int lectureNumber(){
return this.lectureNumber;
}
public int lecture(){
return this.lecture;
}
public String getlecturer(){
this.lecturerlName = dozent.lecturerlName;
return this.lecturerlName;
}
public String toString() {
return (this.lectureName + ", " + this.lectureNumber);
}
public Vorlesung(String lectureName, int lecture) {
this.lectureName = lectureName;
this.lecture = lecture +1;
this.lectureNumber = this.lecture -1;
this.lecturerlName = lecturerlName;
}}
My Main-Method:
public class MainVorlesung {
public static void main(String[] args) {
Student student = new Student("STUDENTNAME", "STUDENTLASTNAME", 178, 1);
Vorlesung vorlesung = new Vorlesung("Programmieren", 13341);
Tutorium tutorium = new Tutorium(3);
Dozent dozent = new Dozent("LECTURERFIRSTNAME", "LECTURERLASTNAME", 815);
System.out.println(student.toString());
System.out.println(vorlesung.toString());
System.out.println(tutorium.toString());
System.out.println(dozent.toString());
}}
My goal is to set the value of tName equal the value of vorlesung.lectureName.
Why can't i do this that way?
I appreciate every help. :)
Thanks
For methods, the arguments that you pass in must have a declared value.
In this case, a String. So you need to change your method to this:
public void settName(String newLectureName) {
this.tName = newLectureName;
}
Read more about what a java method is and how to create one here: http://www.tutorialspoint.com/java/java_methods.htm
Change settName to
public void settName(String name) {
this.tName = name;
}
Since your goal is:
My goal is to set the value of tName equal the value of vorlesung.lectureName.
You should get rid of the setName method entirely since it will depend entirely on the vorlesung field and so should not be changeable. You should also get rid of the tName field, and instead change getName() to:
public class Tutorium {
private Vorlesung vorlesung;
// public String tName; // get rid of
private int tNumber;
public String gettName() {
if (vorlesung != null) {
return vorlesung.getlecturer();
}
return null; // or throw exception
}
// *** get rid of this since you won't be setting names
// public void settName(Vorlesung vorlesung) {
// this.tName = vorlesung.lectureName;
// }
I have just now noticed that your Tutorium class does not have and absolutely needs a setVorlesung(...) method.
public void setVorlesung(Vorlesung vorlesung) {
this.vorlesung = vorlesung;
}
Essentially, this is the kind of data I want returned:
{
"Top10BidAsks":[
{
"Bid":{
"Price":10.0,
"Size":2.0,
"ExchangeID":"SMART",
"timeStamp":0
},
"Ask":{
"Price":12.0,
"Size":2.0,
"ExchangeID":"SMART",
"timeStamp":0
}
},
{
"Bid":{
"Price":0.0,
"Size":0.0,
"ExchangeID":"SMART",
"timeStamp":0
},
"Ask":{
"Price":13.0,
"Size":12.0,
"ExchangeID":"SMART",
"timeStamp":0
}
}
]
}
The {"Price":10.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}, essentially represents a MarketData Object that I've created with those 4 fields.
The main function I'm calling is:
public MarketDataListLevel2 getMarketDataDepth() {
try {
MarketDataListLevel2 md = cs.getMarketDataDepth();
log.info(md.toString());
return md;
}
catch ( Exception e) {
....
}
}
Where cs is just an interface that retrieves the JSON data from a site.
The MarketDataLevel2 object is:
public class MarketDataListLevel2 {
public static class MarketDataList {
public MarketData[] a;
}
public MarketDataList[] listofmarketdatalists;
public MarketDataListLevel2(#JsonProperty("Top10BidAsks") MarketDataList[] listofmarketdatalists) {
this.listofmarketdatalists = listofmarketdatalists;
}
I tried to make this object match the output I want (formatting wise), but apparently I might have a data structure error here, because I'm not getting the data I want returned.
When I run the first method that I listed:
MarketDataListLevel2 a = getDepthMarketData(coin);
When I debug this 'a' object, I see that each element in the listofmarketdatalists array is 'null'
instead of containing an object with this format: {"Bid":{"Price":10.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0},
"Ask":{"Price":12.0,"Size":2.0,"ExchangeID":"SMART","timeStamp":0}}.
Any advice would be awesome.
You have to create correct POJO classes which represent your JSON. See below example:
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonProgram {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Root root = mapper.readValue(json, Root.class);
System.out.println(root.getTop10());
}
}
class Root {
#JsonProperty("Top10BidAsks")
private List<MarketDataEntity> top10;
public List<MarketDataEntity> getTop10() {
return top10;
}
public void setTop10(List<MarketDataEntity> top10) {
this.top10 = top10;
}
}
class MarketDataEntity {
private Map<String, MarketData> datas = new HashMap<String, MarketData>();
#JsonAnySetter
public void setMarketData(String key, MarketData data) {
datas.put(key, data);
}
#Override
public String toString() {
return datas.toString();
}
}
class MarketData {
#JsonProperty("Price")
private BigDecimal price;
#JsonProperty("Size")
private BigDecimal size;
#JsonProperty("ExchangeID")
private String exchangeId;
private int timeStamp;
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getSize() {
return size;
}
public void setSize(BigDecimal size) {
this.size = size;
}
public String getExchangeId() {
return exchangeId;
}
public void setExchangeId(String exchangeId) {
this.exchangeId = exchangeId;
}
public int getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(int timeStamp) {
this.timeStamp = timeStamp;
}
#Override
public String toString() {
return "MarketData [price=" + price + ", size=" + size + ", exchangeId=" + exchangeId + ", timeStamp=" + timeStamp + "]";
}
}
Above program prints:
[{Bid=MarketData [price=10.0, size=2.0, exchangeId=SMART, timeStamp=0], Ask=MarketData [price=12.0, size=2.0, exchangeId=SMART, timeStamp=0]}, {Bid=MarketData [price=0.0, size=0.0, exchangeId=SMART, timeStamp=0], Ask=MarketData [price=13.0, size=12.0, exchangeId=SMART, timeStamp=0]}]