Skip to content

Instantly share code, notes, and snippets.

@kostovtd
Created April 17, 2016 07:41
Show Gist options
  • Save kostovtd/85bd61103215b72831cb479d73476d9a to your computer and use it in GitHub Desktop.
Save kostovtd/85bd61103215b72831cb479d73476d9a to your computer and use it in GitHub Desktop.
/***
* 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