add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / analyzers / common / src / java / org / apache / lucene / analysis / compound / hyphenation / Hyphen.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.apache.lucene.analysis.compound.hyphenation;
19
20 import java.io.Serializable;
21
22 /**
23  * This class represents a hyphen. A 'full' hyphen is made of 3 parts: the
24  * pre-break text, post-break text and no-break. If no line-break is generated
25  * at this position, the no-break text is used, otherwise, pre-break and
26  * post-break are used. Typically, pre-break is equal to the hyphen character
27  * and the others are empty. However, this general scheme allows support for
28  * cases in some languages where words change spelling if they're split across
29  * lines, like german's 'backen' which hyphenates 'bak-ken'. BTW, this comes
30  * from TeX.
31  * 
32  * This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified. 
33  */
34
35 public class Hyphen implements Serializable {
36   public String preBreak;
37
38   public String noBreak;
39
40   public String postBreak;
41
42   Hyphen(String pre, String no, String post) {
43     preBreak = pre;
44     noBreak = no;
45     postBreak = post;
46   }
47
48   Hyphen(String pre) {
49     preBreak = pre;
50     noBreak = null;
51     postBreak = null;
52   }
53
54   @Override
55   public String toString() {
56     if (noBreak == null && postBreak == null && preBreak != null
57         && preBreak.equals("-")) {
58       return "-";
59     }
60     StringBuilder res = new StringBuilder("{");
61     res.append(preBreak);
62     res.append("}{");
63     res.append(postBreak);
64     res.append("}{");
65     res.append(noBreak);
66     res.append('}');
67     return res.toString();
68   }
69
70 }