Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 The Guava Authors
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
   * in compliance with the License. You may obtain a copy of the License 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.
  */
 
 package com.google.common.collect;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.collect.BstModificationResult.ModificationType.REBUILDING_CHANGE;
 import static com.google.common.collect.BstSide.LEFT;
 import static com.google.common.collect.BstSide.RIGHT;
 
 
The result of a mutation operation performed at a single location in a binary search tree.

Parameters:
<K> The key type of the nodes in the modified binary search tree.
<N> The type of the nodes in the modified binary search tree.
Author(s):
Louis Wasserman
 
 final class BstMutationResult<K, N extends BstNode<K, N>> {
  
Creates a BstMutationResult.

Parameters:
targetKey The key targeted for modification. If originalTarget or changedTarget are non-null, their keys must compare as equal to targetKey.
originalRoot The root of the subtree that was modified.
changedRoot The root of the subtree, after the modification and any rebalancing.
modificationResult The result of the local modification to an entry.
 
   public static <K, N extends BstNode<K, N>> BstMutationResult<K, N> mutationResult(
       @Nullable K targetKey, @Nullable N originalRoot, @Nullable N changedRoot,
       BstModificationResult<N> modificationResult) {
     return new BstMutationResult<K, N>(targetKeyoriginalRootchangedRootmodificationResult);
   }
 
   private final K targetKey;
 
   @Nullable
   private N originalRoot;
 
   @Nullable
   private N changedRoot;
   
   private final BstModificationResult<N> modificationResult;
 
   private BstMutationResult(@Nullable K targetKey, @Nullable N originalRoot,
       @Nullable N changedRootBstModificationResult<N> modificationResult) {
     this. = targetKey;
     this. = originalRoot;
     this. = changedRoot;
     this. = checkNotNull(modificationResult);
   }

  
Returns the key which was the target of this modification.
 
   public K getTargetKey() {
     return ;
   }

  
Returns the root of the subtree that was modified.
 
   @Nullable
   public N getOriginalRoot() {
     return ;
   }

  
Returns the root of the subtree, after the modification and any rebalancing was performed.
 
   @Nullable
   public N getChangedRoot() {
     return ;
   }

  
Returns the entry in the original subtree with key targetKey, if any. This should not be treated as a subtree, but only as an entry, and no guarantees are made about its children when viewed as a subtree.
 
   @Nullable
   public N getOriginalTarget() {
  }

  
Returns the result of the modification to getOriginalTarget(). This should not be treated as a subtree, but only as an entry, and no guarantees are made about its children when viewed as a subtree.
  public N getChangedTarget() {
  }
    return .getType();
  }

  
If this mutation was to an immediate child subtree of the specified root on the specified side, returns the BstMutationResult of applying the mutation to the appropriate child of the specified root and rebalancing using the specified mutation rule.
  public BstMutationResult<K, N> lift(N liftOriginalRootBstSide side,
      BstNodeFactory<N> nodeFactoryBstBalancePolicy<N> balancePolicy) {
    assert liftOriginalRoot != null & side != null & nodeFactory != null & balancePolicy != null;
    switch (modificationType()) {
      case :
        this. = this. = liftOriginalRoot;
        return this;
      case :
      case :
        this. = liftOriginalRoot;
        N resultLeft = liftOriginalRoot.childOrNull();
        N resultRight = liftOriginalRoot.childOrNull();
        switch (side) {
          case :
            resultLeft = ;
            break;
          case :
            resultRight = ;
            break;
          default:
            throw new AssertionError();
        }
        if (modificationType() == ) {
          this. = nodeFactory.createNode(liftOriginalRootresultLeftresultRight);
        } else {
          this. =
              balancePolicy.balance(nodeFactoryliftOriginalRootresultLeftresultRight);
        }
        return this;
      default:
        throw new AssertionError();
    }
  }
New to GrepCode? Check out our FAQ X