View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.index.treeview;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.maven.index.ArtifactInfoFilter;
25  import org.apache.maven.index.Field;
26  import org.apache.maven.index.MAVEN;
27  import org.apache.maven.index.context.IndexingContext;
28  
29  public class TreeViewRequest {
30      private final TreeNodeFactory factory;
31  
32      private final String path;
33  
34      private final ArtifactInfoFilter artifactInfoFilter;
35  
36      private final Map<Field, String> fieldHints;
37  
38      private final IndexingContext indexingContext;
39  
40      public TreeViewRequest(final TreeNodeFactory factory, final String path, final IndexingContext ctx) {
41          this(factory, path, null, null, ctx);
42      }
43  
44      public TreeViewRequest(
45              final TreeNodeFactory factory,
46              final String path,
47              final Map<Field, String> hints,
48              final ArtifactInfoFilter artifactInfoFilter,
49              final IndexingContext ctx) {
50          this.factory = factory;
51  
52          this.path = path;
53  
54          this.fieldHints = new HashMap<>();
55  
56          if (hints != null && hints.size() != 0) {
57              this.fieldHints.putAll(hints);
58          }
59  
60          this.artifactInfoFilter = artifactInfoFilter;
61  
62          this.indexingContext = ctx;
63      }
64  
65      public TreeNodeFactory getFactory() {
66          return factory;
67      }
68  
69      public String getPath() {
70          return path;
71      }
72  
73      public ArtifactInfoFilter getArtifactInfoFilter() {
74          return artifactInfoFilter;
75      }
76  
77      public void addFieldHint(Field field, String hint) {
78          fieldHints.put(field, hint);
79      }
80  
81      public void removeFieldHint(Field field) {
82          fieldHints.remove(field);
83      }
84  
85      public boolean hasFieldHints() {
86          return fieldHints.size() > 0 && (hasFieldHint(MAVEN.GROUP_ID));
87      }
88  
89      public boolean hasFieldHint(Field... fields) {
90          for (Field f : fields) {
91              if (!fieldHints.containsKey(f)) {
92                  return false;
93              }
94          }
95  
96          return true;
97      }
98  
99      public String getFieldHint(Field field) {
100         return fieldHints.get(field);
101     }
102 
103     public Map<Field, String> getFieldHints() {
104         return fieldHints;
105     }
106 
107     public IndexingContext getIndexingContext() {
108         return indexingContext;
109     }
110 }