bb.gui
Class FontUtil.FontRank

java.lang.Object
  extended by bb.gui.FontUtil.FontRank
All Implemented Interfaces:
Comparable<FontUtil.FontRank>
Enclosing class:
FontUtil

public static class FontUtil.FontRank
extends Object
implements Comparable<FontUtil.FontRank>

The main purpose of this class is simply to record a Font and some associated rank of that Font. The semantic meaning of that rank is determined by the user.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).


Field Summary
private  Font font
           
private  double rank
           
 
Constructor Summary
FontUtil.FontRank(Font font, double rank)
          Constructs a new FontRank instance from the supplied arguments.
FontUtil.FontRank(Font font, String s)
          Simply calls this( font, findDisplayableCharPercent(font, s) ).
 
Method Summary
 int compareTo(FontUtil.FontRank other)
          Tries to order this and other by their ranks: returns Double.compare( other.rank, this.rank ) if that result is !
 boolean equals(Object obj)
          Only returns true if obj is another FontRank instance whose font and rank fields equal this.
 Font getFont()
           
 double getRank()
           
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

font

private final Font font

rank

private final double rank
Constructor Detail

FontUtil.FontRank

public FontUtil.FontRank(Font font,
                         String s)
Simply calls this( font, findDisplayableCharPercent(font, s) ). In other words, it ranks font based on what percent of characters it can display.


FontUtil.FontRank

public FontUtil.FontRank(Font font,
                         double rank)
                  throws IllegalArgumentException
Constructs a new FontRank instance from the supplied arguments. The font arg may be any Font value except null; the rank arg may be any double value (including NaN and infinity).

Throws:
IllegalArgumentException - if font is null
Method Detail

getFont

public Font getFont()

getRank

public double getRank()

equals

public final boolean equals(Object obj)
                     throws IllegalStateException
Only returns true if obj is another FontRank instance whose font and rank fields equal this.

Overrides:
equals in class Object
Throws:
IllegalStateException - if obj is another FontRank instance whose font field equals this, but whose rank field differs; this is meant to detect subtle bugs

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(FontUtil.FontRank other)
              throws IllegalArgumentException,
                     IllegalStateException
Tries to order this and other by their ranks: returns Double.compare( other.rank, this.rank ) if that result is != 0.

Else tries to order this and other by their names: returns this.font.getName().compareTo( other.font.getName() ) if that result is != 0.

Else tries to order this and other by their sizes: returns Math2.compare( this.font.getSize(), other.font.getSize() ) if that result is != 0.

Else tries to order this and other by their styles: returns Math2.compare( this.font.getStyle() - other.font.getStyle() ) if that result is != 0.

Else returns 0 if this.equals(other) is true. This is the only circumstance in which 0 will ever be returned, thus, this ordering is consistent with equals (see Comparable for more discussion).

Else throws an IllegalStateException.

Specified by:
compareTo in interface Comparable<FontUtil.FontRank>
Throws:
IllegalArgumentException - if other is null
IllegalStateException - if run out of criteria to order this and other