Here you can find the source of toggleEntry(T entry, Collection
Parameter | Description |
---|---|
entry | tested entry. |
collection | tested collection. |
public static <T> boolean toggleEntry(T entry, Collection<T> collection)
//package com.java2s; /*//w ww. j av a 2 s . c om * This file is part of Bukkit Plugin Utilities. * * Bukkit Plugin Utilities is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the License, * or (at your option) any later version. * * Bukkit Plugin Utilities is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Bukkit Plugin Utilities. * If not, see <http://www.gnu.org/licenses/>. */ import java.util.Collection; public class Main { /** * Toggles an entry in a collection. So if the entry is in the collection it * will be removed and if it isn't in the collection it will be added. * * @param entry * tested entry. * @param collection * tested collection. * @return If the entry was added. * @since 1.3 */ public static <T> boolean toggleEntry(T entry, Collection<T> collection) { if (collection.remove(entry)) { return false; } else { collection.add(entry); return true; } } }