Code example for Set

Methods: addcontainsremove

0
	 * Whether an item is chosen 
	 * @param position The position of the item 
	 * @return {@code true} if the item at that position is chosen, {@code false} otherwise 
	 */ 
	public boolean isItemChosen(int position) {
		return chosenItems.contains(position);
	} 
 
	/** 
	 * Get the currently chosen items 
	 * @return The currently chosen items as a set of their positions. If no items are chosen, returns an empty set.  
	 */ 
	public Set<Integer> getChosenItems() {
		return chosenItems;
	} 
 
	/** 
	 * Set the currently opened item 
	 * @param position The position of the currently opened item 
	 */ 
	public void setOpenedItem(int position) {
		this.openedItem = position;
	} 
 
	/** 
	 * Get the currently opened item 
	 * @return The position of the currently opened item 
	 */ 
	public int getOpenedItem() { 
		return this.openedItem;
	} 
 
	/** 
	 * Whether an item is opened 
	 * @param position The position of the item 
	 * @return {@code true} if the item is opened, {@code false} otherwise 
	 */ 
	public boolean isItemOpened(int position) {
		return this.openedItem == position;
	} 
 
	/** 
	 * Clear all choices. This sets all items to the not chosen state 
	 */ 
	public void clearChoices() { 
		chosenItems.clear();
	} 
 
	/** 
	 * Toggle the chosen state of an item 
	 * @param position The position of the item whose chosen state should be toggled 
	 */ 
	public void toggleItem(int position) {
		if (isItemChosen(position)) {
			chosenItems.remove(position);
		} else { 
			chosenItems.add(position);
		} 
	} 
 
	/** 
	 * Get the number of chosen items. Useful for displaying in the Contextual Action Bar for example. 
Stop searching for code, let great code find you!  Add Codota to your java IDE