Formatted all files to the same standard

This commit is contained in:
matthew
2014-10-08 13:42:12 +01:00
parent 53a2a8b150
commit 3da9ad5469
151 changed files with 952 additions and 870 deletions

View File

@ -6,13 +6,13 @@ import java.util.List;
/**
*
* The class that needs many objects.
*
*
*/
public class AlchemistShop {
List<Potion> topShelf;
List<Potion> bottomShelf;
public AlchemistShop() {
topShelf = new ArrayList<>();
bottomShelf = new ArrayList<>();
@ -20,9 +20,9 @@ public class AlchemistShop {
}
private void fillShelves() {
PotionFactory factory = new PotionFactory();
topShelf.add(factory.createPotion(PotionType.INVISIBILITY));
topShelf.add(factory.createPotion(PotionType.INVISIBILITY));
topShelf.add(factory.createPotion(PotionType.STRENGTH));
@ -31,27 +31,27 @@ public class AlchemistShop {
topShelf.add(factory.createPotion(PotionType.STRENGTH));
topShelf.add(factory.createPotion(PotionType.HEALING));
topShelf.add(factory.createPotion(PotionType.HEALING));
bottomShelf.add(factory.createPotion(PotionType.POISON));
bottomShelf.add(factory.createPotion(PotionType.POISON));
bottomShelf.add(factory.createPotion(PotionType.POISON));
bottomShelf.add(factory.createPotion(PotionType.HOLY_WATER));
bottomShelf.add(factory.createPotion(PotionType.HOLY_WATER));
}
public void enumerate() {
System.out.println("Enumerating top shelf potions\n");
for (Potion p: topShelf) {
for (Potion p : topShelf) {
p.drink();
}
System.out.println("\nEnumerating bottom shelf potions\n");
for (Potion p: bottomShelf) {
for (Potion p : bottomShelf) {
p.drink();
}
}
}

View File

@ -1,16 +1,16 @@
package com.iluwatar;
/**
*
*
* Flyweight (PotionFactory) is useful when there is plethora of objects
* (Potion). It provides means to decrease resource usage by sharing object
* instances.
*
*
*/
public class App {
public static void main(String[] args) {
AlchemistShop alchemistShop = new AlchemistShop();
alchemistShop.enumerate();
}
public static void main(String[] args) {
AlchemistShop alchemistShop = new AlchemistShop();
alchemistShop.enumerate();
}
}

View File

@ -4,7 +4,8 @@ public class HealingPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel healed. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel healed. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class HolyWaterPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel blessed. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel blessed. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class InvisibilityPotion implements Potion {
@Override
public void drink() {
System.out.println("You become invisible. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You become invisible. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -4,7 +4,8 @@ public class PoisonPotion implements Potion {
@Override
public void drink() {
System.out.println("Urgh! This is poisonous. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("Urgh! This is poisonous. (Potion="
+ System.identityHashCode(this) + ")");
}
}

View File

@ -3,10 +3,10 @@ package com.iluwatar;
/**
*
* Interface for objects.
*
*
*/
public interface Potion {
public void drink();
}

View File

@ -5,16 +5,16 @@ import java.util.EnumMap;
/**
*
* Flyweight.
*
*
*/
public class PotionFactory {
private EnumMap<PotionType, Potion> potions;
public PotionFactory() {
potions = new EnumMap<>(PotionType.class);
}
Potion createPotion(PotionType type) {
Potion potion = potions.get(type);
if (potion == null) {
@ -45,5 +45,5 @@ public class PotionFactory {
}
return potion;
}
}

View File

@ -2,10 +2,6 @@ package com.iluwatar;
public enum PotionType {
HEALING,
INVISIBILITY,
STRENGTH,
HOLY_WATER,
POISON;
HEALING, INVISIBILITY, STRENGTH, HOLY_WATER, POISON;
}

View File

@ -4,7 +4,8 @@ public class StrengthPotion implements Potion {
@Override
public void drink() {
System.out.println("You feel strong. (Potion=" + System.identityHashCode(this) + ")");
System.out.println("You feel strong. (Potion="
+ System.identityHashCode(this) + ")");
}
}