package votorola.a.count.gwt; // Copyright 2011, 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 java.util.*;
import votorola.g.web.gwt.*;
/** A resource superaccount implemented as a JavaScript overlay type.
*
* @see Category:Account#Superaccounts
*/
public class SacJS extends JavaScriptObjectX
{
protected SacJS() {} // "precisely one constructor... protected, empty, and no-argument"
/** Initializes a superaccount that was received on the wire.
*
* @throws CountingMethodJS.NoSuchMethod if the counting method is unrecognized.
*/
final void init( final String countingMethodName, final String accountName )
throws CountingMethodJS.NoSuchMethod
{
if( countingMethodName == null || accountName == null ) throw new NullPointerException();
if( countingMethodName() != null && accountName() != null )
{
throw new IllegalStateException();
}
_set( "countingMethodName", countingMethodName );
_set( "countingMethodMnemonic", CountingMethodJS.SwitchMnemonic.valueOfFullName(
countingMethodName ));
_set( "accountName", accountName );
}
// ------------------------------------------------------------------------------------
/** The account name for this superaccount.
*
* @see Property:Account_name
*/
public final native String accountName() /*-{ return this.accountName; }-*/;
/** Appends the value for the 'a' switch that designates this superaccount.
*
* @param sac the superaccount, or null for the null account.
* @return the same string builder.
*
* @see SacSelection#aSacSwitch()
*/
public static final StringBuilder appendSwitch( final SacJS sac, final StringBuilder b )
{
if( sac == null ) return b.append( "nulNull" );
b.append( sac.countingMethodMnemonic().name() );
final String accountName = sac.accountName();
final char c = accountName.charAt( 0 );
if( c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c == '\'' ) b.append( '\'' );
b.append( accountName );
return b;
}
/** The switch mnemonic of the counting method.
*/
public final native CountingMethodJS.SwitchMnemonic countingMethodMnemonic()
/*-{
return this.countingMethodMnemonic;
}-*/;
/** The name of the counting method.
*
* @see Category:Counting method
*/
public final native String countingMethodName() /*-{ return this.countingMethodName; }-*/;
/** A lexical comparator that sorts (1) by account name, and (2) by counting method.
*
* @see #accountName()
* @see #countingMethodName()
*/
public static final Comparator NAME_COMPARATOR = new Comparator()
{
public int compare( final SacJS s1, final SacJS s2 )
{
int signum = s1.accountName().compareTo( s2.accountName() );
if( signum == 0 ) signum = s1.countingMethodName().compareTo( s2.countingMethodName() );
assert signum != 0 || s1.equals(s2): "comparison consistent with equality";
return signum;
}
};
}