<commit_before>/****************************************************************************
 * Copyright (C) 2012 ecsec GmbH.
 * All rights reserved.
 * Contact: ecsec GmbH (<EMAIL>)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.common.sal.state;

import iso.std.iso_iec._24727.tech.schema.CardApplicationPathType;
import iso.std.iso_iec._24727.tech.schema.ChannelHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListMap;
import org.openecard.common.util.ByteComparator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class CardStateMap {

    private static final Logger _logger = LoggerFactory.getLogger(CardStateMap.class);

    private final TreeSet<CardStateEntry> allEntries = new TreeSet<CardStateEntry>();
    private final ConcurrentSkipListMap<String,Set<CardStateEntry>> sessionMap = new ConcurrentSkipListMap<String,Set<CardStateEntry>>();
    private final ConcurrentSkipListMap<byte[],Set<CardStateEntry>> contextMap = new ConcurrentSkipListMap<byte[],Set<CardStateEntry>>(new ByteComparator());
    private final ConcurrentSkipListMap<byte[],Set<CardStateEntry>> slothandleMap = new ConcurrentSkipListMap<byte[],Set<CardStateEntry>>(new ByteComparator());


    public synchronized CardStateEntry getEntry(ConnectionHandleType handle) {
	return getEntry(handle);
    }
    public synchronized CardStateEntry getEntry(ConnectionHandleType handle, boolean filterAppId) {
	Set<CardStateEntry> entry = getMatchingEntries(handle, filterAppId);
	int size = entry.size();
	if (size == 1) {
	    return entry.iterator().next();
	} else if (size == 0) {
	    _logger.warn("No state entry found for the given ConnectionHandle.");
	} else {
	    _logger.warn("More than one state entry found for the given ConnectionHandle.");
	}
	return null;
    }

    public synchronized void addEntry(CardStateEntry entry) {
	ConnectionHandleType handle = entry.handleCopy();<commit_msg>Fix getEntry(ConnectionHandleType), the return value should not be the same method (recursive endless loop)<commit_after>/****************************************************************************
 * Copyright (C) 2012-2014 ecsec GmbH.
 * All rights reserved.
 * Contact: ecsec GmbH (<EMAIL>)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.common.sal.state;

import iso.std.iso_iec._24727.tech.schema.CardApplicationPathType;
import iso.std.iso_iec._24727.tech.schema.ChannelHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentSkipListMap;
import org.openecard.common.util.ByteComparator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class CardStateMap {

    private static final Logger _logger = LoggerFactory.getLogger(CardStateMap.class);

    private final TreeSet<CardStateEntry> allEntries = new TreeSet<CardStateEntry>();
    private final ConcurrentSkipListMap<String,Set<CardStateEntry>> sessionMap = new ConcurrentSkipListMap<String,Set<CardStateEntry>>();
    private final ConcurrentSkipListMap<byte[],Set<CardStateEntry>> contextMap = new ConcurrentSkipListMap<byte[],Set<CardStateEntry>>(new ByteComparator());
    private final ConcurrentSkipListMap<byte[],Set<CardStateEntry>> slothandleMap = new ConcurrentSkipListMap<byte[],Set<CardStateEntry>>(new ByteComparator());


    public synchronized CardStateEntry getEntry(ConnectionHandleType handle) {
	return getEntry(handle, true);
    }
    public synchronized CardStateEntry getEntry(ConnectionHandleType handle, boolean filterAppId) {
	Set<CardStateEntry> entry = getMatchingEntries(handle, filterAppId);
	int size = entry.size();
	if (size == 1) {
	    return entry.iterator().next();
	} else if (size == 0) {
	    _logger.warn("No state entry found for the given ConnectionHandle.");
	} else {
	    _logger.warn("More than one state entry found for the given ConnectionHandle.");
	}
	return null;
    }

    public synchronized void addEntry(CardStateEntry entry) {
	ConnectionHandleType handle = entry.handleCopy();
{'fraction_non_alphanumeric': 0.14049859666501568, 'fraction_numerical': 0.011226679874525343, 'mean_word_length': 5.44468085106383, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936854', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1623, 'n_words': 487}