public static void main(String[] args) { System.out.println("Some mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 60); System.out.println("Some lower-case names:"); printNameSamples(new SimpleNameFactory(false), 60); System.out.println("Some more mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 80); System.out.println("Some more lower-case names:"); printNameSamples(new SimpleNameFactory(false), 80); }
/** * Creates and returns the name at the given index. */ private String newName(int index) { // If we're allowed to generate mixed-case names, we can use twice as // many characters. int totalCharacterCount = generateMixedCaseNames ? 2 * CHARACTER_COUNT : CHARACTER_COUNT; int baseIndex = index / totalCharacterCount; int offset = index % totalCharacterCount; char newChar = charAt(offset); String newName = baseIndex == 0 ? new String(new char[] { newChar }) : (name(baseIndex-1) + newChar); return newName; }
/** * Returns the name at the given index. */ private String name(int index) { // Which cache do we need? List cachedNames = generateMixedCaseNames ? cachedMixedCaseNames : cachedLowerCaseNames; // Do we have the name in the cache? if (index < cachedNames.size()) { return (String)cachedNames.get(index); } // Create a new name and cache it. String name = newName(index); cachedNames.add(index, name); return name; }
public static void main(String[] args) { SpecialNameFactory factory = new SpecialNameFactory(new SimpleNameFactory()); for (int counter = 0; counter < 50; counter++) { System.out.println("["+factory.nextName()+"]"); } } }
private static void printNameSamples(SimpleNameFactory factory, int count) { for (int counter = 0; counter < count; counter++) { System.out.println(" ["+factory.nextName()+"]"); } } }
public String nextName() { return name(index++); }
public static void main(String[] args) { SpecialNameFactory factory = new SpecialNameFactory(new SimpleNameFactory()); for (int counter = 0; counter < 50; counter++) { System.out.println("["+factory.nextName()+"]"); } } }
private static void printNameSamples(SimpleNameFactory factory, int count) { for (int counter = 0; counter < count; counter++) { System.out.println(" ["+factory.nextName()+"]"); } } }
public String nextName() { return name(index++); }
public static void main(String[] args) { SpecialNameFactory factory = new SpecialNameFactory(new SimpleNameFactory()); for (int counter = 0; counter < 50; counter++) { System.out.println("["+factory.nextName()+"]"); } } }
public static void main(String[] args) { System.out.println("Some mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 60); System.out.println("Some lower-case names:"); printNameSamples(new SimpleNameFactory(false), 60); System.out.println("Some more mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 80); System.out.println("Some more lower-case names:"); printNameSamples(new SimpleNameFactory(false), 80); }
/** * Creates and returns the name at the given index. */ private String newName(int index) { // If we're allowed to generate mixed-case names, we can use twice as // many characters. int totalCharacterCount = generateMixedCaseNames ? 2 * CHARACTER_COUNT : CHARACTER_COUNT; int baseIndex = index / totalCharacterCount; int offset = index % totalCharacterCount; char newChar = charAt(offset); String newName = baseIndex == 0 ? new String(new char[] { newChar }) : (name(baseIndex-1) + newChar); return newName; }
private static void printNameSamples(SimpleNameFactory factory, int count) { for (int counter = 0; counter < count; counter++) { System.out.println(" ["+factory.nextName()+"]"); } } }
public String nextName() { return name(index++); }
/** * Returns the name at the given index. */ private String name(int index) { // Which cache do we need? List cachedNames = generateMixedCaseNames ? cachedMixedCaseNames : cachedLowerCaseNames; // Do we have the name in the cache? if (index < cachedNames.size()) { return (String)cachedNames.get(index); } // Create a new name and cache it. String name = newName(index); cachedNames.add(index, name); return name; }
public static void main(String[] args) { SpecialNameFactory factory = new SpecialNameFactory(new SimpleNameFactory()); for (int counter = 0; counter < 50; counter++) { System.out.println("["+factory.nextName()+"]"); } } }
public static void main(String[] args) { System.out.println("Some mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 60); System.out.println("Some lower-case names:"); printNameSamples(new SimpleNameFactory(false), 60); System.out.println("Some more mixed-case names:"); printNameSamples(new SimpleNameFactory(true), 80); System.out.println("Some more lower-case names:"); printNameSamples(new SimpleNameFactory(false), 80); }
/** * Creates and returns the name at the given index. */ private String newName(int index) { // If we're allowed to generate mixed-case names, we can use twice as // many characters. int totalCharacterCount = generateMixedCaseNames ? 2 * CHARACTER_COUNT : CHARACTER_COUNT; int baseIndex = index / totalCharacterCount; int offset = index % totalCharacterCount; char newChar = charAt(offset); String newName = baseIndex == 0 ? new String(new char[] { newChar }) : (name(baseIndex-1) + newChar); return newName; }
private static void printNameSamples(SimpleNameFactory factory, int count) { for (int counter = 0; counter < count; counter++) { System.out.println(" ["+factory.nextName()+"]"); } } }
public String nextName() { return name(index++); }