1/* 2 * Copyright (C) 2010 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.google.streamhtmlparser.impl; 18 19import com.google.common.base.Preconditions; 20 21/** 22 * Holds one state transition as derived from a Python configuration 23 * file. A state transition is a triplet as follows: 24 * <ul> 25 * <li>An expression which consists of one or more characters and/or 26 * one or more range of characters. 27 * <li> A source state. 28 * <li> A destination state. 29 * </ul> 30 * 31 * <p>For example, the triplet ("a-z123", A, B) will cause the 32 * state to go from A to B for any character that is either 1,2,3 or in 33 * the range a-z inclusive. 34 */ 35class StateTableTransition { 36 37 private final String expression; 38 private final InternalState from; 39 private final InternalState to; 40 41 /** 42 * Returns the full state of the {@code StateTableTransition} in a 43 * human readable form. The format of the returned {@code String} is not 44 * specified and is subject to change. 45 * 46 * @return full state of the {@code StateTableTransition} 47 */ 48 @Override 49 public String toString() { 50 return String.format("Expression: %s; From: %s; To: %s", 51 expression, from, to); 52 } 53 54 StateTableTransition(String expression, InternalState from, 55 InternalState to) { 56 // Developer error if any triggers. 57 Preconditions.checkNotNull(expression); 58 Preconditions.checkNotNull(from); 59 Preconditions.checkNotNull(to); 60 this.expression = expression; 61 this.from = from; 62 this.to = to; 63 } 64 65 String getExpression() { 66 return expression; 67 } 68 69 InternalState getFrom() { 70 return from; 71 } 72 73 InternalState getTo() { 74 return to; 75 } 76} 77