|
Lines 10-15
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.runtime.preferences; |
11 |
package org.eclipse.core.runtime.preferences; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.HashSet; |
| 14 |
|
| 13 |
/** |
15 |
/** |
| 14 |
* Class which represents and preference filter entry to be used during preference |
16 |
* Class which represents and preference filter entry to be used during preference |
| 15 |
* import/export (for example). |
17 |
* import/export (for example). |
|
Lines 21-26
Link Here
|
| 21 |
public final class PreferenceFilterEntry { |
23 |
public final class PreferenceFilterEntry { |
| 22 |
|
24 |
|
| 23 |
private String key; |
25 |
private String key; |
|
|
26 |
private HashSet matches; |
| 27 |
private IPreferenceMatcher matcher; |
| 28 |
boolean isRegexp; |
| 24 |
|
29 |
|
| 25 |
/** |
30 |
/** |
| 26 |
* Constructor for the class. Create a new preference filter entry with the given |
31 |
* Constructor for the class. Create a new preference filter entry with the given |
|
Lines 36-41
Link Here
|
| 36 |
} |
41 |
} |
| 37 |
|
42 |
|
| 38 |
/** |
43 |
/** |
|
|
44 |
* Constructor for the class. Create a new preference filter entry with the key, given |
| 45 |
* in the form of regular expression and implementation of {@link IPreferenceMatcher}, |
| 46 |
* used to find preferences with names, which are suitable for this regular expression. |
| 47 |
* The key must <em>not</em> be <code>null</code> or empty. |
| 48 |
* |
| 49 |
* @param key the name of the preference key |
| 50 |
* @param matcher used to find preferences with names, which are suitable for key |
| 51 |
* @see org.eclipse.core.runtime.preferences.IPreferenceMatcher |
| 52 |
* |
| 53 |
* @since 3.6 |
| 54 |
*/ |
| 55 |
public PreferenceFilterEntry(String key, IPreferenceMatcher matcher) { |
| 56 |
super(); |
| 57 |
if (key == null || key.length() == 0) |
| 58 |
throw new IllegalArgumentException(); |
| 59 |
this.key = key; |
| 60 |
this.matcher = matcher; |
| 61 |
if (matcher != null) |
| 62 |
isRegexp = true; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 39 |
* Return the name of the preference key for this filter entry. |
66 |
* Return the name of the preference key for this filter entry. |
| 40 |
* It will <em>not</em> return <code>null</code> or the |
67 |
* It will <em>not</em> return <code>null</code> or the |
| 41 |
* empty string. |
68 |
* empty string. |
|
Lines 45-48
Link Here
|
| 45 |
public String getKey() { |
72 |
public String getKey() { |
| 46 |
return key; |
73 |
return key; |
| 47 |
} |
74 |
} |
|
|
75 |
|
| 76 |
/** |
| 77 |
* Return regular expression flag. |
| 78 |
* |
| 79 |
* @return the regular expression flag |
| 80 |
* |
| 81 |
* @since 3.6 |
| 82 |
*/ |
| 83 |
public boolean isRegexp() { |
| 84 |
return isRegexp; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Adding into collection of preferences names, match the regular expression, |
| 89 |
* which is contained in the <code>key</code>. |
| 90 |
* |
| 91 |
* @param name the name of the preference, matches the regular expression, contained in the key |
| 92 |
* |
| 93 |
* @since 3.6 |
| 94 |
*/ |
| 95 |
public void addMatch(String name) { |
| 96 |
if (!isRegexp) |
| 97 |
return; |
| 98 |
if (matches == null) |
| 99 |
matches = new HashSet(); |
| 100 |
if (matcher.find(key, name)) |
| 101 |
matches.add(name); |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Return the array of preferences' names, matches the regular expression, contained in the key |
| 106 |
* |
| 107 |
* @return the array of the preferencs' names, matches the regular expression, contained in the key |
| 108 |
* |
| 109 |
* @since 3.6 |
| 110 |
*/ |
| 111 |
public Object[] getMatches() { |
| 112 |
if (!isRegexp || matches == null || matches.size() == 0) |
| 113 |
return null; |
| 114 |
return matches.toArray(); |
| 115 |
} |
| 116 |
|
| 48 |
} |
117 |
} |