2 * Free Telco Dictionary
3 * Copyright © 2013 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package cz.frantovo.telco.dictionary;
20 import java.io.Closeable;
21 import java.util.HashSet;
22 import java.util.Iterator;
24 import java.util.Map.Entry;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import org.w3c.dom.Node;
29 import org.w3c.dom.NodeList;
33 * @author Ing. František Kučera (frantovo.cz)
35 public class Functions {
37 private static final Logger log = Logger.getLogger(Functions.class.getName());
39 public static Iterable<Node> nodeIterable(final NodeList list) {
40 return new Iterable<Node>() {
42 public Iterator<Node> iterator() {
43 return new Iterator<Node>() {
47 public boolean hasNext() {
48 return position < list.getLength();
53 return list.item(position++);
57 public void remove() {
58 throw new UnsupportedOperationException("remove not supported");
65 public static void close(Closeable c) {
68 } catch (Exception e) {
69 log.log(Level.WARNING, "closing of " + c + " has failed", e);
73 public static boolean equalz(Object a, Object b) {
74 return a == null ? b == null : a.equals(b);
77 public static <K, V> Set<K> getKeysForValue(Map<K, V> map, V value) {
78 Set<K> keysFound = new HashSet<>();
80 for (Entry<K, V> entry : map.entrySet()) {
81 if (equalz(value, entry.getValue())) {
82 keysFound.add(entry.getKey());