Otra forma de hacer lo mismo:
Creo que era lo que "
chuidiang" quiso dar a entender...
Código:
package org.example;
public class example {
public static String arg1;
public static String arg2;
public static String arg3;
public static String arg4;
public static void main(String[] args) {
int b = 0;
b += assignBit(arg1, 0x1); // bitflags 0001 = 1
b += assignBit(arg2, 0x2); // bitflags 0010 = 2
b += assignBit(arg3, 0x4); // bitflags 0100 = 4
b += assignBit(arg4, 0x8); // bitflags 1000 = 8
// b += assignBit(argN, 0x10); // bitflags 10000 = 16
switch (b) {
case 0: // 0 : everything is null
case 1: // 1 : arg1 != null [others == null]
case 2: // 2 : arg2 != null [others == null]
case 3: // 2 + 1 : arg1 != null and arg2 != null [others == null]
case 4: // 4 : arg3 != null [otheres == null]
case 5: // 4 + 1 : arg3 != null and arg1 != null [others == null]
case 6: // 4 + 2 : arg3 != null and arg2 != null [others == null]
case 7: // 4 + 2 + 1 : arg1 != null and arg2 != null and arg3 != null [others == null]
case 8: // 8 : arg4 != null [others == null]
case 9: // 8 + 1 : arg4 != null and arg1 != null [others == null]
// etc, etc....
default:
}
// OR USE java.util.BitSet in place of [int b]
}
public static int assignBit(String arg, int val) {
if(arg != null) if (!arg.isEmpty()) return val;
return 0;
}
}