Option.java revision 953:221a84ef44c0
1179055Sjfv/*
2171384Sjfv * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3205720Sjfv * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4171384Sjfv *
5171384Sjfv * This code is free software; you can redistribute it and/or modify it
6171384Sjfv * under the terms of the GNU General Public License version 2 only, as
7171384Sjfv * published by the Free Software Foundation.  Oracle designates this
8171384Sjfv * particular file as subject to the "Classpath" exception as provided
9171384Sjfv * by Oracle in the LICENSE file that accompanied this code.
10171384Sjfv *
11171384Sjfv * This code is distributed in the hope that it will be useful, but WITHOUT
12171384Sjfv * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13171384Sjfv * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14171384Sjfv * version 2 for more details (a copy is included in the LICENSE file that
15171384Sjfv * accompanied this code).
16171384Sjfv *
17171384Sjfv * You should have received a copy of the GNU General Public License version
18171384Sjfv * 2 along with this work; if not, write to the Free Software Foundation,
19171384Sjfv * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20171384Sjfv *
21171384Sjfv * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22171384Sjfv * or visit www.oracle.com if you need additional information or have any
23171384Sjfv * questions.
24171384Sjfv */
25171384Sjfv
26171384Sjfvpackage jdk.nashorn.internal.runtime.options;
27171384Sjfv
28171384Sjfv/**
29171384Sjfv * This is an option class that at its most primitive level just wraps a
30171384Sjfv * boolean or String. However, it is conceivable that the option, when set
31171384Sjfv * should run some initializations (for example, the logger system) or carry
32179055Sjfv * some other kind of payload, arrays, Collections, etc. In that case, this
33179055Sjfv * should be subclassed
34171384Sjfv *
35171384Sjfv * @param <T> option value type, for example a boolean or something more complex
36171384Sjfv */
37171384Sjfvpublic class Option<T> {
38171384Sjfv    /** the option value */
39171384Sjfv    protected T value;
40171384Sjfv
41171384Sjfv    Option(final T value) {
42172043Sjfv       this.value = value;
43171384Sjfv    }
44171384Sjfv
45171384Sjfv    /**
46205720Sjfv     * Return the value of an option
47171384Sjfv     * @return the option value
48171384Sjfv     */
49171384Sjfv    public T getValue() {
50171384Sjfv        return value;
51171384Sjfv    }
52171384Sjfv
53171384Sjfv    @Override
54179055Sjfv    public String toString() {
55171384Sjfv        return getValue() + " [" + getValue().getClass() + "]";
56171384Sjfv    }
57171384Sjfv}
58171384Sjfv