コード例 #1
0
  /**
   * Ensures the uniqueness of the identifier <code>uniqueId</code>. Throws various exceptions if
   * the id is not unique.
   *
   * @param uniqueId the id that might be unique
   * @param adding the station that is about to be added
   */
  private void checkStationIdentifierUniqueness(String uniqueId, CStation<?> adding) {
    if (uniqueId == null) throw new NullPointerException("uniqueId must not be null");

    if (CContentArea.getCenterIdentifier(CControl.CONTENT_AREA_STATIONS_ID).equals(uniqueId))
      throw new IllegalArgumentException(
          "The id " + uniqueId + " is reserved for special purposes");
    if (CContentArea.getEastIdentifier(CControl.CONTENT_AREA_STATIONS_ID).equals(uniqueId))
      throw new IllegalArgumentException(
          "The id " + uniqueId + " is reserved for special purposes");
    if (CContentArea.getWestIdentifier(CControl.CONTENT_AREA_STATIONS_ID).equals(uniqueId))
      throw new IllegalArgumentException(
          "The id " + uniqueId + " is reserved for special purposes");
    if (CContentArea.getSouthIdentifier(CControl.CONTENT_AREA_STATIONS_ID).equals(uniqueId))
      throw new IllegalArgumentException(
          "The id " + uniqueId + " is reserved for special purposes");
    if (CContentArea.getNorthIdentifier(CControl.CONTENT_AREA_STATIONS_ID).equals(uniqueId))
      throw new IllegalArgumentException(
          "The id " + uniqueId + " is reserved for special purposes");

    for (CStation<?> station : stations) {
      if (station.getUniqueId().equals(uniqueId)) {
        if (station == adding) {
          throw new IllegalArgumentException("The station has already been registered");
        }

        throw new IllegalArgumentException("There exists already a station with id: " + uniqueId);
      }
    }
  }
コード例 #2
0
  public void addStation(CStation<?> station) {
    if (!settingDefaultStations) {
      checkStationIdentifierUniqueness(station.getUniqueId(), station);
    }

    stations.add(station);
  }