I assume the code sample you show is just a simplified example and that the real problem is more complex, so as to deserve using a pattern.
- Make
CustomClass
an external class(*). - Have several processors that implement the same interface
- Have a map of processors using the integer that identifies the format of the CSV line as the key (you call it x).
- Retrieve a processor from the map (with the correspoding key) and make it process the line.
- This similar to strategy pattern, it defines a family of algorithms,encapsulates each algorithm, and makes the algorithms interchangeable within that family.
Advantages: flexibility, if you create the map of processors outside the handler and pass it in the constructor, more processors can be added later and Handler will not need to be changed (for example to add a new case the switch control structure).

(*) You can achieve the same results having the interface and the processors as well as the customclass as inner classes/interfaces inside Handler, but it would pollute the solution a lot.
==> CustomClass.java <==
public class CustomClass {}
==> IMessageProcessor.java <==
import java.util.Map; public interface IMessageProcessor { public void processLine(Map<String, CustomClass> map, String line); }
==> ProcessorA.java <==
import java.util.Map; public class ProcessorA implements IMessageProcessor { @Override public void processLine(Map<String, CustomClass> map, String line) { // TODO Auto-generated method stub } }
==> ProcessorB.java <==
import java.util.Map; public class ProcessorB implements IMessageProcessor { @Override public void processLine(Map<String, CustomClass> map, String line) { // TODO Auto-generated method stub } }
==> ProcessorC.java <==
import java.util.Map; public class ProcessorC implements IMessageProcessor { @Override public void processLine(Map<String, CustomClass> map, String line) { // TODO Auto-generated method stub } }
==> Handler.java <==
import java.util.HashMap; import java.util.Map; public class Handler { private Map<String, CustomClass> map = new HashMap<String, CustomClass>(); private Map<Integer,IMessageProcessor> processors = new HashMap<Integer,IMessageProcessor>(); public processFile(){ // store the processors in their map with the appropiate keys processors.put(1, new ProcessorA()); processors.put(2, new ProcessorB()); processors.put(3, new ProcessorC()); // Read the huge CSV file with millions of records, line by line // for each line, get the string before the first comma (say x) processors.get(x).processLine(map,line); } }
Note: You might wish to validate first whether the processor for the key x exists, and it it doesnt, fall back to a default processor, say, stored with key -1, or any other value garanteed not to exist in the CSV file.