001package votorola.a.count.gwt; // Copyright 2011, 2013, 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 com.google.gwt.core.client.*; 004import votorola.g.web.gwt.*; 005 006 007/** A counting method as a map of {@linkplain SacJS superaccounts} or {@linkplain 008 * SacRegisterJS superaccount registers} that use the method, each keyed by its account 009 * name. This is a JavaScript overlay type; however we do not actually model the 010 * counting methods themselves on the client side, instead we only mirror their 011 * employment in the CountWAP response as namespacing constructs. 012 * 013 * @see <a href='http://reluk.ca/w/Category:Counting_method' 014 * target='_top'>Category:Counting method</a> 015 * @see votorola.s.wap.CountWAP 016 */ 017public final class CountingMethodJS<T extends JavaScriptObject> extends JsMap<T> 018{ 019 020 021 protected CountingMethodJS() {} // "precisely one constructor... protected, empty, and no-argument" 022 023 024 025 // ==================================================================================== 026 027 028 /** Thrown when a requested counting method does not exist. 029 */ 030 public static final class NoSuchMethod extends Exception 031 { 032 NoSuchMethod( String _message ) { super( _message ); } 033 } 034 035 036 037 // ==================================================================================== 038 039 040 /** Short names designating particular counting methods, suitable for use in a 041 * ({@linkplain SacSelection#aSacSwitch() superaccount selection switch}). The 042 * names are resticted to ASCII lowercase letters and digits, and must begin with a 043 * letter. 044 */ 045 public static enum SwitchMnemonic 046 { 047 048 049 /** Designating a <a href='http://reluk.ca/w/Wiki:Null_count' target='_top'>null 050 * count</a>. 051 */ 052 nul( "Wiki:Null count" ), 053 054 055 /** Designating a <a href='http://reluk.ca/w/Wiki:Quantitive_summation' 056 * target='_top'>quantitive summation</a> count. 057 */ 058 q( "Wiki:Quantitive summation" ), 059 060 061 /** Designating a <a href='http://reluk.ca/w/Wiki:Vote_count' target='_top'>vote 062 * count</a>. 063 */ 064 v( "Wiki:Vote count" ); 065 066 067 068 private SwitchMnemonic( String _fullName ) { fullName = _fullName; } 069 070 071 072 // -------------------------------------------------------------------------------- 073 074 075 /** Returns the full name of the counting method. 076 */ 077 public String fullName() { return fullName; } 078 079 080 private final String fullName; 081 082 083 084 /** Returns the switch mnemonic with the specified full name. 085 * 086 * @throws NoSuchMethod if no switch mnemonic has the specified full name. 087 */ 088 public static SwitchMnemonic valueOfFullName( final String fullName ) throws NoSuchMethod 089 { 090 for( SwitchMnemonic m: values() ) if( m.fullName().equals( fullName )) return m; 091 092 throw new NoSuchMethod( fullName ); 093 } 094 095 096 } 097 098 099}