1/*
2 * Copyright (C) 2011 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied. See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15package com.google.common.collect;
16
17import static com.google.common.base.Preconditions.checkNotNull;
18
19import com.google.common.annotations.GwtCompatible;
20
21import javax.annotation.Nullable;
22
23/**
24 * The result of a {@code BstModifier}.
25 *
26 * @author Louis Wasserman
27 */
28@GwtCompatible
29final class BstModificationResult<N extends BstNode<?, N>> {
30  enum ModificationType {
31    IDENTITY, REBUILDING_CHANGE, REBALANCING_CHANGE;
32  }
33
34  static <N extends BstNode<?, N>> BstModificationResult<N> identity(@Nullable N target) {
35    return new BstModificationResult<N>(target, target, ModificationType.IDENTITY);
36  }
37
38  static <N extends BstNode<?, N>> BstModificationResult<N> rebuildingChange(
39      @Nullable N originalTarget, @Nullable N changedTarget) {
40    return new BstModificationResult<N>(
41        originalTarget, changedTarget, ModificationType.REBUILDING_CHANGE);
42  }
43
44  static <N extends BstNode<?, N>> BstModificationResult<N> rebalancingChange(
45      @Nullable N originalTarget, @Nullable N changedTarget) {
46    return new BstModificationResult<N>(
47        originalTarget, changedTarget, ModificationType.REBALANCING_CHANGE);
48  }
49
50  @Nullable private final N originalTarget;
51  @Nullable private final N changedTarget;
52  private final ModificationType type;
53
54  private BstModificationResult(
55      @Nullable N originalTarget, @Nullable N changedTarget, ModificationType type) {
56    this.originalTarget = originalTarget;
57    this.changedTarget = changedTarget;
58    this.type = checkNotNull(type);
59  }
60
61  @Nullable
62  N getOriginalTarget() {
63    return originalTarget;
64  }
65
66  @Nullable
67  N getChangedTarget() {
68    return changedTarget;
69  }
70
71  ModificationType getType() {
72    return type;
73  }
74}
75