Skip to content

Commit

Permalink
Create NewsPerCategoryCounterSingleton.java
Browse files Browse the repository at this point in the history
  • Loading branch information
ernis9112 committed Oct 29, 2014
1 parent 0673278 commit a9458c5
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions NewsPerCategoryCounterSingleton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.LinkedHashMap;


public class NewsPerCategoryCounterSingleton {

private static NewsPerCategoryCounterSingleton instance = null;

private LinkedHashMap categoriesCounts = new LinkedHashMap();


private NewsPerCategoryCounterSingleton()
{
}

public static NewsPerCategoryCounterSingleton getInstance()
{
if (instance == null)
{
instance = new NewsPerCategoryCounterSingleton();
}
return instance;
}

public void fillCategoryArray(String category)
{
if(categoriesCounts.containsKey(category)) {
Integer val = (Integer) categoriesCounts.get(category);
categoriesCounts.put(category, val + 1);
} else {
categoriesCounts.put(category, 1);
Logger.getInstance().addLog("Skaiciujant prideta nauja kategorija: " + category);
}

}

public LinkedHashMap getCategories()
{
return categoriesCounts;
}

}

0 comments on commit a9458c5

Please sign in to comment.