Picking a pattern based on employee type or department
You can't really do much to simplify this. There are 6 cases plus one default which means 7 different results, which means 7 lines to return and 6 conditions.

Unless you don't need to return a new thing every time. Assuming Pattern is from java.util.regex, this is the case. Then you can use something like

import com.google.common.collect.ImmutableMap;

private static final Map&lt;String, Pattern&gt; PATTERNS_FOR_TYPE =
    ImmutableMap.of(
    "individual", new IndivualPattern(),
    "multiple", new MultiplePattern(),
    "combined", new CombinedPattern());
private static final Map&lt;String, Pattern&gt; PATTERNS_FOR_DEPARTMENT = ...;

public static Pattern decidePattern(Employee employee) {
    Pattern result = PATTERNS_FOR_TYPE
            .get(employee.getType().toLowerCase(Locale.ENGLISH));
    if (result!=null) {
        return result;
    }
    Pattern result = PATTERNS_FOR_DEPARTMENT
        .get(employee.getDepartment().toLowerCase(Locale.ENGLISH));
    if (result!=null) {
        return result;
    }
    return new DefaultPattern();
}


But I wouldn't call it a big improvement. What you should do instead or in addition to it, is to get rid of the Strings, that's what enums are for.

In case you insist on Strings, you should normalize them ASAP. No equalsIgnoreCase, no toLowerCase anywhere but when when you encounter the inputs the first time.

Concerning catch Exception, no method can really throw an all possible Exceptions and you should be as specific as possible.



You can (and most probably should) use enums. The annotations come from project Lombok and do exactly what they say (you can do it manually, too).

@RequiredArgsConstructor @Getter 
enum Type {
    INDIVIDUAL(new IndivualPattern()),
    MULTIPLE(new MultiplePattern()),
    COMBINED(new CombinedPattern()),
    ANOTHER(null),
    YET_ANOTHER(null);

    private final Pattern pattern;
}

... enum Department ...

public static Pattern decidePattern(Employee employee) {
    Pattern result = employee.getType().getPattern();
    if (result!=null) {
        return result;
    }
    ...
}


Not always it is a good idea to define the pattern in the enum itself. Then you can use a switch

public static Pattern decidePattern(Employee employee) {
    switch (employee.getType()) {
        case INDIVIDUAL: return new new IndivualPattern();
        ...
        default: // (just to prevent "missing label" warning)
    }
    switch (employee.getType()) {
        ...
    }
    ...
}