/* * Copyright (C) 2004-2014 L2J Server * * This file is part of L2J Server. * * L2J Server is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * L2J Server 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 * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.l2jserver.util; import java.util.HashMap; import java.util.Map; import com.l2jserver.gameserver.model.interfaces.IL2EntryProcedure; import com.l2jserver.gameserver.model.interfaces.IProcedure; /** * A custom version of HashMap: Extension for iterating without using temporary collection
* @author UnAfraid * @param * @param */ public class L2HashMap extends HashMap { private static final long serialVersionUID = 8503855490858805336L; private static final float DEFAULT_LOAD_FACTOR = 0.75f; public L2HashMap() { super(); } public L2HashMap(Map map) { super(map); } public L2HashMap(int initialCapacity) { this(initialCapacity, DEFAULT_LOAD_FACTOR); } public L2HashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } /** * Public method that iterate entire collection.
* @param proc - a class method that must be executed on every element of collection.
* @return - returns true if entire collection is iterated, false if it`s been interrupted by
* check method (IL2EntryProcedure.execute())
*/ public boolean executeForEachEntry(IL2EntryProcedure proc) { for (Map.Entry e : entrySet()) { if (!proc.execute(e.getKey(), e.getValue())) { return false; } } return true; } public boolean executeForEachKey(IProcedure proc) { for (K k : keySet()) { if (!proc.execute(k)) { return false; } } return true; } public boolean executeForEachValue(IProcedure proc) { for (V v : values()) { if (!proc.execute(v)) { return false; } } return true; } }