1/*
2 *******************************************************************************
3 * Copyright (C) 2014, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
6 */
7package com.ibm.icu.text;
8
9import com.ibm.icu.impl.SimpleFilteredSentenceBreakIterator;
10import com.ibm.icu.util.ULocale;
11
12/**
13 * The BreakIteratorFilter is used to modify the behavior of a BreakIterator
14 *  by constructing a new BreakIterator which suppresses certain segment boundaries.
15 *  See  http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions .
16 *  For example, a typical English Sentence Break Iterator would break on the space
17 *  in the string "Mr. Smith" (resulting in two segments),
18 *  but with "Mr." as an exception, a filtered break iterator
19 *  would consider the string "Mr. Smith" to be a single segment.
20 *
21 * <p><b>Note:</b> An instance of {@link BreakIterator} returned by this builder
22 * class currently does not support following operations in this technology preview
23 * version:
24 * <ul>
25 *   <li>{@link BreakIterator#next(int) next(int n)}</li>
26 *   <li>{@link BreakIterator#previous() previous()}</li>
27 *   <li>{@link BreakIterator#following(int) following(int offset)}</li>
28 *   <li>{@link BreakIterator#preceding(int) preceding(int offset)}</li>
29 * </ul>
30 * When one of above methods is called, {@link UnsupportedOperationException} will be
31 * thrown.
32 *
33 * @author tomzhang
34 *
35 * @internal ICU 54 technology preview
36 * @deprecated This API might change or be removed in a future release.
37 */
38@Deprecated
39public abstract class FilteredBreakIteratorBuilder {
40
41    /**
42     * Construct a FilteredBreakIteratorBuilder based on rules in a locale.
43     * The rules are taken from CLDR exception data for the locale,
44     * see http://www.unicode.org/reports/tr35/tr35-general.html#Segmentation_Exceptions
45     * This is the equivalent of calling createInstance(UErrorCode&)
46     * and then repeatedly calling addNoBreakAfter(...) with the contents
47     * of the CLDR exception data.
48     * @param where the locale.
49     * @return the new builder
50     * @internal ICU 54 technology preview
51     * @deprecated This API might change or be removed in a future release.
52     */
53    @Deprecated
54    public static FilteredBreakIteratorBuilder createInstance(ULocale where) {
55        FilteredBreakIteratorBuilder ret = new SimpleFilteredSentenceBreakIterator.Builder(where);
56        return ret;
57    }
58
59    /**
60     * Construct an empty FilteredBreakIteratorBuilder.
61     * In this state, it will not suppress any segment boundaries.
62     * @return the new builder
63     * @internal ICU 54 technology preview
64     * @deprecated This API might change or be removed in a future release.
65     */
66    @Deprecated
67    public static FilteredBreakIteratorBuilder createInstance() {
68        FilteredBreakIteratorBuilder ret = new SimpleFilteredSentenceBreakIterator.Builder();
69        return ret;
70    }
71
72    /**
73     * Suppress a certain string from being the end of a segment.
74     * For example, suppressing "Mr.", then segments ending in "Mr." will not be returned
75     * by the iterator.
76     * @param str the string to suppress, such as "Mr."
77     * @return returns true if the string was not present and now added,
78     * false if the call was a no-op because the string was already being suppressed.
79     * @internal ICU 54 technology preview
80     * @deprecated This API might change or be removed in a future release.
81     */
82    @Deprecated
83    public abstract boolean suppressBreakAfter(String str);
84
85    /**
86     * Stop suppressing a certain string from being the end of the segment.
87     * This function does not create any new segment boundaries, but only serves to un-do
88     * the effect of earlier calls to suppressBreakAfter, or to un-do the effect of
89     * locale data which may be suppressing certain strings.
90     * @param str the str the string to unsuppress, such as "Mr."
91     * @return returns true if the string was present and now removed,
92     * false if the call was a no-op because the string was not being suppressed.
93     * @internal ICU 54 technology preview
94     * @deprecated This API might change or be removed in a future release.
95     */
96    @Deprecated
97    public abstract boolean unsuppressBreakAfter(String str);
98
99    /**
100     * Wrap (adopt) an existing break iterator in a new filtered instance.
101     * The resulting BreakIterator is owned by the caller.
102     * The BreakIteratorFilter may be destroyed before the BreakIterator is destroyed.
103     * Note that the adoptBreakIterator is adopted by the new BreakIterator
104     * and should no longer be used by the caller.
105     * The FilteredBreakIteratorBuilder may be reused.
106     * @param adoptBreakIterator the break iterator to adopt
107     * @return the new BreakIterator, owned by the caller.
108     * @internal ICU 54 technology preview
109     * @deprecated This API might change or be removed in a future release.
110     */
111    @Deprecated
112    public abstract BreakIterator build(BreakIterator adoptBreakIterator);
113
114    /**
115     * For subclass use
116     * @internal ICU 54 technology preview
117     * @deprecated This API might change or be removed in a future release.
118     */
119    @Deprecated
120    protected FilteredBreakIteratorBuilder() {}
121}