package jalview.datamodel; /** * Data bean that holds a mapping from one sequence to another */ public class SequenceMapping { SequenceI fromSeq; Mapping mapping; private MappingType type; SequenceMapping(SequenceI from, Mapping map) { this.fromSeq = from; this.mapping = map; } /** * Readable representation for debugging only, not guaranteed not to change */ @Override public String toString() { return String.format("From %s %s", fromSeq.getName(), mapping.toString()); } /** * Returns a hashCode derived from the hashcodes of the mappings and fromSeq * * @see SequenceMapping#hashCode() */ @Override public int hashCode() { return (fromSeq == null ? 0 : fromSeq.hashCode() * 31) + mapping.hashCode(); } /** * Answers true if the objects hold the same mapping between the same two * sequences * * @see Mapping#equals */ @Override public boolean equals(Object obj) { if (!(obj instanceof SequenceMapping)) { return false; } SequenceMapping that = (SequenceMapping) obj; if (this.mapping == null) { return that.mapping == null; } // TODO: can simplify by asserting fromSeq is a dataset sequence return (this.fromSeq == that.fromSeq || (this.fromSeq != null && that.fromSeq != null && this.fromSeq.getDatasetSequence() != null && this.fromSeq.getDatasetSequence() == that.fromSeq .getDatasetSequence())) && this.mapping.equals(that.mapping); } public SequenceI getFromSeq() { return fromSeq; } public Mapping getMapping() { return mapping; } public MappingType getType() { return type; } }