Exemplo n.º 1
0
  /**
   * Computes the interpolation of the new bets.
   *
   * @param bets
   */
  public synchronized void updateBets(List<BetContainer> bets) {

    // Add bets not in the list betsPoint
    for (BetContainer betContainer : bets) {
      boolean found = false;
      for (Interpolator<BetContainer> b : betsPoint) {
        if (b.getObject().equals(betContainer)) {
          found = true;
        }
      }
      if (!found) {
        betsPoint.add(
            new Interpolator<BetContainer>(
                baseX(betContainer.getBet().getBetToken().getStable() - 1, BET_Y_POSITION) - 10,
                BET_Y_POSITION,
                betContainer));
      }
    }

    // Remove bets in the list betsPoint that are not in bets
    Iterator<Interpolator<BetContainer>> bIter = betsPoint.iterator();
    while (bIter.hasNext()) {
      Interpolator<BetContainer> b = bIter.next();
      boolean found = false;
      for (BetContainer betContainer : bets) {
        if (b.getObject().equals(betContainer)) {
          found = true;
        }
      }
      if (!found) {
        bIter.remove();
      }
    }

    // Check if there's more than one interpolator overlapped and move them
    boolean overlap = false;
    do {
      overlap = false;
      for (Interpolator<BetContainer> i1 : betsPoint) {
        for (Interpolator<BetContainer> i2 : betsPoint) {
          if (i1 != i2
              && Math.abs(i1.destination.x - i2.destination.x) < 20
              && Math.abs(i1.destination.y - i2.destination.y) < 45) {
            i1.setNewPosition(i1.destination.x, i1.destination.y + 30, 1000);
            i2.setNewPosition(i2.destination.x, i2.destination.y - 30, 1000);
            i1.start();
            i2.start();
            overlap = true;
          }
        }
      }
    } while (overlap);
  }