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.schema;
23 
24 import org.apache.openoffice.ooxml.schema.automaton.HopcroftMinimizer;
25 import org.apache.openoffice.ooxml.schema.automaton.State;
26 import org.apache.openoffice.ooxml.schema.automaton.StateContainer;
27 import org.apache.openoffice.ooxml.schema.automaton.StateContext;
28 import org.apache.openoffice.ooxml.schema.automaton.Transition;
29 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
30 
31 /** A simple test of the minimization algorithm for DFAs.
32  *
33  *  May lead to the use of a testing framework in the future.
34  */
35 public class Test
36 {
main(final String ... aArgumentList)37     public static void main (final String ... aArgumentList)
38     {
39         new Test("S", new String[]{"E"}, new String[][]{
40             {"S", "A", "a"},
41             {"A", "B", "b"},
42             {"A", "C", "b"},
43             {"B", "E", "c"},
44             {"C", "E", "c"},
45         });
46     }
Test( final String sStartState, final String[] aAcceptingStates, final String[][] aTransitions)47     private Test (
48         final String sStartState,
49         final String[] aAcceptingStates,
50         final String[][] aTransitions)
51     {
52         final StateContainer aOriginalStateContainer = new StateContainer();
53         final StateContext aStates = new StateContext(
54             aOriginalStateContainer,
55             sStartState);
56         for (final String sAcceptingState : aAcceptingStates)
57         {
58             final State s = aStates.CreateState(sAcceptingState);
59             s.SetIsAccepting();
60         }
61         for (final String[] aTransition : aTransitions)
62         {
63             final State start = aStates.GetOrCreateState(
64                 new QualifiedName(aTransition[0]),
65                 null);
66             final State end = aStates.GetOrCreateState(
67                 new QualifiedName(aTransition[1]),
68                 null);
69             final QualifiedName element = new QualifiedName(aTransition[2]);
70             final String type = "T_"+aTransition[2];
71 
72             start.AddTransition(new Transition(start, end, element, type));
73         }
74         HopcroftMinimizer.MinimizeDFA (
75             new StateContainer(),
76             aStates,
77             null,
78             null,
79             System.out);
80     }
81 }
82