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 AsbtractWrapper} class provides a partial implementation 025 * for the {@code Wrapper} interface, by taking the elements to be 026 * returned by the {@code getWrapper(int)} method as constructor 027 * parameters. 028 * 029 * @author <a href="mailto:xclerc@ocamljava.org">Xavier Clerc</a> 030 * @version 2.0 031 * @since 2.0 032 */ 033public abstract class ComposedWrapper<T extends OCamlValue> implements Wrapper<T>{ 034 035 /** 036 * Elements to be returned by the {@code getWrapper(int)} method. 037 */ 038 private final Wrapper<? extends OCamlValue>[] wrappers; 039 040 /** 041 * Constructs a new instance. 042 * @param wrappers elements to be returned by the {@code getWrapper(int)} 043 * method 044 */ 045 @SuppressWarnings("unchecked") 046 public ComposedWrapper(final Wrapper<? extends OCamlValue>... wrappers) { 047 this.wrappers = wrappers; 048 } // end constructor(Wrapper<? extends OCamlValue>) 049 050 /** 051 * {@inheritDoc} 052 */ 053 @Override 054 public final Wrapper<? extends OCamlValue> getWrapper(final int idx) { 055 if (idx < this.wrappers.length) { 056 return this.wrappers[idx]; 057 } else { 058 return OCamlUnit.WRAPPER; 059 } // end if/else 060 } // end method 'getWrapper(int)' 061 062} // end class 'ComposedWrapper'