/** * Speculative method to see if it can determine a trend. The larger the number the stronger the * trend. * * @return current - interger. A positive number is an increasing trend. A negative number is a * decreasing trend. */ public int getTrend() { int retVal = 0; // based on current ping values. if (currPing < 0.0) { retVal--; } else { if (currPing < shortTerm.getAverage()) { retVal++; } else { retVal--; } if (currPing < medTerm.getAverage()) { retVal++; } else { retVal--; } if (currPing < longTerm.getAverage()) { retVal++; } else { retVal--; } } // compare shortTerm and medium term averages. if (shortTerm.getAverage() < medTerm.getAverage()) { retVal++; } else { retVal--; } // compare short-term with long term. if (shortTerm.getAverage() < longTerm.getAverage()) { retVal++; } else { retVal--; } // compare medium-term with long-term. if (medTerm.getAverage() < longTerm.getAverage()) { retVal++; } else { retVal--; } // modify results based on absolute ping values. final int ABSOLUTE_GOOD_PING_VALUE = 30; if (currPing < ABSOLUTE_GOOD_PING_VALUE) { retVal++; } if (shortTerm.getAverage() < ABSOLUTE_GOOD_PING_VALUE) { retVal++; } if (medTerm.getAverage() < ABSOLUTE_GOOD_PING_VALUE) { retVal++; } if (longTerm.getAverage() < ABSOLUTE_GOOD_PING_VALUE) { retVal++; } // modify results based on absolute ping values that are too long. final int ABSOLUTE_BAD_PING_VALUE = 300; if (currPing > ABSOLUTE_BAD_PING_VALUE) { retVal--; } if (shortTerm.getAverage() > ABSOLUTE_BAD_PING_VALUE) { retVal--; } if (medTerm.getAverage() > ABSOLUTE_BAD_PING_VALUE) { retVal--; } if (longTerm.getAverage() > ABSOLUTE_BAD_PING_VALUE) { retVal--; } return retVal; } // getTrend
public void addPingTime(int ping) { currPing = (double) ping; shortTerm.update((double) ping); medTerm.update((double) ping); longTerm.update((double) ping); }