public void paintComponent(Graphics g) { super.paintComponent(g); calcSizes(); drawAxes(g); calcMaxes(); calcTickIncrements(); drawXTicks(g); drawYTicks(g); int t = 0; int prevX = 0, prevY1 = 0, prevY2 = 0; for (DataPair pair : data) { int h = pair.getH(); int p = pair.getP(); // calculate where to put the dots int x = xVal(t, maxT); int y1 = yVal(h, maxH); int y2 = yVal(p, maxP); // draw herbivore dot g.setColor(Color.BLUE); g.fillOval(x, y1, 2 * r, 2 * r); // draw a line connecting this dot to the last if (prevX != 0) { g.drawLine(prevX + r, prevY1 + r, x + r, y1 + r); } // draw predator dot g.setColor(Color.RED); g.fillOval(x, y2, 2 * r, 2 * r); // draw a line connecting this dot to the last if (prevX != 0) { g.drawLine(prevX + r, prevY2 + r, x + r, y2 + r); } // remember these dots prevX = x; prevY1 = y1; prevY2 = y2; g.setColor(Color.BLACK); t++; } }
private void calcMaxes() { maxH = -1; maxP = -1; maxT = -1; for (DataPair pair : data) { int h = pair.getH(); int p = pair.getP(); if (h > maxH) maxH = h; if (p > maxP) maxP = p; maxT++; } }
@DataPoints public static DataPair[] getExistCompatibleData() { return new DataPair[] { DataPair.pair(XS_DURATION, "P3Y6M4DT12H30M5S"), DataPair.pair(XS_BYTE, "32"), DataPair.pair(XS_NORMALIZED_STRING, VALUE), DataPair.pair(XS_TOKEN, VALUE), DataPair.pair(XS_LANGUAGE, VALUE), DataPair.pair(XS_UNTYPED_ATOMIC, VALUE), }; }
public static void main(String[] args) { // Keep Account Information DataPair<String, Double> account = null; account = new DataPair<String, Double>("SBI-100", 20.5); System.out.println("Account Information"); account.showType(); // Show the type of data used by iOb. String accNum = account.getKey(); // No type cast is required. double accBal = account.getValue(); System.out.println(accNum + " : " + accBal); // Keep Marksheet Information DataPair<String, Integer> marksheet = null; marksheet = new DataPair<String, Integer>("RN_786", 98); System.out.println("Marksheet Information"); marksheet.showType(); // Show the type of data used by iOb. String rollNo = marksheet.getKey(); int marks = marksheet.getValue(); System.out.println(rollNo + " : " + marks); }