package votorola.a.diff.harvest.cache;// Copyright 2010-2012. Christian Weilbach. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. /** * This class contains a derived Message object, which * contains all the original message data and additionally * information to the single diffKey URL it maps to in this * message. This is what is stored in the database. * This is losely connected to the Bite type of {@link votorola.s.wap.HarvestWAP}. * @see DraftPair * @see Cache * @see Message * @see HarvestTable */ import votorola.a.diff.DraftPair; import votorola.a.diff.harvest.Message; import votorola.a.diff.harvest.auth.Authenticator; import votorola.g.lang.ThreadSafe; /** * DiffMessages are created by HarvestCache from {@linkplain Message} * objects by {@linkplain HarvestCache#store(Message, Authenticator)}. * * @see HarvestCache * @see Message * */ public @ThreadSafe class DiffMessage { final private Message msg; /** * The message containing this difference. * * @return wrapped message */ public Message message() { return msg; } /** * Representing a valid {@link votorola.a.diff.DraftPair}. * * @return draft-pair */ public DraftPair draftPair() { return draftPair; } private final DraftPair draftPair; /** * Constructor to create a DiffMessage from a {@linkplain Message} and * decorate it with difference information. * * @param msg * @param draftPair * used internally to compute, but is only stored as * {@link votorola.a.diff.DiffKey} */ DiffMessage(final Message msg, final DraftPair draftPair) { this.msg = msg; this.draftPair = draftPair; } @Override public boolean equals(Object o) { if( o == this ) { return true; } return (o instanceof DiffMessage) && ((DiffMessage)o).msg.equals(msg) && ((DiffMessage)o).draftPair.equals(draftPair); } @Override public int hashCode() { int hash = msg.hashCode(); hash = msg.hashCode()*37 + draftPair.hashCode(); return hash; } /** * Returns message content and draft-pair. This is not * guaranteed to stable. */ @Override public String toString() { return msg.toString() + "|" + draftPair.toString(); } }