001/**
002 * Copyright (c) 2012, 2014, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016package org.javamoney.moneta.internal.format;
017
018import java.io.IOException;
019
020import javax.money.MonetaryAmount;
021import javax.money.format.MonetaryParseException;
022
023/**
024 * Abstraction for a token that is part of a token stream, used for formatting
025 * and parsing.
026 * 
027 * @author Anatole Tresch
028 */
029public interface FormatToken {
030        /**
031         * Parse the context, based on the given {@link ParseContext}.
032         * 
033         * @param context
034         *            the current {@link ParseContext}.
035         * @throws MonetaryParseException
036         *             if parsing fails.
037         */
038        public void parse(ParseContext context) throws MonetaryParseException;
039
040        /**
041         * Formats the given {@link javax.money.MonetaryAmount} to an {@link Appendable}.
042         * @param appendable the {@link Appendable}, not {@code null}.
043         * @param amount the {@link MonetaryAmount} to be formatted, not {@code null}.
044         * @throws IOException thrown by the {@link Appendable} on appending.
045         */
046        public void print(Appendable appendable, MonetaryAmount amount)
047                        throws IOException;
048
049}