001/*
002 * This file is part of OCaml-Java runtime.
003 * Copyright (C) 2007-2013 Xavier Clerc.
004 *
005 * OCaml-Java runtime is free software; you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation; either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * OCaml-Java runtime is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.ocamljava.runtime.wrappers;
020
021import org.ocamljava.runtime.values.Value;
022
023/**
024 * The {@code OCamlUnit} class is the wrapper class for OCaml values of
025 * type {@code unit}.
026 *
027 * @author <a href="mailto:xclerc@ocamljava.org">Xavier Clerc</a>
028 * @version 2.0
029 * @since 2.0
030 */
031public final class OCamlUnit extends OCamlValue {
032
033    /** Wrapper for {@code OCamlUnit} values. */
034    public static final Wrapper<OCamlUnit> WRAPPER = new SimpleWrapper<OCamlUnit>() {
035
036        /**
037         * {@inheritDoc}
038         */
039        @Override
040        public OCamlUnit wrap(final Value v) {
041            return new OCamlUnit();
042        } // end method 'wrap(Value)'
043
044    }; // end anonymous inner-class
045
046    /** An representation of {@code OCamlUnit}, all instances being equal. */
047    public static final OCamlUnit INSTANCE = new OCamlUnit();
048
049    /**
050     * Constructs a new instance wrapping the passed value.
051     */
052    private OCamlUnit() {
053        super(Value.UNIT);
054    } // end constructor()
055
056    /**
057     * {@inheritDoc}
058     */
059    @Override
060    public Wrapper<? extends OCamlUnit> getWrapper() {
061        return OCamlUnit.WRAPPER;
062    } // end method 'getWrapper()'
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public Wrapper<? extends OCamlValue> getWrapper(final int idx) {
069        return OCamlUnit.WRAPPER;
070    } // end method 'getWrapper(int)'
071
072    /**
073     * {@inheritDoc}
074     */
075    @Override
076    public int hashCode() {
077        return 0;
078    } // end method 'hashCode()'
079
080    /**
081     * {@inheritDoc}
082     */
083    @Override
084    public boolean equals(final Object obj) {
085        return (obj instanceof OCamlUnit);
086    } // end method 'equals(Object)'
087
088    /**
089     * {@inheritDoc}
090     */
091    @Override
092    public String toString() {
093        return "OCamlUnit()";
094    } // end method 'toString()'
095
096    /**
097     * Constructs a new {@code unit} value, and wraps it.
098     * @return a new {@code OCamlUnit} instance wrapping the passed value
099     */
100    public static OCamlUnit create() {
101        return OCamlUnit.INSTANCE;
102    } // end method 'create()'
103
104    /**
105     * Wraps the passed value.
106     * @param v ignored
107     * @return a new {@code OCamlUnit} instance wrapping the passed value
108     */
109    public static OCamlUnit wrap(final Value v) {
110        assert v != null : "null v";
111        return OCamlUnit.INSTANCE;
112    } // end method 'wrap(Value)'
113
114    /**
115     * Returns a wrapper for {@code OCamlUnit} values.
116     * @return a wrapper for {@code OCamlUnit} values
117     */
118    public static Wrapper<? extends OCamlUnit> wrapper() {
119        return OCamlUnit.WRAPPER;
120    } // end method 'wrapper()'
121
122} // end class 'OCamlUnit'