001/*
002 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
003 *
004 * Based in London, we are world leaders in the design and development
005 * of bespoke applications for the securities financing markets.
006 *
007 * <a href="http://www.objectlab.co.uk/open">Click here to learn more</a>
008 *           ___  _     _           _   _          _
009 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
010 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
011 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
012 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
013 *                   |__/
014 *
015 *                     www.ObjectLab.co.uk
016 *
017 * $Id$
018 *
019 * Copyright 2006 the original author or authors.
020 *
021 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
022 * use this file except in compliance with the License. You may obtain a copy of
023 * the License at
024 *
025 * http://www.apache.org/licenses/LICENSE-2.0
026 *
027 * Unless required by applicable law or agreed to in writing, software
028 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
029 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
030 * License for the specific language governing permissions and limitations under
031 * the License.
032 */
033package net.objectlab.kit.datecalc.common;
034
035/**
036 * enum of Tenor Codes held by a {@link Tenor}
037 *
038 * @author Benoit Xhenseval
039 *
040 */
041public enum TenorCode {
042    OVERNIGHT("ON", false),
043    SPOT("SP", false),
044    TOM_NEXT("TN", false),
045    SPOT_NEXT("SN", false),
046    DAY("D", true),
047    WEEK("W", true),
048    MONTH("M", true),
049    YEAR("Y", true);
050
051    private final String code;
052
053    private final boolean acceptUnits;
054
055    private TenorCode(final String code, final boolean acceptUnits) {
056        this.code = code;
057        this.acceptUnits = acceptUnits;
058    }
059
060    // -----------------------------------------------------------------------
061    //
062    // ObjectLab, world leaders in the design and development of bespoke
063    // applications for the securities financing markets.
064    // www.ObjectLab.co.uk
065    //
066    // -----------------------------------------------------------------------
067
068    /**
069     * @return the string representation of this <code>TenorCode</code>
070     */
071    public String getCode() {
072        return code;
073    }
074
075    /**
076     * @param code
077     *            string representation of the <code>TenorCode</code>
078     * @return a <code>TenorCode</code> represented by the string argument
079     */
080    public static TenorCode fromCode(final String code) {
081        for (final TenorCode ct : TenorCode.values()) {
082            if (ct.getCode().equals(code)) {
083                return ct;
084            }
085        }
086        return null;
087    }
088
089    /**
090     * @return true if the TenorCode can have units e.g. 1 Day, 3 Week but not 6 OVERNIGHT or 5 SPOT/SP
091     */
092    public boolean acceptUnits() {
093        return acceptUnits;
094    }
095}
096
097/*
098 * ObjectLab, http://www.objectlab.co.uk/open is sponsoring the ObjectLab Kit.
099 *
100 * Based in London, we are world leaders in the design and development
101 * of bespoke applications for the securities financing markets.
102 *
103 * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a>
104 *           ___  _     _           _   _          _
105 *          / _ \| |__ (_) ___  ___| |_| |    __ _| |__
106 *         | | | | '_ \| |/ _ \/ __| __| |   / _` | '_ \
107 *         | |_| | |_) | |  __/ (__| |_| |__| (_| | |_) |
108 *          \___/|_.__// |\___|\___|\__|_____\__,_|_.__/
109 *                   |__/
110 *
111 *                     www.ObjectLab.co.uk
112 */