franta-hg@12: /**
franta-hg@12: * copy-image-resizer
franta-hg@12: * Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@12: *
franta-hg@12: * This program is free software: you can redistribute it and/or modify
franta-hg@12: * it under the terms of the GNU General Public License as published by
franta-hg@12: * the Free Software Foundation, either version 3 of the License, or
franta-hg@12: * (at your option) any later version.
franta-hg@12: *
franta-hg@12: * This program is distributed in the hope that it will be useful,
franta-hg@12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@12: * GNU General Public License for more details.
franta-hg@12: *
franta-hg@12: * You should have received a copy of the GNU General Public License
franta-hg@12: * along with this program. If not, see .
franta-hg@12: */
franta-hg@12: package cz.frantovo.copyImageResizer;
franta-hg@12:
franta-hg@12: import java.util.EnumMap;
franta-hg@12: import java.util.Map;
franta-hg@12:
franta-hg@12: /**
franta-hg@12: *
franta-hg@12: * @author Ing. František Kučera (frantovo.cz)
franta-hg@12: */
franta-hg@12: public class Counters {
franta-hg@12:
franta-hg@12: private final Map data = new EnumMap(COUNTER_TYPE.class);
franta-hg@12:
franta-hg@12: public int increment(COUNTER_TYPE counter) {
franta-hg@12: synchronized (data) {
franta-hg@12: int value = get(counter);
franta-hg@12: value++;
franta-hg@12: data.put(counter, value);
franta-hg@12: return value;
franta-hg@12: }
franta-hg@12: }
franta-hg@12:
franta-hg@12: public int get(COUNTER_TYPE counter) {
franta-hg@12: Integer value = data.get(counter);
franta-hg@12: return value == null ? 0 : value;
franta-hg@12: }
franta-hg@12:
franta-hg@12: @Override
franta-hg@12: public String toString() {
franta-hg@12: StringBuilder sb = new StringBuilder();
franta-hg@12:
franta-hg@12: sb.append("Counters: ");
franta-hg@12:
franta-hg@12: for (COUNTER_TYPE counter : COUNTER_TYPE.values()) {
franta-hg@12: sb.append(counter);
franta-hg@12: sb.append("=");
franta-hg@12: sb.append(get(counter));
franta-hg@12: sb.append(" ");
franta-hg@12:
franta-hg@12: }
franta-hg@12:
franta-hg@12: return sb.toString();
franta-hg@12: }
franta-hg@12:
franta-hg@12: public static enum COUNTER_TYPE {
franta-hg@12:
franta-hg@12: DIRECTORIES,
franta-hg@12: FILES,
franta-hg@12: RESIZED,
franta-hg@13: JUST_COPIED,
franta-hg@12: SKIPPED_UNKNOWN_EXTENSION,
franta-hg@12: SKIPPED_ERROR;
franta-hg@12:
franta-hg@12: @Override
franta-hg@12: public String toString() {
franta-hg@12: return name().toLowerCase();
franta-hg@12: }
franta-hg@12:
franta-hg@12: }
franta-hg@12: }