/*
* Created on 11.12.2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package pack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class InterSuche {
Interpreter[] interpreters;
public static void main(String[] args) {
new InterSuche().doIt();
}
/**
*
*/
private void doIt() {
// TODO Auto-generated method stub
String[] names =
new String[] {
"Hans",
"Michael",
"Thomas",
"Dirk",
"Christian",
"Domenik",
"Matthias",
"Lukas",
"Heino",
"Sadam" };
interpreters = new Interpreter[10];
for (int i = 0; i < interpreters.length; i++) {
interpreters[i] = new Interpreter(names[i]);
}
//..............
//Suche den Interpreter mit Chris* als Zeichenfolge
String[] suchMuster = new String[] { "Th*", "^*RK", "^*tth*" };
Interpreter inter;
for (int i = 0; i < suchMuster.length; i++) {
inter = searchInterByPattern(suchMuster[i]);
if (inter != null)
System.out.println(inter.getName());
else
System.out.println("Suche erfolglos ... :-(");
}
}
/**
* @param string
* @return
*/
private Interpreter searchInterByPattern(String string) {
// TODO Auto-generated method stub
Pattern pat = Pattern.compile(string, Pattern.CASE_INSENSITIVE);
Matcher matcher = null;
for (int i = 0; i < interpreters.length; i++) {
matcher = pat.matcher(interpreters[i].getName());
if (matcher.find())
return interpreters[i];
}
return null;
}
class Interpreter {
private String name;
//und die tausend anderen Attribute ...
/**
*
*/
public Interpreter(String nam) {
super();
this.name = nam;
// TODO Auto-generated constructor stub
}
/**
* @return
*/
public String getName() {
return name;
}
}
}