001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle-sdk.
005 *
006 * Dicoogle/dicoogle-sdk is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle-sdk is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.sdk.utils;
020
021import java.lang.reflect.Field;
022import java.util.HashMap;
023import java.util.Iterator;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028import org.dcm4che2.data.Tag;
029
030/**
031 *
032 * @author Lu??s A. Basti??o Silva <bastiao@ua.pt>
033 */
034public class DictionaryAccess
035{
036
037    private HashMap<String, Integer> tagList = new HashMap<String, Integer>();
038    private HashMap<Integer, String> tagListByTag = new HashMap<Integer, String>();
039
040    
041    private static final DictionaryAccess instance =  new DictionaryAccess(); ;
042
043    public static DictionaryAccess getInstance()
044    {
045        return instance;
046    }
047
048    private DictionaryAccess()
049    {
050        
051        Field [] tags = Tag.class.getFields();
052        for (int i = 0 ; i<tags.length; i++)
053        {
054            try {
055                tagList.put(tags[i].getName(), tags[i].getInt(null));
056                tagListByTag.put(tags[i].getInt(null),tags[i].getName());
057            } catch (IllegalArgumentException ex) {
058                LoggerFactory.getLogger(DictionaryAccess.class).error(ex.getMessage(), ex);
059            } catch (IllegalAccessException ex) {
060                LoggerFactory.getLogger(DictionaryAccess.class).error(ex.getMessage(), ex);
061            }
062        }
063    }
064
065    public String tagName(int tag)
066    {
067        return this.tagListByTag.get(tag);
068    }
069
070    public String toString()
071    {
072        String str = "" ;
073        Iterator<String> it = (Iterator<String>) getTagList().keySet().iterator();
074        while(it.hasNext())
075        {
076            String key = it.next();
077            str+="Name: " + key + " with value: " +
078                    Integer.toHexString( this.getTagList().get(key));
079        }
080        return str ;
081    }
082
083
084    /*public static void  main(String args[]) throws IllegalArgumentException, IllegalAccessException
085    {
086        DictionaryAccess da = new DictionaryAccess();
087        
088    }*/
089
090    /**
091     * @return the tagList
092     */
093    public HashMap<String, Integer> getTagList() {
094        return tagList;
095    }
096
097    /**
098     * @param tagList the tagList to set
099     */
100    public void setTagList(HashMap<String, Integer> tagList) {
101        this.tagList = tagList;
102    }
103
104}