#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#    This file is part of arena.
#   
#    arena is free software: you can redistribute it and/or modify it
#    under the terms of the GNU General Public License as published by the
#    Free Software Foundation; either version 3 of the License or, at your
#    option, any later version.
#
#    arena is distributed in the hope that it will be useful, but
#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABLITY
#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
#    License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with arena.  If not, see <http://www.gnu.org/licenses/>. 

## @file
#  This file defines and implements a class that stores a string value as a
#  name.  It is extended to allow a class instance to be easily added to a binary
#  tree.

from Library.Memory.BinaryTrees import ABinaryLeaf
from Library.String.Utilities import IsPrintable, String

## A binary node that uses a string key instead of an integer key for sorting.
class AStringLeaf(ABinaryLeaf):
    ## Constructor
    def __init__(Self, thisName):
        ABinaryLeaf.__init__(Self, thisName)
        
    # IsPrintable implementation -----------------------------------------------
    ## Return a string representation of the node.  This representation is 
    #  merely the string key used to sort the node.
    def toString(Self):        
        return Self._key
        
    # Properties ---------------------------------------------------------------
    ## Retrieve the name of the node.  This is its sort key or, if that is 
    #  not available, the display name of the class.
    def name(Self):
        if len(Self._key) > 0:
            return Self._key
            
        else:
            return ABinaryLeaf.name(Self)
