// --- PRINT VECTOR ----------------------------------------------------------------------------
  protected String printVector(Vector vector) {
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < vector.size(); i++) {
      buf.append(vector.get(i)).append(", ");
    }

    // remove last comma
    if (buf.length() > 0) buf.deleteCharAt(buf.length() - 2);

    return buf.toString();
  }
Пример #2
0
  /**
   * Extracts default values from the input file. The values in the file can be in any order as long
   * as they are the first 3 non-empty lines.
   *
   * <p>Example if the input has the first three lines:
   *
   * <p>Title = Music Sheet Subtitle = By Ron Spacing = 4.5
   *
   * <p>It sets title to "Music Sheet", subtitle to "By Ron" and spacing to 4.5.
   *
   * @param file
   */
  public void extractProperties(File file) {
    File input = file;
    BufferedReader stream;
    try {
      String line;
      Matcher m_title, m_subtitle, m_spacing;
      StringBuffer extractable = new StringBuffer();
      stream = new BufferedReader(new FileReader(input));

      /* Read all comment lines from the input file and concatenate them */
      while ((line = stream.readLine()) != null) {
        line = line.replaceAll("\\s+$", "");
        TabString temp = new TabString(line);
        if (!line.isEmpty()) {
          if (temp.checkError() == TabString.ERROR_COMMENT) extractable.append("%" + line + "%");
          else break;
        }
      }
      /* Return if nothing was found */
      if (extractable.length() == 0) {
        stream.close();
        return;
      }

      m_title = TITLE_PATTERN.matcher(extractable.toString());
      m_subtitle = SUBTITLE_PATTERN.matcher(extractable.toString());
      m_spacing = SPACING_PATTERN.matcher(extractable.toString());

      /* Set the title to the extracted title */
      if (m_title.find()) this.setTitle(m_title.group(VALUE_POSITION));

      /* Set the subtitle to the extracted subtitle */
      if (m_subtitle.find()) this.setSubtitle(m_subtitle.group(VALUE_POSITION));

      /* Set the spacing to the extracted spacing */
      if (m_spacing.find()) this.setSpacing(Float.parseFloat(m_spacing.group(VALUE_POSITION)));

      stream.close();

    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }