public class NonsenseShipOrPub extends java.lang.Object implements NonsenseGenerator
Both ships and pubs seem to have names that follow the general pattern of
"The <adjective> <noun>", like "The Salty Dog" or "The Mourning
Glory" or "The Rapacious Tardigrade". OK, maybe not the last one. Anyway,
since NonsenseBuilder
worked out so well, and this is actually a
simpler algorithm, it seemed only right to go ahead with this now.
As with NonsenseBuilder
, this class makes use of two of the array
resources that are included with the library:
R.array#asNonsenseAdjectives
R.array#asNonsenseNouns
Applications using this class may choose to have overrides for either or both of these string resources, in order to customize the text that might be rendered in the randomized names.
NonsenseGenerator.Utils
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_ARTICLE_CHANCE
By default, this class will always begin the name with a "The".
|
protected java.lang.String[] |
m_asAdjectives
A list of adjectives.
|
protected java.lang.String[] |
m_asNouns
A list of nouns.
|
protected android.content.Context |
m_ctx
A context in which the string resources are available.
|
protected int |
m_nArticleChance
The percent chance that the builder will begin the random name with
"The".
|
protected static java.util.Random |
RANDOM
The internal RNG of the builder, used to select each token in the name.
|
Constructor and Description |
---|
NonsenseShipOrPub(android.content.Context ctx)
A constructor which sets the resource context.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
getArticle()
Might start us off with ah "The".
|
java.lang.String |
getString()
Generates the name.
|
protected java.lang.String |
getStrippedNoun()
Ensures that we strip any article that was already included with the
noun resource.
|
NonsenseShipOrPub |
setAdjectives(java.util.Collection<java.lang.String> asAdjectives)
Defines the set of adjectives that should be considered when generating
the name.
|
NonsenseShipOrPub |
setAdjectives(int resAdjectives)
Defines the set of adjectives that should be considered when generating
the name.
|
NonsenseShipOrPub |
setArticleChance(int nChance)
Sets the chance that the builder will begin the name with "The".
|
NonsenseShipOrPub |
setContext(android.content.Context ctx)
Sets the resource context.
|
NonsenseShipOrPub |
setNouns(java.util.Collection<java.lang.String> asNouns)
Defines the set of nouns that should be considered when generating the
name.
|
NonsenseShipOrPub |
setNouns(int resNouns)
Defines the set of nouns that should be considered when generating the
name.
|
protected static final java.util.Random RANDOM
protected static final int DEFAULT_ARTICLE_CHANCE
setArticleChance(int)
method to alter the instance's chance at
runtime.m_nArticleChance
,
Constant Field Valuesprotected android.content.Context m_ctx
protected int m_nArticleChance
setArticleChance(int)
.DEFAULT_ARTICLE_CHANCE
protected java.lang.String[] m_asAdjectives
setAdjectives(int)
.protected java.lang.String[] m_asNouns
setNouns(int)
.public NonsenseShipOrPub(android.content.Context ctx)
ctx
- a context in which string resources are availablepublic NonsenseShipOrPub setContext(android.content.Context ctx)
setContext
in interface NonsenseGenerator
ctx
- the context in which string resources are availablepublic NonsenseShipOrPub setArticleChance(int nChance)
nChance
- an integer between 0 and 100 (inclusive)public NonsenseShipOrPub setAdjectives(int resAdjectives)
resAdjectives
- the resource ID of an array of adjectivespublic NonsenseShipOrPub setAdjectives(java.util.Collection<java.lang.String> asAdjectives)
asAdjectives
- a collection of adjective stringspublic NonsenseShipOrPub setNouns(int resNouns)
resNouns
- the resource ID of an array of nounspublic NonsenseShipOrPub setNouns(java.util.Collection<java.lang.String> asNouns)
asNouns
- a collection of noun stringspublic java.lang.String getString()
getString
in interface NonsenseGenerator
protected java.lang.String getArticle()
protected java.lang.String getStrippedNoun()