Package com.google.enterprise.connector.util.diffing

Source Code of com.google.enterprise.connector.util.diffing.TraversalContextManager

// Copyright 2010 Google Inc.
//
// 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.enterprise.connector.util.diffing;

import com.google.common.base.Preconditions;
import com.google.enterprise.connector.spi.TraversalContext;

import java.util.concurrent.atomic.AtomicReference;

/**
* Holder for the {@link TraversalContext}.
*
* @since 2.8
*/
public class TraversalContextManager {
  private final AtomicReference<TraversalContext> traversalContext =
      new AtomicReference<TraversalContext>();

  /**
   * Sets the {@link TraversalContext}.
   *
   * @param traversalContext the {@link TraversalContext} to hold - must not be
   *        {@code null}
   */
  public void setTraversalContext(TraversalContext traversalContext) {
    Preconditions.checkNotNull(traversalContext,
                               "traversalContext must not be null.");
    this.traversalContext.set(traversalContext);
  }

  /**
   * @return the {@link TraversalContext}
   */
  public TraversalContext getTraversalContext() {
    TraversalContext result = traversalContext.get();
    Preconditions.checkState((result != null),
                             "setTraversalContext has not been called.");
    return result;
  }
}
TOP

Related Classes of com.google.enterprise.connector.util.diffing.TraversalContextManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.