NodeAttributes.java :  » UnTagged » android-family-browser » ca » chaves » androidApp » familyBrowser » helpers » Android Open Source

Android Open Source » UnTagged » android family browser 
android family browser » ca » chaves » androidApp » familyBrowser » helpers » NodeAttributes.java
package ca.chaves.androidApp.familyBrowser.helpers;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/*
 * The class NodeAttributes stores the node attribute's metadata. Each attribute
 * contains a flag indicating if it is a hidden attribute, and a label.
 * @author david@chaves.ca
 */
public class NodeAttributes {
    
    protected static final String TAG = NodeAttributes.class.getSimpleName();
    
    /** Hidden attribute_id(s) */
    private final Set<Integer> m_hiddenAttributeIds = new HashSet<Integer>();
    /** Attribute labels - this map is indexed by attribute_id(s) */
    private final Map<Integer, String> m_labelsMap = new HashMap<Integer, String>();
    
    /**
     * Is this attribute_id hidden?
     * 
     * @param attributeId
     * @return true if this attributeId is hidden
     */
    public boolean isAttributeHidden(final Integer attributeId) {
        return this.m_hiddenAttributeIds.contains(attributeId);
    }
    
    /**
     * Get the attribute label for this attribute_id.
     * 
     * @param attributeId
     * @return the attributeId's label
     */
    public String getAttributeLabel(final Integer attributeId) {
        final String label = this.m_labelsMap.get(attributeId);
        return (label == null) ? "" : label;
    }
    
    /**
     * Add attribute.
     * 
     * @param attributeId
     * @param isHidden
     * @param attributeLabel
     */
    public void addAttribute(final Integer attributeId, final boolean isHidden, final String attributeLabel) {
        if (isHidden) {
            this.m_hiddenAttributeIds.add(attributeId);
        }
        if (attributeLabel != null) {
            this.m_labelsMap.put(attributeId, attributeLabel);
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.