/* Copyright (c) 2008-2010, developers of the Ascension Log Visualizer * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE 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 SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ package com.googlecode.logVisualizer.logData; import com.googlecode.logVisualizer.parser.UsefulPatterns; /** * A simple immutable container class for stat gains from adventures, * consumables and so on. */ public final class Statgain { public final int mus; public final int myst; public final int mox; /** * Construct the stat gain object with a value of 0 for all three stats. */ public Statgain() { this(0, 0, 0); } /** * @param mus * The muscle stat gain to set. * @param myst * The mysticality stat gain to set. * @param mox * The moxie stat gain to set. */ public Statgain(final int mus, final int myst, final int mox) { this.mus = mus; this.myst = myst; this.mox = mox; } /** * @param mus * The muscle stats to set. * @return The new Statgain. */ public Statgain setMuscle(final int mus) { return new Statgain(mus, this.myst, this.mox); } /** * @param myst * The myst stats to set. * @return The new Statgain. */ public Statgain setMyst(final int myst) { return new Statgain(this.mus, myst, this.mox); } /** * @param mox * The moxie stats to set. * @return The new Statgain. */ public Statgain setMoxie(final int mox) { return new Statgain(this.mus, this.myst, mox); } /** * @return True if all stats are zero, otherwise false. */ public boolean isAllStatsZero() { return (this.mus == 0) && (this.myst == 0) && (this.mox == 0); } /** * @return The total stat gain. */ public int getTotalStatgain() { return this.mus + this.myst + this.mox; } /** * @param stats * Adds all stat gains of that Statgain object to this instance. * @return The new Statgain. * @throws NullPointerException * if stats is {@code null} */ public Statgain addStats(final Statgain stats) { return this.addStats(stats.mus, stats.myst, stats.mox); } /** * @param mus * The muscle stat gain to add. * @param myst * The mysticality stat gain to add. * @param mox * The moxie stat gain to add. * @return The new Statgain. */ public Statgain addStats(final int mus, final int myst, final int mox) { return new Statgain(this.mus + mus, this.myst + myst, this.mox + mox); } @Override public String toString() { final StringBuilder str = new StringBuilder(20); str.append(UsefulPatterns.SQUARE_BRACKET_OPEN); str.append(this.mus); str.append(UsefulPatterns.COMMA); str.append(this.myst); str.append(UsefulPatterns.COMMA); str.append(this.mox); str.append(UsefulPatterns.SQUARE_BRACKET_CLOSE); return str.toString(); } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (o != null) { if (o instanceof Statgain) { return (((Statgain) o).mus == this.mus) && (((Statgain) o).myst == this.myst) && (((Statgain) o).mox == this.mox); } } return false; } @Override public int hashCode() { int result = 25; result = (31 * result) + this.mus; result = (31 * result) + this.myst; result = (31 * result) + this.mox; return result; } }