Skip to main content
summaryrefslogtreecommitdiffstats
blob: 66eafd00d80630f77ca770bb1156cc471782b26d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************************************
 * Copyright (c) 2010, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.help.internal.base.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.help.ICriteria;
import org.eclipse.help.internal.criteria.CriterionResource;

public class CriteriaUtilities {

    public static List<String> getCriteriaValues(String rawValues) {
    	List<String> result = new ArrayList<String>();
    	if (rawValues != null) {
    		String[] values = rawValues.split(","); //$NON-NLS-1$
    		for(int j = 0; j < values.length; ++j){
    			String value = values[j].trim();
    			if (value.length() > 0) {
    				result.add(value);
    			}
    		}
    	}
		return result;
    }

    public static void addCriteriaToMap(Map<String, Set<String>> map, ICriteria[] criteria) {
    	for (int i = 0; i < criteria.length; ++i) {
			ICriteria criterion = criteria[i];
			String name = criterion.getName();
			List<String> values = CriteriaUtilities.getCriteriaValues(criterion.getValue());
			if (name != null && name.length() > 0 && values.size() > 0) {
				name = name.toLowerCase();
				Set<String> existingValueSet = map.get(name);
				if (null == existingValueSet) {
					existingValueSet = new HashSet<String>();
				}
				existingValueSet.addAll(values);
				map.put(name, existingValueSet);
			}
		}
    }

    public static void addCriteriaToMap(Map<String, Set<String>> map, CriterionResource[] criteria) {
    	for(int i = 0; i < criteria.length; ++ i){
			CriterionResource criterion = criteria[i];
			String criterionName = criterion.getCriterionName();
			List<String> criterionValues = criterion.getCriterionValues();

			Set<String> existedValueSet = map.get(criterionName);
			if (null == existedValueSet)
				existedValueSet = new HashSet<String>();
			existedValueSet.addAll(criterionValues);
			map.put(criterionName, existedValueSet);
		}
    }

}

Back to the top