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 Crossforum. * @see DraftPair * @see Cache * @see Message * @see HarvestTable */ import votorola.a.diff.harvest.Message; import votorola.a.diff.harvest.auth.Authenticator; import votorola.g.lang.ThreadSafe; import votorola.g.lang.Warning; /** * Authenticated difference messages contain both the difference and authorship * information gained when {@link Authenticator} matches a {@link DiffMessage}. * * @see HarvestCache * @see DiffMessage * */ @ThreadSafe public class AuthDiffMessage { final private DiffMessage dmsg; public DiffMessage diffMessage() { return dmsg; } /** * Sender of the message as verified email. * * @return author */ public String author() { return author; } private final String author; /** * Addressee of the message as email. * * @return addressee */ public String addressee() { return addressee; } /** * This is the selectand of a difference. * * @return selectand string, e.g. "a" or "b" */ public String selectand() { return selectand; } private final String addressee; private final String selectand; private AuthDiffMessage(final DiffMessage dmsg, final String author, final String addressee, final String selectand) { this.dmsg = dmsg; this.author = author; this.addressee = addressee; this.selectand = selectand; } /** * Create a DiffMessage from a {@linkplain Message} and decorate it with * difference information. * * @param dmsg * @param author * @param addressee * @param selectand */ public static AuthDiffMessage create(final DiffMessage dmsg, final String author, final String addressee, final String selectand) { return new AuthDiffMessage(dmsg, author, addressee, selectand); } @Override public boolean equals(Object o) { if (o == this) { return true; } return (o instanceof AuthDiffMessage) && ((AuthDiffMessage) o).dmsg.equals(dmsg) && ((AuthDiffMessage) o).author.equals(author) && ((AuthDiffMessage) o).addressee.equals(addressee) && ((AuthDiffMessage) o).selectand.equals(selectand); } @Override public int hashCode() { int hash = dmsg.hashCode(); hash = hash * 37 + author.hashCode(); hash = hash * 37 + addressee.hashCode(); hash = hash * 37 + selectand.hashCode(); return hash; } /** * Return {@linkplain DiffMessage} contents as well as author, addressee and * selectand. The format is not guaranteed to be stable. */ @Override public String toString() { return dmsg.toString() + "|" + author + "|" + addressee + "|" + selectand; } }