<commit_before>/*
 * Date: 22/7/2008
 * Author: rcote
 * File: uk.ac.ebi.jmzml.xml.jaxb.unmarshaller.cache.AdapterObjectCache
 *
 * jmzml is Copyright 2008 The European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 *
 */

package uk.ac.ebi.jmzml.xml.jaxb.unmarshaller.cache;

import uk.ac.ebi.jmzml.model.mzml.*;
import uk.ac.ebi.jmzml.xml.Constants;

import java.util.HashMap;

public class AdapterObjectCache {

    private HashMap<String, CV> cvMap = new HashMap<String, CV>();
    private HashMap<String, DataProcessing> dataProcessingMap = new HashMap<String, DataProcessing>();
    private HashMap<String, InstrumentConfiguration> instrConfigMap = new HashMap<String, InstrumentConfiguration>();
    private HashMap<String, ReferenceableParamGroup> refParamGroupMap = new HashMap<String, ReferenceableParamGroup>();
    private HashMap<String, Sample> sampleMap = new HashMap<String, Sample>();
    private HashMap<String, Software> softwareMap = new HashMap<String, Software>();
    private HashMap<String, SourceFile> sourceFileMap = new HashMap<String, SourceFile>();
    private HashMap<String, Spectrum> spectrumMap = new HashMap<String, Spectrum>();

    public <MzMLObject> MzMLObject getCachedObject(String ID, Constants.ReferencedType type) {
        switch (type) {
            case CV:
                return (MzMLObject) cvMap.get(ID);
            case DataProcessing:
                return (MzMLObject) dataProcessingMap.get(ID);
            case InstrumentConfiguration:
                return (MzMLObject) instrConfigMap.get(ID);
            case ReferenceableParamGroup:
                return (MzMLObject) refParamGroupMap.get(ID);
            case Sample:
                return (MzMLObject) sampleMap.get(ID);
            case Software:
                return (MzMLObject) softwareMap.get(ID);
            case SourceFile:
                return (MzMLObject) sourceFileMap.get(ID);
            case Spectrum:<commit_msg>added todo note for caching<commit_after>/*
 * Date: 22/7/2008
 * Author: rcote
 * File: uk.ac.ebi.jmzml.xml.jaxb.unmarshaller.cache.AdapterObjectCache
 *
 * jmzml is Copyright 2008 The European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 *
 */

package uk.ac.ebi.jmzml.xml.jaxb.unmarshaller.cache;

import uk.ac.ebi.jmzml.model.mzml.*;
import uk.ac.ebi.jmzml.xml.Constants;

import java.util.HashMap;

public class AdapterObjectCache {

    //todo
    //configure caching levels so that individual object classes are/aren't cached
    //at runtime

    private HashMap<String, CV> cvMap = new HashMap<String, CV>();
    private HashMap<String, DataProcessing> dataProcessingMap = new HashMap<String, DataProcessing>();
    private HashMap<String, InstrumentConfiguration> instrConfigMap = new HashMap<String, InstrumentConfiguration>();
    private HashMap<String, ReferenceableParamGroup> refParamGroupMap = new HashMap<String, ReferenceableParamGroup>();
    private HashMap<String, Sample> sampleMap = new HashMap<String, Sample>();
    private HashMap<String, Software> softwareMap = new HashMap<String, Software>();
    private HashMap<String, SourceFile> sourceFileMap = new HashMap<String, SourceFile>();
    private HashMap<String, Spectrum> spectrumMap = new HashMap<String, Spectrum>();

    public <MzMLObject> MzMLObject getCachedObject(String ID, Constants.ReferencedType type) {
        switch (type) {
            case CV:
                return (MzMLObject) cvMap.get(ID);
            case DataProcessing:
                return (MzMLObject) dataProcessingMap.get(ID);
            case InstrumentConfiguration:
                return (MzMLObject) instrConfigMap.get(ID);
            case ReferenceableParamGroup:
                return (MzMLObject) refParamGroupMap.get(ID);
            case Sample:
                return (MzMLObject) sampleMap.get(ID);
            case Software:
                return (MzMLObject) softwareMap.get(ID);
            case SourceFile:
                return (MzMLObject) sourceFileMap.get(ID);
            case Spectrum:
{'fraction_non_alphanumeric': 0.09137254901960784, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 3.3302207130730053, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '4048272', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1346, 'n_words': 428}