001package votorola.a.count; // Copyright 2011-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 votorola.g.lang.*; 004 005 006/** A collection of votes on a prospective issue. 007 * 008 * @see <a href='http://reluk.ca/w/Category:Poll' target='_top'>Category:Poll</a> 009 */ 010public interface Poll 011{ 012 013 014 /** A name that is guaranteed not to designate an actual poll, though it is otherwise 015 * valid as a poll name. 016 * 017 * @see #name() 018 * @see <a href='http://reluk.ca/w/Sys/not-a-poll' target='_top' 019 * >zelea.com/w/Sys/not-a-poll</a> 020 */ 021 public static final String NOT_A_POLL = "Sys/not-a-poll"; 022 023 024 025 /** The name of the local test poll, which is {@value}. It serves as a default in 026 * some contexts. 027 * 028 * @see <a href='http://reluk.ca/w/Sys/p/sandbox' target='_top' 029 * >zelea.com/w/Sys/p/sandbox</a> 030 */ 031 public static final String TEST_POLL_NAME = "Sys/p/sandbox"; 032 033 034 035 // - P o l l -------------------------------------------------------------------------- 036 037 038 /** An informal, descriptive title for the poll in wiki-style title case, or null if 039 * there is none. 040 * 041 * @see <a href='http://reluk.ca/w/Property:Display_title' target='_top' 042 * >zelea.com/w/Property:Display_title</a> 043 */ 044 public String displayTitle(); 045 046 047 048 /** The issue type of the poll, specified by the short name of its page in the 049 * pollwiki, i.e. without the namespace. 050 * 051 * @see <a href='http://reluk.ca/w/Property:Issue_type' target='_top' 052 * >zelea.com/w/Property:Issue_type</a> 053 */ 054 public String issueType(); 055 056 057 058 /** The name of the poll. 059 * 060 * @see PollService#POLL_NAME_PATTERN 061 * @see votorola.a.VoterService#NAME_MAX_LENGTH 062 */ 063 public String name(); 064 065 066 067 // ==================================================================================== 068 069 070 /** Poll utilities. 071 */ 072 public @ThreadSafe static final class U 073 { 074 075 private U() {} 076 077 078 /** Translates a query parameter value to a poll name. 079 * 080 * @return poll name, or null if value is null. 081 * 082 * @see <a href='http://reluk.ca/w/Template:PN2HTP' target='_top' 083 * >Template:PN2HTP</a> 084 * @see #toQuery(String) 085 */ 086 public static String toName( final String value ) 087 { 088 return value == null? null: value.replace( '!', '/' ); 089 } 090 091 092 /** Translates a poll name to an HTTP query parameter value by inserting 093 * exclamation marks (!) in place of slash characters (/), which are technically 094 * not allowed in query parameters. 095 * 096 * @see <a href='http://reluk.ca/w/Template:PN2HTP' target='_top' 097 * >Template:PN2HTP</a> 098 * @see #toName(String) 099 */ 100 public static String toQuery( final String pollName ) 101 { 102 return pollName.replace( '/', '!' ); 103 } 104 105 } 106 107}