Skip to content

Instantly share code, notes, and snippets.

@MaxxselvaK
Created October 16, 2022 12:34
Show Gist options
  • Save MaxxselvaK/7a4895c6c55f70d65ca557829b4b49b8 to your computer and use it in GitHub Desktop.
Save MaxxselvaK/7a4895c6c55f70d65ca557829b4b49b8 to your computer and use it in GitHub Desktop.
FlyWeight
package FlyWeight;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class CellPropertyFactory {
Map<Integer, CellProperty> map;
CellPropertyFactory(){
map = new HashMap<>();
}
CellProperty getDefaultCellProperty(String fontFamily,int fontSize,boolean isBold){
int hash = Objects.hash(fontFamily,fontSize,isBold);
if(map.containsKey(hash)){
System.out.println("Reusing cellProperty");
return map.get(hash);
}else{
System.out.println("New cellProperty");
CellProperty prop = new CellProperty(fontFamily,12,false);
map.put(hash,prop);
return prop;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment