#####################################################################
#####################################################################
## Versavant Topic Map Application Bus / Subject Addressing Engine ##
## Copyright 2005 Steven R. Newcomb                                ##
##                                                                 ##
## This software is licensed under the Apache License, Version 2.0 ##
## (the "License"); you may not use this file except in compliance ##
## with the License.  Copies of the License are available 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.        ##
##                                                                 ##
## Copies of the source code and the license are available at      ##
##        http://www.versavant.org                                 ##
#####################################################################
#####################################################################

####################################
cvsRevision = "$Revision: 1.3 $" ##
####################################

#######################################################################
## This property class assumes a value type of lists whose items are ##
## strings.  The value type implementation found in                  ##
## versavant/Lib/VTstringList.py can be used.                        ##
#######################################################################

#######################################################
def Add_stringList_PropToOverheadDict( vsv, propertyInstance, overheadDict):
    hashableValue = propertyInstance.hashablePropertyValue = tuple( propertyInstance._value)
    if overheadDict.has_key( hashableValue):
        overheadDict[ hashableValue].append( propertyInstance.proxyId)
    else:
        overheadDict[ hashableValue] = [ propertyInstance.proxyId]


#######################################################
def Remove_stringList_PropFromOverheadDict( vsv, propertyInstance, overheadDict):
    hashableValue = propertyInstance.hashablePropertyValue
    overheadDict[ hashableValue].remove( propertyInstance.proxyId)
    if not len( overheadDict[ hashableValue]):
        del overheadDict[ hashableValue]  ## be a good citizen and clean up after yourself


#######################################################
def Merge_stringList_PropertyValues( vsv, value1, value2):
    if value1 == value2:  ## this actually works, apparently; the two mutable sequences are compared
        return value1
    else:
        return None  ## the merge failed.

#######################################################
def ValuesOf_stringList_PropertyInstancesAreSignificantlyDifferent( vsv, value1, value2):
    if value1 == value2:  ## this actually works, apparently; the two mutable sequences are compared
        return False
    else:
        return True  

#######################################################
def ProxiesOfSubjectIdentifiedBy_stringList_Value( vsv, propertyClass, value):
    if propertyClass.overheadDict.has_key( tuple( value)):
        return propertyClass.overheadDict[ tuple( value)]
    else:
        return []  ## empty list -- no match

#######################################################
def MergeProxiesBecause_stringList_PropertyInstancesSpecifySameSubject( vsv, propertyClass):
    ## Declare this one if and only if your property class is for SIPs
    ## (subject identity properties).
    for hashablePropertyValue in propertyClass.overheadDict:
        if len( propertyClass.overheadDict[ hashablePropertyValue]) > 1:
            vsv.mergeListOfProxies( propertyClass, propertyClass.overheadDict[ hashablePropertyValue])
    
