001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.camel.language.simple.types;
018    
019    /**
020     * Holder for a token, with associated type and position in the input.
021     */
022    public final class SimpleToken {
023    
024        private final SimpleTokenType type;
025        private final int index;
026        private final int length;
027    
028        public SimpleToken(SimpleTokenType type, int index) {
029            this(type, index, type.getValue() != null ? type.getValue().length() : 0);
030        }
031    
032        public SimpleToken(SimpleTokenType type, int index, int length) {
033            this.type = type;
034            this.index = index;
035            this.length = length;
036        }
037    
038        public SimpleTokenType getType() {
039            return type;
040        }
041    
042        public int getIndex() {
043            return index;
044        }
045    
046        public String getText() {
047            return type.getValue();
048        }
049    
050        public int getLength() {
051            return length;
052        }
053    
054        @Override
055        public String toString() {
056            return type.toString();
057        }
058    }