001/*
002 * nimbus-jose-jwt
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.jose.util;
019
020import net.jcip.annotations.NotThreadSafe;
021
022
023/**
024 * Generic container of items of any type.
025 *
026 * <p>This class is not thread-safe, if thread safety is required it should be
027 * done externally to the class.
028 *
029 * <p>The author believes he borrowed the idea for such a class many years ago
030 * from a man called Boris Karadjov.
031 *
032 * @param <T> the type of the item in this container.
033 *
034 * @author Dimitar A. Stoikov
035 * @version 2016-10-13
036 */
037@NotThreadSafe
038public class Container<T> {
039        
040        
041        /**
042         * The item.
043         */
044        private T item;
045        
046        
047        /**
048         * Creates a new container with no item.
049         */
050        public Container() {
051        }
052        
053        
054        /**
055         * Creates a new container with the specified item.
056         *
057         * @param item The item, may be {@code null}.
058         */
059        public Container(final T item) {
060                this.item = item;
061        }
062        
063        
064        /**
065         * Gets the contained item.
066         *
067         * @return The item, {@code null} if none.
068         */
069        public T get() {
070                return item;
071        }
072        
073        
074        /**
075         * Sets the contained item.
076         *
077         * @param item The item, may be {@code null}.
078         */
079        public void set(final T item) {
080                this.item = item;
081        }
082}