Skip to content

Commit 1bdcc2c

Browse files
author
Mike Davis
committed
Update doc string.
1 parent 3c48148 commit 1bdcc2c

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

core-api/src/main/java/com/optimizely/ab/config/audience/match/MatchRegistry.java

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
1+
/**
2+
*
3+
* Copyright 2020, Optimizely and contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* 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+
*/
117
package com.optimizely.ab.config.audience.match;
218

319
import java.util.Map;
420
import java.util.concurrent.ConcurrentHashMap;
521

22+
/**
23+
* MatchRegistry maps a string match "type" to a match implementation.
24+
* All supported Match implementations must be registed with this registry.
25+
* Third-party {@link Match} implementations may also be registered to provide
26+
* additional functionality.
27+
*/
628
public class MatchRegistry {
729

830
private static final Map<String, Match> registry = new ConcurrentHashMap<>();
9-
private static final String EXISTS = "exists";
10-
private static final String EXACT = "exact";
11-
private static final String GREATER_THAN = "gt";
12-
private static final String LESS_THAN = "lt";
13-
private static final String SUBSTRING = "substring";
14-
private static final Match LEGACY = new DefaultMatchForLegacyAttributes();
31+
public static final String EXISTS = "exists";
32+
public static final String EXACT = "exact";
33+
public static final String GREATER_THAN = "gt";
34+
public static final String LESS_THAN = "lt";
35+
public static final String SUBSTRING = "substring";
36+
public static final String LEGACY = "legacy";
1537

1638
static {
17-
registry.put(EXISTS, new ExistsMatch());
18-
registry.put(EXACT, new ExactMatch());
19-
registry.put(GREATER_THAN, new GTMatch());
20-
registry.put(LESS_THAN, new LTMatch());
21-
registry.put(SUBSTRING, new SubstringMatch());
39+
register(EXISTS, new ExistsMatch());
40+
register(EXACT, new ExactMatch());
41+
register(GREATER_THAN, new GTMatch());
42+
register(LESS_THAN, new LTMatch());
43+
register(SUBSTRING, new SubstringMatch());
44+
register(LEGACY, new DefaultMatchForLegacyAttributes());
2245
}
2346

2447
// TODO rename Match to Matcher
2548
public static Match getMatch(String name) throws UnknownMatchTypeException {
26-
if (name == null) {
27-
return LEGACY;
28-
}
29-
30-
Match match = registry.get(name);
49+
Match match = registry.get(name == null ? LEGACY : name);
3150
if (match == null) {
3251
throw new UnknownMatchTypeException();
3352
}
3453

3554
return match;
3655
}
3756

57+
/**
58+
* register registers a Match implementation with it's name.
59+
* NOTE: This does not check for existence so default implementations can
60+
* be overridden.
61+
* @param name
62+
* @param match
63+
*/
3864
public static void register(String name, Match match) {
3965
registry.put(name, match);
4066
}

0 commit comments

Comments
 (0)