net.sourceforge.worldsaver.names
Class Names

java.lang.Object
  |
  +--net.sourceforge.worldsaver.names.Names
All Implemented Interfaces:
MiscUtils

public class Names
extends java.lang.Object
implements MiscUtils

This is Names, the class doing all the work in this package. With some configuration this class can be used to generate pronouncable words (currently just with the english alphabet). If you want to use this class, you should carefully read the methods to make sure you know what you are doing.

This class can also be called directly by java as a commandline tool.

Version:
1.0.1 Mar 15 2001
Author:
Andreas Schmitz

Field Summary
protected  Localizer lang
           
static java.lang.String VERSION
          Version information.
 
Fields inherited from interface net.sourceforge.worldsaver.util.MiscUtils
CONSOLE_WIDTH, NEWLINE, RANDOM
 
Constructor Summary
Names()
          The constructor initializes a properties object with some standard values.
 
Method Summary
 void cleanFilters()
          This methods cleans out unnecessary entries in the filters.
 void createConfigvalues()
          This method creates new configvalues by analyzing the inputfile.
 void createFiltervalues()
           This is the method which creates the filters magically.
 java.lang.String getConfigfile()
          Returns the name of the configfile
 java.lang.String getFilterfile()
          Returns the name of the filterfile
 java.lang.String getInputfile()
          Returns the name of the inputfile
 int[] getLengthOfMagic()
          Returns the length of names generated by createFiltervalues().
 java.lang.String getLengthOfMagicString()
          Returns the length of names generated by createFiltervalues().
 int getLengthOfNames()
          Returns the length of generated names
 int getLengthOfTask()
          Returns the length of the current task.
 java.lang.String getMessage()
          Returns a message on what the running thread is doing right now.
 java.lang.String getName(int length)
          Ever wanted to get a name computed without using your fantasy?
 java.lang.String getNames()
          This method returns the predefined number of names as one string (names seperated by newlines).
 int getNumberOfNames()
          Returns the number of generated names at once
 int getNumberToGenerate()
          Returns the amount of names that are generated for each setLengthOfMagic item when calling createFiltervalues()
 java.lang.String getOptionsfile()
          Returns the name of the optionsfile
 int getStatus()
          Indicates the percentile of completion of the current running thread.
 boolean getVerbose()
          Returns whether there will be output on stdout
 boolean hasConfig()
          Indicates if configuration data has been created or loaded or not.
 boolean hasInput()
          Indicates if an inputfile has already been loaded.
 boolean isReady()
          Indicates whether a thread is running in this names object or not.
 void loadOptions()
          Simply loads options from file.
static void main(java.lang.String[] args)
          Run this to run the cmdline application Names.
static void printUsage(Localizer l)
          Just prints out cmdline-usage and exits.
 void prooveConfig()
          You must run this method to make sure that the instance can be used to create names.
 void readConfigfile()
          This method reads configvalues from file and overrides the old ones.
 void readFilterfile()
          This methods appends a filterfile to the actual values.
 void readInputfile()
          This method loads a textfile into memory and splits it into words.
 void saveConfigfile()
          Saves configfile to disk.
 void saveFilterfile()
          Saves the filterfile.
 void saveOptions()
          Simply saves current options to file.
 void setConfigfile(java.lang.String v)
          Sets the name of the configfile
 void setFilterfile(java.lang.String v)
          Sets the name of the filterfile
 void setInputfile(java.lang.String v)
          Sets the name of the inputfile
 void setLengthOfMagic(int[] a)
          Sets the length and (partially) the number of names that are generated by createFiltervalues().
 void setLengthOfMagic(java.lang.String v)
          Sets the length and (partially) the number of names that are generated by createFiltervalues().
 void setLengthOfNames(int v)
          Sets the length of names to be generated
 void setNumberOfNames(int v)
          Sets the number of names to generate at once
 void setNumberToGenerate(int v)
          Sets the amount of names that are generated for each setLengthOfMagic item when calling createFiltervalues()
 void setOptionsfile(java.lang.String v)
          Sets the name of the optionsfile
 void setReady(boolean v)
          Sets that a thread runs now in this instance.
 void setVerbose(boolean v)
          Sets whether there should be output on stdout or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Version information.

lang

protected Localizer lang
Constructor Detail

Names

public Names()
      throws java.io.IOException
The constructor initializes a properties object with some standard values. Defaults are the following: Read the methods carefully to learn what the files mean.
Method Detail

setOptionsfile

public void setOptionsfile(java.lang.String v)
Sets the name of the optionsfile
Parameters:
v - The new filename

getOptionsfile

public java.lang.String getOptionsfile()
Returns the name of the optionsfile

setConfigfile

public void setConfigfile(java.lang.String v)
Sets the name of the configfile
Parameters:
v - The new filename

getConfigfile

public java.lang.String getConfigfile()
Returns the name of the configfile

setFilterfile

public void setFilterfile(java.lang.String v)
Sets the name of the filterfile
Parameters:
v - The new filename

getFilterfile

public java.lang.String getFilterfile()
Returns the name of the filterfile

setInputfile

public void setInputfile(java.lang.String v)
Sets the name of the inputfile
Parameters:
v - The new filename

getInputfile

public java.lang.String getInputfile()
Returns the name of the inputfile

