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