1 package com.atlassian.user.search.query;
2
3 import com.atlassian.user.repository.RepositoryIdentifier;
4
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Collections;
8 import java.util.List;
9
10 public final class DefaultQueryContext implements QueryContext
11 {
12 private final List<String> repositoryKeys;
13
14
15
16
17
18
19
20 public DefaultQueryContext()
21 {
22 repositoryKeys = new ArrayList<String>();
23 }
24
25
26
27
28
29
30 public DefaultQueryContext(RepositoryIdentifier... repositories)
31 {
32 List<String> keys = new ArrayList<String>(repositories.length);
33 for (RepositoryIdentifier repository : repositories)
34 keys.add(repository.getKey());
35 repositoryKeys = Collections.unmodifiableList(keys);
36 }
37
38
39
40
41
42
43 public DefaultQueryContext(String... repositoryKeys)
44 {
45 this.repositoryKeys = Collections.unmodifiableList(Arrays.asList(repositoryKeys));
46 }
47
48
49 public void addRepositoryKey(String key) throws IllegalArgumentException
50 {
51 if (repositoryKeys.contains(key) || repositoryKeys.contains(QueryContext.ALL_REPOSITORIES))
52 throw new IllegalArgumentException("Repository key [" + key + " is already listed in this query context.");
53
54 repositoryKeys.add(key);
55 }
56
57
58 public List<String> getRepositoryKeys()
59 {
60 return Collections.unmodifiableList(repositoryKeys);
61 }
62
63 public boolean contains(RepositoryIdentifier repositoryIdentifier)
64 {
65
66 if (getRepositoryKeys().contains(QueryContext.ALL_REPOSITORIES))
67 return true;
68 return getRepositoryKeys().contains(repositoryIdentifier.getKey());
69 }
70 }