mercredi 13 décembre 2017

How to combine multiple OR statements into one expression in an if condition?

The sonar report gives me the illustration as:

The complexity of an expression is defined by the number of &&, || and condition ? ifTrue : ifFalse operators it contains.

A single expression's complexity should not become too high to keep the code readable.

 if (c.isPrimitive() ||                                 // primitives
                    c == Void.class || c == Boolean.class || 
                    c == Integer.class || c == Long.class ||
                    c == Float.class || c == Double.class || 
                    c == Byte.class || c == Short.class || 
                    c == Character.class)
                return super.createSchema(type, names);

Aucun commentaire:

Enregistrer un commentaire