public void add(final T line) {
   if (standards.containsKey(line.getID())) {
     throw new TribbleException(
         "Attempting to add multiple standard header lines for ID " + line.getID());
   }
   standards.put(line.getID(), line);
 }
    public T repair(final T line) {
      final T standard = get(line.getID(), false);
      if (standard != null) {
        final boolean badCountType = line.getCountType() != standard.getCountType();
        final boolean badCount =
            line.isFixedCount() && !badCountType && line.getCount() != standard.getCount();
        final boolean badType = line.getType() != standard.getType();
        final boolean badDesc = !line.getDescription().equals(standard.getDescription());
        final boolean needsRepair =
            badCountType || badCount || badType || (REPAIR_BAD_DESCRIPTIONS && badDesc);

        if (needsRepair) {
          if (GeneralUtils.DEBUG_MODE_ENABLED) {
            System.err.println(
                "Repairing standard header line for field "
                    + line.getID()
                    + " because"
                    + (badCountType
                        ? " -- count types disagree; header has "
                            + line.getCountType()
                            + " but standard is "
                            + standard.getCountType()
                        : "")
                    + (badType
                        ? " -- type disagree; header has "
                            + line.getType()
                            + " but standard is "
                            + standard.getType()
                        : "")
                    + (badCount
                        ? " -- counts disagree; header has "
                            + line.getCount()
                            + " but standard is "
                            + standard.getCount()
                        : "")
                    + (badDesc
                        ? " -- descriptions disagree; header has '"
                            + line.getDescription()
                            + "' but standard is '"
                            + standard.getDescription()
                            + "'"
                        : ""));
          }
          return standard;
        } else {
          return line;
        }
      } else {
        return line;
      }
    }
Example #3
0
    public String getID() {
      if (last == null) {
        return null;
      }

      return last.getID();
    }
Example #4
0
 protected void notifyMediaListeners(T media, Change change) {
   if (!canRaiseEvents) {
     return;
   }
   for (ListChangeHandler<T> lch : listeners) {
     lch.listChanged(this, change, media.getID(), media);
   }
 }
Example #5
0
  /**
   * Checks for equality.
   *
   * @param o the object to check equality against.
   * @return <code>true</code> if the object is of the right class and has the same identifier.
   */
  @Override
  public final boolean equals(final Object o) {

    if (this == o) {
      return true;
    }

    if (!checkClass(o)) {
      return false;
    }

    T that = (T) o;

    return that.hashCode() == hashCode && id.equals(that.getID());
  }
 protected void dumpMap() {
   try {
     tmpFileIndex++;
     String outfile = tmpDIR + "/" + tmpFileIndex + ".tmp";
     logger.info("dumping memory to file: " + outfile);
     PrintStream tmpContentFile = new PrintStream(outfile);
     TIntObjectIterator<T> it = id2item.iterator();
     while (it.hasNext()) {
       it.advance();
       T item = it.value();
       tmpContentFile.print(item.getID());
       tmpContentFile.print("\t");
       tmpContentFile.print(Serialization.serialize(item));
       tmpContentFile.print("\n");
       it.remove();
     }
     tmpContentFile.close();
   } catch (Exception e) {
     logger.error(e.toString());
   }
 }
Example #7
0
  /**
   * Adds a new profile to this typing data, if there is not already an equal one. The new profile
   * should have values for all the features considered in this typing data. Otherwise, it will not
   * be added.
   *
   * @param profile the new profile to be added.
   * @return the inserted profile.
   * @throws Exception on unsuccess.
   */
  public T addData(T profile) throws Exception {

    // Do we have values for all fields?
    if (profile.profileLength() != headers.length - 1) {
      throw new Exception(
          "Incompatible length: "
              + profile.getID()
              + " has length"
              + profile.profileLength()
              + "(!="
              + (headers.length - 1)
              + ")");
    }

    if (unique.contains(profile)) {
      throw new Exception(
          "Duplicated profile: " + profile.getID() + " aka " + this.getEqual(profile).getID());
    }

    if (idset.contains(profile.getID())) {
      throw new Exception("Duplicated profile ID: " + profile.getID());
    }

    domains[0].add(profile.getID());
    for (int i = 0; i < profile.profileLength(); i++) {
      domains[i + 1].add(profile.getValue(i));
    }

    collection.add(profile);
    unique.add(profile);
    idset.add(profile.getID());

    weightOk = false;

    return profile;
  }
Example #8
0
 public void addMedia(T media) {
   mediaCache.put(media.getID(), media);
   notifyMediaListeners(media, Change.ADDED);
 }
Example #9
0
 /**
  * Compares two identifiers lexicographically.
  *
  * @param t the identifiable to compare to.
  * @return the value <code>0</code> if the argument identifier is equal to this identifier; a
  *     value less than <code>0</code> if this identifier is lexicographically less than the
  *     identifier argument; and a value greater than <code>0</code> if this identifier is
  *     lexicographically greater than the identifier argument.
  */
 public final int compareTo(final T t) {
   return getID().compareTo(t.getID());
 }
 public int compare(T a, T b) {
   return CUtil.getStringCompare().compare(a.getID() + "", b.getID() + "");
 }
 public void setSelecte(T unit) {
   list.setSelectedValue(unit, true);
   if (unit != null) {
     text_unit_name.setText(unit.getID() + "");
   }
 }