de.enough.polish.util
Class AbbreviationsGenerator

java.lang.Object
  extended by de.enough.polish.util.AbbreviationsGenerator

public class AbbreviationsGenerator
extends Object

Creates and stores abbreviations for any String based keys.

This is useful for storing only necessary character sequences instead of full names, which saves some memory.

Copyright Enough Software 2004 - 2011

 history
        23-Jul-2004 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de

Field Summary
static char[] ABBREVIATIONS_ALPHABET_LOWERCASE
          A character array consisting of a-z.
static char[] ABBREVIATIONS_ALPHABET_UPPERCASE
          A character array consisting of A-Z
static char[] ABBREVIATIONS_ALPHANUMERICAL
          A character array consisting of numbers and A-Z and a-z.
 
Constructor Summary
AbbreviationsGenerator()
          Creates a new empty generator.
AbbreviationsGenerator(Map abbreviations)
          Creates a new generator.
AbbreviationsGenerator(Map abbreviations, char[] abbreviationCharacters)
          Creates a new generator.
 
Method Summary
 String getAbbreviation(String name, boolean create)
          Retrieves an abbreviation for the given key.
 Map getAbbreviationsMap()
          Retrieves the map containing all abbreviations.
protected  int getCharIndex(char c, String abbreviation)
          Retrieves the index of the given character in the ABBREVIATION array.
static String getLastAbbreviation(String[] abbreviationsArr)
          Finds the last abbreviation within the given String array, e.g.
 String getNextPropertyAbbreviation()
          Creates the next property abbreviation
static void main(String[] args)
           
 void setAbbreviationsMap(Map map)
          Sets the abbreviations for this generator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABBREVIATIONS_ALPHANUMERICAL

public static final char[] ABBREVIATIONS_ALPHANUMERICAL
A character array consisting of numbers and A-Z and a-z.


ABBREVIATIONS_ALPHABET_LOWERCASE

public static final char[] ABBREVIATIONS_ALPHABET_LOWERCASE
A character array consisting of a-z.


ABBREVIATIONS_ALPHABET_UPPERCASE

public static final char[] ABBREVIATIONS_ALPHABET_UPPERCASE
A character array consisting of A-Z

Constructor Detail

AbbreviationsGenerator

public AbbreviationsGenerator()
Creates a new empty generator.


AbbreviationsGenerator

public AbbreviationsGenerator(Map abbreviations)
Creates a new generator.

Parameters:
abbreviations - the known abbreviations

AbbreviationsGenerator

public AbbreviationsGenerator(Map abbreviations,
                              char[] abbreviationCharacters)
Creates a new generator.

Parameters:
abbreviations - the known abbreviations
abbreviationCharacters - characters used for creating the abbreviations
Method Detail

getAbbreviationsMap

public Map getAbbreviationsMap()
Retrieves the map containing all abbreviations.

Returns:
the map containing all abbreviations.

setAbbreviationsMap

public void setAbbreviationsMap(Map map)
Sets the abbreviations for this generator.

Parameters:
map - a HashMap containing all abbreviations for full keywords

getLastAbbreviation

public static String getLastAbbreviation(String[] abbreviationsArr)
Finds the last abbreviation within the given String array, e.g. is "ab" later than "z".

Parameters:
abbreviationsArr - an array of already used abbreviations
Returns:
the last used abbreviation

getCharIndex

protected final int getCharIndex(char c,
                                 String abbreviation)
Retrieves the index of the given character in the ABBREVIATION array.

Parameters:
c - the character
abbreviation - the abbreviation of the style
Returns:
the index in the ABBREVIATIONS array

getAbbreviation

public String getAbbreviation(String name,
                              boolean create)
Retrieves an abbreviation for the given key.

Parameters:
name - the full name of the key
create - true when a new abbreviation should be created when none is found.
Returns:
either the abbreviation when it was found or when create is true, or null when no abbreviation was found

getNextPropertyAbbreviation

public String getNextPropertyAbbreviation()
Creates the next property abbreviation

Returns:
a new property abbreviation

main

public static void main(String[] args)
                 throws FileNotFoundException,
                        IOException
Throws:
FileNotFoundException
IOException