1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package org.apache.openoffice.ooxml.parser; 23 24 import java.util.HashMap; 25 import java.util.Map; 26 import java.util.Vector; 27 28 public class TransitionTable 29 { TransitionTable(final Vector<String[]> aData)30 public TransitionTable (final Vector<String[]> aData) 31 { 32 maTransitions = new HashMap<>(); 33 34 for (final String[] aLine : aData) 35 { 36 // Create new transition. 37 final int nStartStateId = Integer.parseInt(aLine[1]); 38 final int nEndStateId = Integer.parseInt(aLine[2]); 39 final int nElementPrefixId = Integer.parseInt(aLine[3]); 40 final int nElementLocalId = Integer.parseInt(aLine[4]); 41 final int nElementStateId = Integer.parseInt(aLine[5]); 42 final Transition aTransition = new Transition( 43 nStartStateId, 44 nEndStateId, 45 (nElementPrefixId<<16) | nElementLocalId, 46 nElementStateId); 47 48 Map<Integer,Transition> aPerElementTransitions = maTransitions.get(aTransition.GetStartStateId()); 49 if (aPerElementTransitions == null) 50 { 51 aPerElementTransitions = new HashMap<>(); 52 maTransitions.put(aTransition.GetStartStateId(), aPerElementTransitions); 53 } 54 aPerElementTransitions.put(aTransition.GetElementId(), aTransition); 55 } 56 } 57 58 59 60 GetTransition( final int nStateId, final int nPrefixId, final int nLocalId)61 public Transition GetTransition ( 62 final int nStateId, 63 final int nPrefixId, 64 final int nLocalId) 65 { 66 Map<Integer,Transition> aPerElementTransitions = maTransitions.get(nStateId); 67 if (aPerElementTransitions == null) 68 return null; 69 else 70 return aPerElementTransitions.get((nPrefixId<<16) | nLocalId); 71 } 72 73 74 75 GetTransitionCount()76 public int GetTransitionCount () 77 { 78 return maTransitions.size(); 79 } 80 81 82 83 84 private final Map<Integer,Map<Integer,Transition>> maTransitions; 85 } 86