1 /*******************************************************************************
2  * Copyright (c) 2010, 2017 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.equinox.internal.p2.updatesite;
15 
16 import java.util.ArrayList;
17 import java.util.List;
18 
19 public class SiteIU {
20 
21 	public static final String QUERY_TYPE_CONTEXT = "context"; //$NON-NLS-1$
22 	public static final String QUERY_TYPE_MATCH = "match"; //$NON-NLS-1$
23 
24 	private String id = null;
25 	private String range = null;
26 	private String queryExpression = null;
27 	private String queryType = null;
28 	private List<String> queryParams = null;
29 	private List<String> categoryNames = null;
30 
31 	/**
32 	 * Returns the id of the IU
33 	 * @return the id of the IU
34 	 */
getID()35 	public String getID() {
36 		return id;
37 	}
38 
39 	/**
40 	 * Returns the range of the IU
41 	 * @return the range of the IU
42 	 */
getRange()43 	public String getRange() {
44 		return range;
45 	}
46 
47 	/**
48 	 * Returns the query expression for the IU.
49 	 *
50 	 * @return query expression
51 	 */
getQueryExpression()52 	public String getQueryExpression() {
53 		return queryExpression;
54 	}
55 
56 	/**
57 	 * Returns the query type for the IU.
58 	 *
59 	 * @return the query type
60 	 */
getQueryType()61 	public String getQueryType() {
62 		return queryType;
63 	}
64 
65 	/**
66 	 * Returns the params for the query expression for the IU
67 	 *
68 	 * @return an array of query params.
69 	 */
getQueryParams()70 	public String[] getQueryParams() {
71 		if (queryParams == null)
72 			return new String[0];
73 
74 		return queryParams.toArray(new String[0]);
75 	}
76 
77 	/**
78 	 * Returns the names of categories the referenced IU belongs to.
79 	 *
80 	 * @return an array of names, or an empty array.
81 	 */
getCategoryNames()82 	public String[] getCategoryNames() {
83 		if (categoryNames == null)
84 			return new String[0];
85 
86 		return categoryNames.toArray(new String[0]);
87 	}
88 
89 	/**
90 	 * Sets the id for the IU.
91 	 * @param id the id
92 	 */
setID(String id)93 	public void setID(String id) {
94 		this.id = id;
95 	}
96 
97 	/**
98 	 * Sets the range for the IU.
99 	 * @param range the range
100 	 */
setRange(String range)101 	public void setRange(String range) {
102 		this.range = range;
103 	}
104 
105 	/**
106 	 * Sets the query expression for the IU.
107 	 *
108 	 * @param queryExpression query expression
109 	 */
setQueryExpression(String queryExpression)110 	public void setQueryExpression(String queryExpression) {
111 		this.queryExpression = queryExpression;
112 	}
113 
114 	/**
115 	 * Sets the query type for the IU.
116 	 *
117 	 * @param queryType the query type
118 	 */
setQueryType(String queryType)119 	public void setQueryType(String queryType) {
120 		this.queryType = queryType;
121 	}
122 
123 	/**
124 	 * Adds the name of a category this IU belongs to.
125 	 *
126 	 * @param categoryName category name
127 	 */
addCategoryName(String categoryName)128 	public void addCategoryName(String categoryName) {
129 		if (this.categoryNames == null)
130 			this.categoryNames = new ArrayList<>();
131 		if (!this.categoryNames.contains(categoryName))
132 			this.categoryNames.add(categoryName);
133 	}
134 
135 	/**
136 	 * Adds a param for the query expression for this IU.
137 	 *
138 	 * @param queryParam a query param.
139 	 */
addQueryParams(String queryParam)140 	public void addQueryParams(String queryParam) {
141 		if (this.queryParams == null)
142 			this.queryParams = new ArrayList<>();
143 		// don't do contains check, order matters and there may be duplicates
144 		this.queryParams.add(queryParam);
145 	}
146 }
147