Nie zamienisz tego na switch
, ale możesz zamienić na tablicę i pętle.
np: http://ideone.com/4QpGPF
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static Function[] tb=new Function[]
{
new Function("abc")
{
@Override protected void run(Object o)
{
System.out.println("1");
}
},
new Function("def")
{
@Override protected void run(Object o)
{
System.out.println("2");
}
},
new Function("ghi")
{
@Override protected void run(Object o)
{
System.out.println("3");
}
}
};
public static void main (String[] args) throws java.lang.Exception
{
String serverLine="x def y";
for(Function i:tb) if(i.test(serverLine,null)) break;
}
}
class Function
{
private String text;
protected void run(Object o) {}
public boolean test(String line,Object o)
{
if(!line.contains(text)) return false;
run(o);
return true;
}
Function(String text) { this.text=text; }
}