Created
April 17, 2016 07:41
-
-
Save kostovtd/85bd61103215b72831cb479d73476d9a to your computer and use it in GitHub Desktop.
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
/*** | |
* USAGE: | |
* DataManager.getInstance().setItemsList(itemsList); | |
* | |
* Item item = DataManager.getInstance().getItemByIdx(5); | |
* | |
* Please, notice that the getItemByIdx() function my throw an exception!!! | |
*/ | |
public class DataManager { | |
private static DataManager ourInstance = new DataManager(); | |
private static List<Item> itemsList = new ArrayList<>(); | |
public static DataManager getInstance() { | |
return ourInstance; | |
} | |
private DataManager() { | |
} | |
public static List<Item> getItemsList() { | |
return itemsList; | |
} | |
public static void setItemsList(List<Item> itemsList) { | |
DataManager.itemsList = itemsList; | |
} | |
/** | |
* Return an item be it's idex | |
* @param idx The index of the desired item | |
* @return The desired item | |
* @throws IndexOutOfBoundsException in case the index is | |
* not valid | |
*/ | |
public static Item getItemByIdx(int idx) { | |
return itemsList.get(idx); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment