package votorola.s.gwt.stage.vote; // Copyright 2012, Michael Allan. 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. import static votorola.a.count.CountNode.DART_SECTOR_MAX; /** A simple implementation of a lightable difference. */ public final class LightableDifference1 implements LightableDifference { /** Constructs a LightableDifference1. * * @param rel the {@linkplain LightableDifference style symbol} for the cast * relation of the other author in regard to the anchor, e.g. {@linkplain * #REL_VOTER REL_VOTER}. * @param sec the dart sector, which is used for {@linkplain #REL_VOTER * REL_VOTER} and {@linkplain #REL_CO REL_CO} relations. It may be -2, which * yields a {@linkplain #bodySecClass() bodySecClass} of null. For all other * other cast relations it must be negative. * @see #selectand() * @see #personName() * @see #pollName() * * @throws IllegalArgumentException if 'sec' is out of range. */ public LightableDifference1( final char rel, final int sec, final String selectand, String _personName, String _pollName ) { personName = _personName; pollName = _pollName; actorLinkVariant = actorLinkVariantFor( rel, selectand ); bodyOrdClass = "b".equals(selectand)? "voLiDi-ord-a": "voLiDi-ord-b"; bodyRelClass = BODY_REL_PREFIX + rel; if( rel == REL_VOTER || rel == REL_CO ) { if( sec == -2 ) { bodySecClass = null; stageRelClass = Character.toString( rel ); } else { if( sec < 0 || sec > DART_SECTOR_MAX ) throw new IllegalArgumentException( "sec" ); bodySecClass = BODY_SEC_PREFIX + Integer.toString(sec); stageRelClass = rel + Integer.toString(sec); } } else { if( sec >= 0 ) throw new IllegalArgumentException( "sec >= 0, but rel not voter or co" ); bodySecClass = null; stageRelClass = Character.toString( rel ); } this.selectand = selectand; } // ------------------------------------------------------------------------------------ /** Returns the actor link variant for the specified cast-relational style symbol and * {@linkplain votorola.a.diff.DiffLook#selectand() selectand}. * * @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER * REL_VOTER}. * @see #selectand() */ public static String actorLinkVariantFor( final char rel, final String selectand ) { final String ext; if( rel == REL_VOTER ) ext = "-voter"; else if( rel == REL_CO || rel == REL_TIGHT_CYCLE ) { ext = "b".equals(selectand)? "-peer-a": "-peer-b"; } else if( rel == REL_CANDIDATE ) ext = "-candidate"; else { assert rel == REL_UNKNOWN; ext = "b".equals(selectand)? "-unknown-a": "-unknown-b"; } return ACTOR_LINK_VARIANT_BASE + ext; } /** The ordinal "a" or "b" of the * anchoring revision. This is identical to the {@linkplain votorola.s.wic.diff.WP_D * difference bridge} selectand parameter 's'. * * @see votorola.a.diff.DiffLook#selectand() */ public String selectand() { return selectand; } private final String selectand; // - L i g h t a b l e - D i f f e r e n c e ------------------------------------------ public String actorLinkVariant() { return actorLinkVariant; } private final String actorLinkVariant; public String bodyOrdClass() { return bodyOrdClass; } private final String bodyOrdClass; public String bodyRelClass() { return bodyRelClass; } private final String bodyRelClass; public String bodySecClass() { return bodySecClass; } private final String bodySecClass; public String personName() { return personName; } private final String personName; public String pollName() { return pollName; } private final String pollName; public String stageRelClass() { return stageRelClass; } private final String stageRelClass; }