Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduces checkstyle errors in flyweight
  • Loading branch information
anuragagarwal561994 committed Nov 11, 2019
commit 2f974fb6a01985a08000e86bc0bcb50041d5cce6
41 changes: 19 additions & 22 deletions flyweight/src/main/java/com/iluwatar/flyweight/AlchemistShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@

package com.iluwatar.flyweight;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* AlchemistShop holds potions on its shelves. It uses PotionFactory to provide the potions.
*
*/
public class AlchemistShop {

Expand All @@ -42,31 +39,31 @@ public class AlchemistShop {
private List<Potion> bottomShelf;

/**
* Constructor
* Constructor.
*/
public AlchemistShop() {
PotionFactory factory = new PotionFactory();
topShelf = List.of(
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.HEALING)
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.INVISIBILITY),
factory.createPotion(PotionType.STRENGTH),
factory.createPotion(PotionType.HEALING),
factory.createPotion(PotionType.HEALING)
);
bottomShelf = List.of(
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.HOLY_WATER),
factory.createPotion(PotionType.HOLY_WATER)
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.POISON),
factory.createPotion(PotionType.HOLY_WATER),
factory.createPotion(PotionType.HOLY_WATER)
);
}

/**
* Get a read-only list of all the items on the top shelf
* Get a read-only list of all the items on the top shelf.
*
* @return The top shelf potions
*/
Expand All @@ -75,7 +72,7 @@ public final List<Potion> getTopShelf() {
}

/**
* Get a read-only list of all the items on the bottom shelf
* Get a read-only list of all the items on the bottom shelf.
*
* @return The bottom shelf potions
*/
Expand All @@ -84,7 +81,7 @@ public final List<Potion> getBottomShelf() {
}

/**
* Enumerate potions
* Enumerate potions.
*/
public void enumerate() {

Expand Down
14 changes: 6 additions & 8 deletions flyweight/src/main/java/com/iluwatar/flyweight/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@
package com.iluwatar.flyweight;

/**
*
* Flyweight pattern is useful when the program needs a huge amount of objects. It provides means to
* decrease resource usage by sharing object instances.
* <p>
* In this example {@link AlchemistShop} has great amount of potions on its shelves. To fill the
*
* <p>In this example {@link AlchemistShop} has great amount of potions on its shelves. To fill the
* shelves {@link AlchemistShop} uses {@link PotionFactory} (which represents the Flyweight in this
* example). Internally {@link PotionFactory} holds a map of the potions and lazily creates new ones
* when requested.
* <p>
* To enable safe sharing, between clients and threads, Flyweight objects must be immutable.
*
* <p>To enable safe sharing, between clients and threads, Flyweight objects must be immutable.
* Flyweight objects are by definition value objects.
*
*/
public class App {

/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* HealingPotion
*
* HealingPotion.
*/
public class HealingPotion implements Potion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* HolyWaterPotion
*
* HolyWaterPotion.
*/
public class HolyWaterPotion implements Potion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* InvisibilityPotion
*
* InvisibilityPotion.
*/
public class InvisibilityPotion implements Potion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* PoisonPotion
*
* PoisonPotion.
*/
public class PoisonPotion implements Potion {

Expand Down
2 changes: 0 additions & 2 deletions flyweight/src/main/java/com/iluwatar/flyweight/Potion.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.flyweight;

/**
*
* Interface for Potions.
*
*/
public interface Potion {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import java.util.Map;

/**
*
* PotionFactory is the Flyweight in this example. It minimizes memory use by sharing object
* instances. It holds a map of potion instances and new potions are created only when none of the
* type already exists.
*
*/
public class PotionFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.iluwatar.flyweight;

/**
*
* Enumeration for potion types.
*
*/
public enum PotionType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import org.slf4j.LoggerFactory;

/**
*
* StrengthPotion
*
* StrengthPotion.
*/
public class StrengthPotion implements Potion {

Expand Down