Package instantbach.data

Source Code of instantbach.data.SymbolList

package instantbach.data;

import java.util.ArrayList;
import instantbach.data.chord.Symbol;
import java.util.HashMap;

/**
* <p>Title: Symbol list</p>
*
* <p>Description: Represents a list of chord symbols</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author John Valentino II
* @version 1.0
*/
public class SymbolList {

    /** Represents the list of available symbols */
    private ArrayList<Symbol> list;
    /** Represents a list of symbols by identifer */
    private HashMap<String, Symbol> identifierMap;

    /**
     * Creates a list of symbols
     */
    public SymbolList() {
        list = new ArrayList<Symbol>();
        identifierMap = new HashMap<String,Symbol>();
    }

    /**
     * Adds the symbol of the given identifier and displayed name to this list
     * @param identifier String
     * @param displayed String
     */
    public void add(String identifier, String displayed) {
        Symbol symbol = new Symbol(identifier, displayed);
        list.add(symbol);
        identifierMap.put(symbol.getIdentifier(), symbol);
    }

    /**
     * Adds the given symbol to the current list
     * @param symbol Symbol
     */
    public void add(Symbol symbol) {
        list.add(symbol);
        identifierMap.put(symbol.getIdentifier(), symbol);
    }

    /**
     * Returns the symbol for the givne identifier
     * @param identifier String
     * @return Symbol
     */
    public Symbol getSymbolByIdentifier(String identifier) {
        return identifierMap.get(identifier);
    }

    /**
     * Returns the symbol at the given index
     * @param index int
     * @return Symbol
     */
    public Symbol get(int index) {
        if (index > -1 && index < size())
            return list.get(index);
        else
            return null;
    }

    /**
     * Returns the displayed text for the symbol at the given index
     * @param index int
     * @return String
     */
    public String getDisplayed(int index) {
        Symbol symbol = this.get(index);

        if (symbol != null)
            return symbol.getDisplayed();
        else
            return null;
    }

    /**
     * Returns the symbol identifier at the given index
     * @param index int
     * @return String
     */
    public String getIdentifier(int index) {
        Symbol symbol = this.get(index);

        if (symbol != null)
            return symbol.getIdentifier();
        else
            return null;
    }

    /**
     * Returns the number of symbols in this list
     * @return int
     */
    public int size() {
        return list.size();
    }

    /**
     * Clears this list
     */
    public void clear() {
        list.clear();
    }
}
TOP

Related Classes of instantbach.data.SymbolList

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.