/*
 * VerificationSessions.java
 *
 * Copyright (c) 2015, Sietse Ringers, Radboud University
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the IRMA project nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package org.irmacard.verification.web;

import java.util.HashMap;

public class VerificationSessions {
    private static VerificationSessions vs = null;

    public static VerificationSessions getInstance() {
        if (vs == null) {
            vs = new VerificationSessions();
        }
        return vs;
    }

    private HashMap<String, VerificationSession> sessions;

    public VerificationSessions() {
        sessions = new HashMap<String, VerificationSession>();
    }

    public void addSession(VerificationSession session) {
        sessions.put(session.getSessionToken(), session);
    }

    public VerificationSession getSession(String sessionToken) {
        return sessions.get(sessionToken);
    }

    public void remove(VerificationSession session) {
        sessions.remove(session.getSessionToken());
    }
}

@@ -1678,16 +1678,44 @@
 HashMap;
+%0Aimport java.util.Map.Entry;
 %0A%0Apublic
@@ -2473,11 +2473,350 @@
 );%0A    %7D
+%0A%0A    public void print() %7B%0A        System.out.println(%22Active verification sessions:%22);%0A        for (Entry%3CString, VerificationSession%3E pairs : sessions.entrySet()) %7B%0A            String key = pairs.getKey();%0A            VerificationSession session = pairs.getValue();%0A%0A            System.out.println(key + %22: %22 + session);%0A        %7D%0A    %7D
 %0A%7D%0A

Debug print function for active sessions