setLengthOfNames

public void setLengthOfNames(int v)
Sets the length of names to be generated
Parameters:
v - The new length

getLengthOfNames

public int getLengthOfNames()
Returns the length of generated names

setNumberOfNames

public void setNumberOfNames(int v)
Sets the number of names to generate at once
Parameters:
v - The new number

getNumberOfNames

public int getNumberOfNames()
Returns the number of generated names at once

setNumberToGenerate

public void setNumberToGenerate(int v)
Sets the amount of names that are generated for each setLengthOfMagic item when calling createFiltervalues()
Parameters:
v - The new number

getNumberToGenerate

public int getNumberToGenerate()
Returns the amount of names that are generated for each setLengthOfMagic item when calling createFiltervalues()

setVerbose

public void setVerbose(boolean v)
Sets whether there should be output on stdout or not.
Parameters:
v - false means no output

getVerbose

public boolean getVerbose()
Returns whether there will be output on stdout

setLengthOfMagic

public void setLengthOfMagic(java.lang.String v)
Sets the length and (partially) the number of names that are generated by createFiltervalues(). Standard is two and three which means that getNumberOfGenerate() times a two and three character name is prooved to be valid. You should use very small values here (two and three is quite a good guess).
Parameters:
v - A comma seperated list of integers, e.g. v="2,3"

setLengthOfMagic

public void setLengthOfMagic(int[] a)
Sets the length and (partially) the number of names that are generated by createFiltervalues(). Standard is two and three which means that getNumberOfGenerate() times a two and three character name is prooved to be valid. You should use very small values here (two and three is quite a good guess).
Parameters:
v - An integer array containing the values

getLengthOfMagic

public int[] getLengthOfMagic()
Returns the length of names generated by createFiltervalues(). Note that finally there are getLengthOfMagic().length*getNumberToGenerate() names are created for every call... Returns an integer array with the value.

getLengthOfMagicString

public java.lang.String getLengthOfMagicString()
Returns the length of names generated by createFiltervalues(). Note that finally there are getLengthOfMagic().length*getNumberToGenerate() names are created for every call... Returns a String with the values (comma seperated, e.g. "2,3").

isReady

public boolean isReady()
Indicates whether a thread is running in this names object or not.

hasInput

public boolean hasInput()
Indicates if an inputfile has already been loaded.

hasConfig

public boolean hasConfig()
Indicates if configuration data has been created or loaded or not.

getStatus

public int getStatus()
Indicates the percentile of completion of the current running thread.
Returns:
the status

setReady

public void setReady(boolean v)
Sets that a thread runs now in this instance.

getMessage

public java.lang.String getMessage()
Returns a message on what the running thread is doing right now.
Returns:
the message

getLengthOfTask

public int getLengthOfTask()
Returns the length of the current task.
Returns:
the length

loadOptions

public void loadOptions()
                 throws java.io.IOException
Simply loads options from file.

saveOptions

public void saveOptions()
                 throws java.io.IOException
Simply saves current options to file.

prooveConfig

public void prooveConfig()
                  throws WrongConfigvaluesException
You must run this method to make sure that the instance can be used to create names. Note that there may be work to be done to create really names; but this method makes sure that this will be possible somewhen. If anything isn't cool, it throws a WrongConfigvaluesException. Note that it won't be possible to make the most things work without calling this method before.

saveConfigfile

public void saveConfigfile()
                    throws java.io.IOException
Saves configfile to disk.
Throws:
java.io.IOException - if the file could not be read

createConfigvalues

public void createConfigvalues()
This method creates new configvalues by analyzing the inputfile. The inputfile is a normal textfile, and the configvalues store the information of one character following another in this inputfile. It is possible to accumulate several inputfiles by loading them and afterwards calling this method.

readConfigfile

public void readConfigfile()
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
This method reads configvalues from file and overrides the old ones.

readInputfile

public void readInputfile()
                   throws java.io.IOException
This method loads a textfile into memory and splits it into words. This method can take some time on slow computers, but not too much.

createFiltervalues

public void createFiltervalues()

This is the method which creates the filters magically. It generates (by default) 10000 two character names and 10000 three character names. Each of them is prooved to occur in the inputfile's words at the beginning, in the middle and in the ends. If the `name' is not found, we have a new filter.

You can run this method as often as you want to, but beware: it costs a LOT of time.

NOTE: This method can hang, if the inputfile is too small/bad or the filterfile contains too much filters. (It's not really this method that hangs then, but the getName[s]() method; although this situation only occurs when adding new filters.)


readFilterfile

public void readFilterfile()
                    throws java.io.IOException
This methods appends a filterfile to the actual values.

saveFilterfile

public void saveFilterfile()
                    throws java.io.IOException
Saves the filterfile.

cleanFilters

public void cleanFilters()
This methods cleans out unnecessary entries in the filters.

getName

public java.lang.String getName(int length)
Ever wanted to get a name computed without using your fantasy? You won't dare...

getNames

public java.lang.String getNames()
This method returns the predefined number of names as one string (names seperated by newlines).

printUsage

public static void printUsage(Localizer l)
Just prints out cmdline-usage and exits.

main

public static void main(java.lang.String[] args)
Run this to run the cmdline application Names.