1 23 package com.tc.jrexx.regex; 24 25 import com.tc.jrexx.set.*; 26 27 import java.util.*; 28 import java.io.*; 29 30 public class PAutomaton extends SAutomaton { 31 private static final HashMap AUTOMATON_MAP = new HashMap(); 32 33 protected PAutomaton(Automaton_Pattern automaton) { 34 super(automaton); 35 } 36 37 protected AutomatonSet_String getAutomaton() { 38 return this.automaton; 39 } 40 41 public PAutomaton() { 42 super(new Automaton_Pattern()); 43 } 44 45 public PAutomaton(String regEx) { 46 super(new Automaton_Pattern(regEx)); 47 } 48 49 public PAutomaton(FSAData data) { 50 super(new Automaton_Pattern()); 51 this.init(data); 52 } 53 54 public PAutomaton(InputStream automatonDataStream) throws java.io.IOException ,ClassNotFoundException { 55 super(new Automaton_Pattern()); 56 this.init(toFSAData(new ObjectInputStream(automatonDataStream).readObject())); 58 try { 59 ObjectInputStream oin = new ObjectInputStream( automatonDataStream) { 60 70 protected void readStreamHeader() 71 throws IOException, StreamCorruptedException 72 { 73 short incoming_magic = 0; 74 short incoming_version = 0; 75 incoming_magic = readShort(); 77 incoming_version = readShort(); 78 if (incoming_magic != STREAM_MAGIC) 83 throw new StreamCorruptedException("InputStream does not contain a serialized object"); 84 85 if (incoming_version != STREAM_VERSION) 86 throw new StreamCorruptedException("Version Mismatch, Expected " + 87 STREAM_VERSION + " and got " + 88 incoming_version); 89 } 90 }; 91 ((Automaton_Pattern)this.automaton).regEx = (String )oin.readObject(); 92 } catch(EOFException e) { 93 94 } 95 } 96 97 100 public void toData(OutputStream automatonDataStream) throws IOException { 101 super.toData(automatonDataStream); 102 ObjectOutputStream oOut = new ObjectOutputStream(automatonDataStream) { 103 111 protected void writeStreamHeader() throws IOException { 112 writeShort(STREAM_MAGIC); 113 writeShort(STREAM_VERSION); 114 } 115 }; 116 117 oOut.writeObject(this.getRegEx()); 118 } 119 120 public void addAll(String regEx) { 121 ((Automaton_Pattern)this.automaton).addAll(regEx); 122 } 123 124 public void retainAll(String regEx) { 125 ((Automaton_Pattern)this.automaton).retainAll(regEx); 126 } 127 128 public void removeAll(String regEx) { 129 ((Automaton_Pattern)this.automaton).removeAll(regEx); 130 } 131 132 public String getRegEx() { 133 return ((Automaton_Pattern)this.automaton ).regEx; 134 } 135 } | Popular Tags |