]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/contentassist/FindExactMatch.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / contentassist / FindExactMatch.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt.contentassist;
13
14 import java.util.Arrays;
15 import java.util.Collection;
16
17 /**
18  * @author Tuukka Lehtonen
19  */
20 public class FindExactMatch {
21
22     public static <T extends INamedObject> T exec(String name, T... allowedValues) {
23         return exec(name, Arrays.asList(allowedValues));
24     }
25
26     public static <T extends INamedObject> T exec(String name, Collection<T> allowedValues) {
27         name = name.toLowerCase();
28         T found = null;
29         for (T obj : allowedValues) {
30             if (obj.getName().toLowerCase().startsWith(name)) {
31                 if (found != null)
32                     return null;
33                 found = obj;
34             }
35         }
36         return found;
37     }
38
39 }