/**
   * Save a pattern of size 1 to the output file
   *
   * @param item the item
   * @param bitmap its bitmap
   * @throws IOException exception if error while writing to the file
   */
  private void savePattern(Integer item, Bitmap bitmap) throws IOException {
    // First, we check if the pattern contains the desired items (optional)
    // We only do that if the user has specified some items that must appear in
    // patterns.
    if (mustAppearItems != null) {

      // if the pattern does not contains all required items, then return
      if (mustAppearItems.length > 1) {
        return;
      }
      if (item.equals(mustAppearItems[0]) == false) {
        return;
      }
    }

    patternCount++; // increase the pattern count
    StringBuilder r = new StringBuilder("");
    r.append(item);
    r.append(" -1 ");
    r.append("#SUP: ");
    r.append(bitmap.getSupport());
    // if the user wants the sequence IDs, we will show them
    if (outputSequenceIdentifiers) {
      r.append(" #SID: ");
      r.append(bitmap.getSIDs(sequencesSize));
    }
    writer.write(r.toString());
    writer.newLine();
  }
  /**
   * Save a pattern of size > 1 to the output file.
   *
   * @param prefix the prefix
   * @param bitmap its bitmap
   * @throws IOException exception if error while writing to the file
   */
  private void savePattern(Prefix prefix, Bitmap bitmap) throws IOException {
    // First, we check if the pattern contains the desired items (optional)
    // We only do that if the user has specified some items that must appear in
    // patterns.
    if (mustAppearItems != null) {
      Set<Integer> itemsFound = new HashSet<Integer>();
      // for each item in the pattern
      loop:
      for (Itemset itemset : prefix.getItemsets()) {
        for (Integer item : itemset.getItems()) {
          // if the user required that this item must appear in all patterns
          if (itemMustAppearInPatterns(item)) {
            // we note it
            itemsFound.add(item);
            if (itemsFound.size() == mustAppearItems.length) {
              break loop;
            }
          }
        }
      }
      // if the pattern does not contains all required items, then return
      if (itemsFound.size() != mustAppearItems.length) {
        return;
      }
    }
    patternCount++;

    StringBuilder r = new StringBuilder("");
    for (Itemset itemset : prefix.getItemsets()) {
      //			r.append('(');
      for (Integer item : itemset.getItems()) {
        String string = item.toString();
        r.append(string);
        r.append(' ');
      }
      r.append("-1 ");
    }

    r.append("#SUP: ");
    r.append(bitmap.getSupport());
    // if the user wants the sequence IDs, we will show them
    if (outputSequenceIdentifiers) {
      r.append(" #SID: ");
      r.append(bitmap.getSIDs(sequencesSize));
    }
    writer.write(r.toString());
    //		System.out.println(r.toString());
    writer.newLine();
  }