public boolean addLeaf ( final Leaf leaf , final Tree tree ) { if ( leaf == null ) { throw new IllegalArgumentException ( "Null leaves are not allowed" ) ; } if ( leaves == null ) { leaves = new HashMap < Integer , Leaf > ( ) ; leaves . put ( leaf . hashCode ( ) , leaf ) ; return true ; } if ( leaves . containsKey ( leaf . hashCode ( ) ) ) { // if we try to sync a leaf with the same hash of an existing key // but a different TSUID, it's a collision, so mark it if ( ! leaves . get ( leaf . hashCode ( ) ) . getTsuid ( ) . equals ( leaf . getTsuid ( ) ) ) { final Leaf collision = leaves . get ( leaf . hashCode ( ) ) ; if ( tree != null ) { tree . addCollision ( leaf . getTsuid ( ) , collision . getTsuid ( ) ) ; } // log at info or lower since it's not a system error, rather it's // a user issue with the rules or naming schema LOG . warn ( "Incoming TSUID [" + leaf . getTsuid ( ) + "] collided with existing TSUID [" + collision . getTsuid ( ) + "] on display name [" + collision . getDisplayName ( ) + "]" ) ; } return false ; } else { leaves . put ( leaf . hashCode ( ) , leaf ) ; return true ; } }
Adds a leaf to the local branch looking for collisions