package com.geektcp.alpha.design.pattern.flyweight;

import java.util.HashMap;

/**
 * @author tanghaiyang on 2019/9/21.
 */
public class FlyweightFactory {

    private HashMap<String, Flyweight> flyweights = new HashMap<>();

    Flyweight getFlyweight(String intrinsicState) {
        if (!flyweights.containsKey(intrinsicState)) {
            Flyweight flyweight = new ConcreteFlyweight(intrinsicState);
            flyweights.put(intrinsicState, flyweight);
        }
        return flyweights.get(intrinsicState);
    }
}

{'avg_line_length': 26.4, 'max_line_length': 72, 'alphanum_fraction': 0.6931818181818182, 'licenses': ['Apache-2.0'], 'repository_name': 'arist0tle/alpha', 'path': 'alpha-design/alpha-design-pattern/src/main/java/com/geektcp/alpha/design/pattern/flyweight/FlyweightFactory.java', 'size': 528, 'lang': 'Java'}