Beispiel #1
0
    /**
     * A REMOVE command is supposed to have the following form:
     *
     * <p>REMOVE EVENT_TYPE X Y
     *
     * <p>where X and Y are double
     */
    @Override
    public void handle(SocketChannel sc, Scanner scanner) throws IOException {
      if (!scanner.hasNext()) throw new IOException("REMOVE : Invalid command");
      EventType event;
      double x, y;
      try {
        event = EventType.valueOf(scanner.next());
      } catch (IllegalArgumentException e) {
        throw new IOException("Invalid event type");
      }
      String tmp = scanner.next();
      try {
        x = Double.parseDouble(tmp);
      } catch (NumberFormatException e) {
        throw new IOException("Missing X coordinate");
      }
      tmp = scanner.nextLine();
      while (tmp.startsWith(" ")) {
        tmp = tmp.substring(1);
      }
      try {
        y = Double.parseDouble(tmp);
      } catch (NumberFormatException e) {
        throw new IOException("Missing Y coordinate");
      }

      BipbipClient.events.remove(new Event(event, x, y));
    }
Beispiel #2
0
    /**
     * A INFO command is supposed to have the following form:
     *
     * <p>INFO EVENT_TYPE X Y
     *
     * <p>where X and Y are double
     */
    @Override
    public void handle(SocketChannel sc, Scanner scanner) throws IOException {
      if (!scanner.hasNext()) throw new IOException("INFO : Invalid command");
      EventType event;
      double x, y;
      try {
        event = EventType.valueOf(scanner.next());
      } catch (IllegalArgumentException e) {
        throw new IOException("Invalid event type");
      }
      String tmp = scanner.next();
      try {
        x = Double.parseDouble(tmp);
      } catch (NumberFormatException e) {
        throw new IOException("Missing X coordinate");
      }
      tmp = scanner.nextLine();
      while (tmp.startsWith(" ")) {
        tmp = tmp.substring(1);
      }
      try {
        y = Double.parseDouble(tmp);
      } catch (NumberFormatException e) {
        throw new IOException("Missing Y coordinate");
      }

      // Verify if it is not a doubl
      // TODO can be ameliorate with clustering
      Event evt = new Event(event, x, y);
      for (Event e : BipbipClient.events.getEvents()) {
        if (e.equals(evt)) {
          return;
        }
      }
      BipbipClient.events.addEvent(new Event(event, x, y));
    }