-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create NewsPerCategoryCounterSingleton.java
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |