/* 
 * Copyright (C) 2016 Hobrasoft s.r.o.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.hobrasoft.pdfmu;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Hex;

/**
 *
 * @author <a href="mailto:filip.bartek@hobrasoft.cz">Filip Bartek</a>
 */
public class PdfmuUtils {

    /**
     * Converts an array of keys and an array of values to a {@link Map}.
     *
     * @param <K> the type of keys.
     * @param <V> the type of values.
     * @param keys the array of keys. Only the keys that have a matching value
     * are used.
     * @param values the array of values. Only the values that have a matching
     * key are used.
     * @return a {@link Map} that contains a key-value pair for each index in
     * keys and values. The order of the entries is preserved by the underlying
     * implementation ({@link LinkedHashMap}).
     */
    // TODO: Rename
    public static <K, V> Map<K, V> sortedMap(K[] keys, V[] values) {
        Map<K, V> result = new LinkedHashMap<>();
        int n = Math.min(keys.length, values.length);
        for (int i = 0; i < n; ++i) {
            result.put(keys[i], values[i]);
        }
        return result;
    }

    // TODO: Rename
    public static <K, V> Map<K, V> sortedMap(Map.Entry<K, V>... entries) {
        Map<K, V> result = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : entries) {
            K key = entry.getKey();
            V value = entry.getValue();
            result.put(key, value);
        }
        return result;
    }

    /**
     * Extracts named groups from a matcher.
     *
     * @param m the matcher.
     * @param names the names of the groups.
     * @return a sorted map that assigns group values to the names.
     */
    public static Map<String, String> getMatcherGroups(Matcher m, List<String> names) {
        assert m != null;
        assert names != null;
        Map<String, String> result = new LinkedHashMap<>();
        for (String name : names) {
            result.put(name, m.group(name));
        }
        return result;
    }

    public static int countMatches(String regex, String message) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(message);
        int count = 0;
        while (m.find()) {
            count++;
        }
        return count;
    }

    public static byte[] objectToBytes(Object obj) throws IOException {
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream so = new ObjectOutputStream(bo);
        so.writeObject(obj);
        so.flush();
        return bo.toByteArray();
    }

    public static String encodeHexString(Object obj) throws IOException {
        return Hex.encodeHexString(objectToBytes(obj));
    }
}

@@ -2904,690 +2904,7 @@
    %7D
-%0A%0A    public static int countMatches(String regex, String message) %7B%0A        Pattern p = Pattern.compile(regex);%0A        Matcher m = p.matcher(message);%0A        int count = 0;%0A        while (m.find()) %7B%0A            count++;%0A        %7D%0A        return count;%0A    %7D%0A%0A    public static byte%5B%5D objectToBytes(Object obj) throws IOException %7B%0A        ByteArrayOutputStream bo = new ByteArrayOutputStream();%0A        ObjectOutputStream so = new ObjectOutputStream(bo);%0A        so.writeObject(obj);%0A        so.flush();%0A        return bo.toByteArray();%0A    %7D%0A%0A    public static String encodeHexString(Object obj) throws IOException %7B%0A        return Hex.encodeHexString(objectToBytes(obj));%0A    %7D
 %0A%7D%0A

Remove unused methods