001package 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. 002 003import static votorola.a.count.CountNode.DART_SECTOR_MAX; 004 005 006/** A simple implementation of a lightable difference. 007 */ 008public final class LightableDifference1 implements LightableDifference 009{ 010 011 012 /** Constructs a LightableDifference1. 013 * 014 * @param rel the {@linkplain LightableDifference style symbol} for the cast 015 * relation of the other author in regard to the anchor, e.g. {@linkplain 016 * #REL_VOTER REL_VOTER}. 017 * @param sec the dart sector, which is used for {@linkplain #REL_VOTER 018 * REL_VOTER} and {@linkplain #REL_CO REL_CO} relations. It may be -2, which 019 * yields a {@linkplain #bodySecClass() bodySecClass} of null. For all other 020 * other cast relations it <em>must</em> be negative. 021 * @see #selectand() 022 * @see #personName() 023 * @see #pollName() 024 * 025 * @throws IllegalArgumentException if 'sec' is out of range. 026 */ 027 public LightableDifference1( final char rel, final int sec, final String selectand, 028 String _personName, String _pollName ) 029 { 030 personName = _personName; 031 pollName = _pollName; 032 actorLinkVariant = actorLinkVariantFor( rel, selectand ); 033 bodyOrdClass = "b".equals(selectand)? "voLiDi-ord-a": "voLiDi-ord-b"; 034 bodyRelClass = BODY_REL_PREFIX + rel; 035 if( rel == REL_VOTER || rel == REL_CO ) 036 { 037 if( sec == -2 ) 038 { 039 bodySecClass = null; 040 stageRelClass = Character.toString( rel ); 041 } 042 else 043 { 044 if( sec < 0 || sec > DART_SECTOR_MAX ) throw new IllegalArgumentException( "sec" ); 045 046 bodySecClass = BODY_SEC_PREFIX + Integer.toString(sec); 047 stageRelClass = rel + Integer.toString(sec); 048 } 049 } 050 else 051 { 052 if( sec >= 0 ) throw new IllegalArgumentException( "sec >= 0, but rel not voter or co" ); 053 054 bodySecClass = null; 055 stageRelClass = Character.toString( rel ); 056 } 057 this.selectand = selectand; 058 } 059 060 061 062 // ------------------------------------------------------------------------------------ 063 064 065 /** Returns the actor link variant for the specified cast-relational style symbol and 066 * {@linkplain votorola.a.diff.DiffLook#selectand() selectand}. 067 * 068 * @param rel the cast-relational style symbol, such as {@linkplain #REL_VOTER 069 * REL_VOTER}. 070 * @see #selectand() 071 */ 072 public static String actorLinkVariantFor( final char rel, final String selectand ) 073 { 074 final String ext; 075 if( rel == REL_VOTER ) ext = "-voter"; 076 else if( rel == REL_CO || rel == REL_TIGHT_CYCLE ) 077 { 078 ext = "b".equals(selectand)? "-peer-a": "-peer-b"; 079 } 080 else if( rel == REL_CANDIDATE ) ext = "-candidate"; 081 else 082 { 083 assert rel == REL_UNKNOWN; 084 ext = "b".equals(selectand)? "-unknown-a": "-unknown-b"; 085 } 086 return ACTOR_LINK_VARIANT_BASE + ext; 087 } 088 089 090 091 /** The <a href='../../../../a/diff/DiffKey.html#ord'>ordinal</a> "a" or "b" of the 092 * anchoring revision. This is identical to the {@linkplain votorola.s.wic.diff.WP_D 093 * difference bridge} selectand parameter 's'. 094 * 095 * @see votorola.a.diff.DiffLook#selectand() 096 */ 097 public String selectand() { return selectand; } 098 099 100 private final String selectand; 101 102 103 104 // - L i g h t a b l e - D i f f e r e n c e ------------------------------------------ 105 106 107 public String actorLinkVariant() { return actorLinkVariant; } 108 109 110 private final String actorLinkVariant; 111 112 113 114 public String bodyOrdClass() { return bodyOrdClass; } 115 116 117 private final String bodyOrdClass; 118 119 120 121 public String bodyRelClass() { return bodyRelClass; } 122 123 124 private final String bodyRelClass; 125 126 127 128 public String bodySecClass() { return bodySecClass; } 129 130 131 private final String bodySecClass; 132 133 134 135 public String personName() { return personName; } 136 137 138 private final String personName; 139 140 141 142 public String pollName() { return pollName; } 143 144 145 private final String pollName; 146 147 148 149 public String stageRelClass() { return stageRelClass; } 150 151 152 private final String stageRelClass; 153 154 155} 156 157