001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.modeshape.common.collection.ring;
018
019import java.util.concurrent.atomic.AtomicLong;
020
021/**
022 * A sequence of long values that are updated atomically.
023 * 
024 * @author Randall Hauch (rhauch@redhat.com)
025 */
026public class Pointer {
027
028    public static long INITIAL_VALUE = -1L;
029
030    private final AtomicLong value;
031
032    public Pointer() {
033        value = new AtomicLong(INITIAL_VALUE);
034    }
035
036    public Pointer( long initialValue ) {
037        value = new AtomicLong(initialValue);
038    }
039
040    public long get() {
041        return value.get();
042    }
043
044    public void set( long newValue ) {
045        this.value.set(newValue);
046    }
047
048    public long incrementAndGet() {
049        return this.value.incrementAndGet();
050    }
051
052    @Override
053    public String toString() {
054        return super.toString() + "=" + value.get();
055    }
056
057}