1 package org.apache.lucene.util.fst;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
22 import org.apache.lucene.store.DataInput;
23 import org.apache.lucene.store.DataOutput;
26 * Represents the outputs for an FST, providing the basic
27 * algebra needed for the FST.
29 * @lucene.experimental
32 public abstract class Outputs<T> {
34 // TODO: maybe change this API to allow for re-use of the
35 // output instances -- this is an insane amount of garbage
36 // (new object per byte/char/int) if eg used during
39 /** Eg common("foo", "foobar") -> "foo" */
40 public abstract T common(T output1, T output2);
42 /** Eg subtract("foobar", "foo") -> "bar" */
43 public abstract T subtract(T output, T inc);
45 /** Eg add("foo", "bar") -> "foobar" */
46 public abstract T add(T prefix, T output);
48 public abstract void write(T output, DataOutput out) throws IOException;
50 public abstract T read(DataInput in) throws IOException;
52 /** NOTE: this output is compared with == so you must
53 * ensure that all methods return the single object if
54 * it's really no output */
55 public abstract T getNoOutput();
57 public abstract String outputToString(T output);
59 public T merge(T first, T second) {
60 throw new UnsupportedOperationException();