コード例 #1
0
  /**
   * Generate information string on the local computer configuration (includes {@link #computer},
   * {@link #repositories}, {@link #combination}).
   *
   * @return whether new changes have occurred due to the update.
   * @author Julius Huelsmann
   * @version %I%, %U%
   * @since 1.0
   */
  public boolean convertInformationString(final String xstring, final String xadr) {

    // go through all the identifiers and generate Vector of Computers,
    // Repositories and Link-Combinations
    boolean changesOccurred = false;

    //
    // Fetch information from string
    final int occurr1 = xstring.indexOf(Utils.invalidCharLevel1);
    final String remoteUid = xstring.substring(0, occurr1);
    final String rest00 = xstring.substring(occurr1 + 1, xstring.length());
    final String port = rest00.substring(0, rest00.indexOf(Utils.invalidCharLevel1));
    final int iport = Integer.parseInt(port);

    boolean found = false;
    for (int i = 0; i < computer.size(); i++) {
      if (computer.get(i).getUid().equals(remoteUid)) {
        found = true;

        if (computer.get(i).getPort() != iport
            || computer.get(i).getAddress().equals(xadr)
            || computer.get(i).isConnected() == false) {
          changesOccurred = true;
        }
        computer.get(i).setPort(iport);
        computer.get(i).setAddress(xadr);
        computer.get(i).setConnected(true);
        computer.get(i).setContacted();
      }
    }

    // if the computer has not been found inside the list of computers, add
    // it.
    if (!found) {
      ComputerRemote cr = new ComputerRemote(remoteUid, xadr, iport);
      cr.setConnected(true);
      addComputer(cr);
      changesOccurred = true;
      cr.setContacted();
    }

    // TODO: Check whether the computer with the UID has already been added
    // to the list of computers.
    String remainingString =
        xstring.substring(remoteUid.length() + port.length() + 2, xstring.length());

    String strgComputer =
        remainingString.substring(0, remainingString.indexOf(Utils.invalidCharLevel1));
    remainingString =
        remainingString.substring(strgComputer.length() + 1, remainingString.length());
    String strgRepositories =
        remainingString.substring(0, remainingString.indexOf(Utils.invalidCharLevel1));
    remainingString =
        remainingString.substring(strgRepositories.length() + 1, remainingString.length());
    String strgCombination = remainingString;

    //
    // ComputerRemote
    for (int i = strgComputer.indexOf(Utils.invalidCharLevel2);
        i != -1;
        i = strgComputer.indexOf(Utils.invalidCharLevel2)) {
      final String strgComputerSingle = strgComputer.substring(0, i);
      strgComputer = strgComputer.substring(i + 1, strgComputer.length());

      ComputerRemote comp = ComputerRemote.convertInformationString(strgComputerSingle);
      changesOccurred = addComputer(comp) || changesOccurred;
    }

    //
    // Repository
    for (int i = strgRepositories.indexOf(Utils.invalidCharLevel2);
        i != -1;
        i = strgRepositories.indexOf(Utils.invalidCharLevel2)) {
      final String strgSingle = strgRepositories.substring(0, i);
      strgRepositories = strgRepositories.substring(i + 1, strgRepositories.length());

      Repository repo = Repository.convertInformationString(strgSingle);

      changesOccurred = addRepository(repo) || changesOccurred;
    }

    //
    // Links
    // Important: the Links can ony be added to the vector of
    for (int i = strgCombination.indexOf(Utils.invalidCharLevel2);
        i != -1;
        i = strgCombination.indexOf(Utils.invalidCharLevel2)) {
      final String strgSingle = strgCombination.substring(0, i);
      strgCombination = strgCombination.substring(i + 1, strgCombination.length());

      Link clink = Link.convertInformationString(strgSingle, repositories, computer);
      changesOccurred = addLink(clink) || changesOccurred;
    }

    View.print("Something changed: " + changesOccurred);
    if (changesOccurred) {
      changed();
    }

    // Return whether the above-created computers, combinations and
    // repositories have been already added to list.
    return changesOccurred;
  }