001package jmri;
002
003import javax.annotation.CheckForNull;
004import javax.annotation.CheckReturnValue;
005
006/**
007 * A reference to an object.
008 * It's a faster replacement for AtomicReference when thread safety is not
009 * needed.
010 *
011 * @param <E> the type of the reference
012 *
013 * @author Daniel Bergqvist Copyright (C) 2021
014 */
015public class Reference<E> {
016
017    private E _ref;
018
019    /**
020     * Create an instance of Reference.
021     */
022    public Reference() {
023    }
024
025    /**
026     * Create an instance of Reference.
027     * @param ref the reference
028     */
029    public Reference(@CheckForNull E ref) {
030        this._ref = ref;
031    }
032
033    /**
034     * Set the reference.
035     * @param ref the new reference
036     */
037    public void set(@CheckForNull E ref) {
038        this._ref = ref;
039    }
040
041    /**
042     * Return the reference.
043     * @return the reference
044     */
045    @CheckReturnValue
046    @CheckForNull
047    public E get() {
048        return _ref;
049    }
050
051}