I'd create local variables for
clientDetails[b]
andclientDetails[c]
. They are used a lot.About the output: if you want to show the number of compatible clients in the header you have to count them (and maybe store them in an
ArrayList
to avoid running the loop twice) before printing the header. If you are not allowed to useArrayList
s I don't think that it's worth it.I don't know what's the type of the
clientGender
field. If it'sString
, you should not compare it with!=
or==
. See: Java String.equals versus == Java String.equals versus ==The
anyMatch
variable is duplicated, it could be eliminated. It only stores the state whethercount == 0
or not.final boolean anyMatch = (count > 0); if (anyMatch) { ... }
I'd create local variables for
clientDetails[b]
andclientDetails[c]
. They are used a lot.About the output: if you want to show the number of compatible clients in the header you have to count them (and maybe store them in an
ArrayList
to avoid running the loop twice) before printing the header. If you are not allowed to useArrayList
s I don't think that it's worth it.I don't know what's the type of the
clientGender
field. If it'sString
, you should not compare it with!=
or==
. See: Java String.equals versus ==The
anyMatch
variable is duplicated, it could be eliminated. It only stores the state whethercount == 0
or not.final boolean anyMatch = (count > 0); if (anyMatch) { ... }
I'd create local variables for
clientDetails[b]
andclientDetails[c]
. They are used a lot.About the output: if you want to show the number of compatible clients in the header you have to count them (and maybe store them in an
ArrayList
to avoid running the loop twice) before printing the header. If you are not allowed to useArrayList
s I don't think that it's worth it.I don't know what's the type of the
clientGender
field. If it'sString
, you should not compare it with!=
or==
. See: Java String.equals versus ==The
anyMatch
variable is duplicated, it could be eliminated. It only stores the state whethercount == 0
or not.final boolean anyMatch = (count > 0); if (anyMatch) { ... }
I usually prefer final
variables. Making a variable final
relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers. @nerdytenor's answers.)
I usually prefer final
variables. Making a variable final
relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers.)
I usually prefer final
variables. Making a variable final
relieves the programmer of excess mental juggling - he/she doesn't have to scan through the code to see if the variable has changed. (From @nerdytenor's answers.)
If it's possible I'd consider storing the interest fielddata in
BitSet
s. Then it would be possible toand
two of them and get the number of common bits with thecardinality
method. Here is some test code:@Test public void testBitSet() { final BitSet interestBitSet = createBitSetFromString("11100111"); final BitSet otherInterestBitSet = createBitSetFromString("11001001"); final BitSet clone = (BitSet) interestBitSet.clone(); clone.and(otherInterestBitSet); assertEquals(3, clone.cardinality()); } private BitSet createBitSetFromString(final String input) { final BitSet result = new BitSet(); final char[] inputArray = input.toCharArray(); for (int index = 0; index < inputArray.length; index++) { if (inputArray[index] == '1') { result.set(index); } } return result; }
The and
method modifies the bitset which is a disadvantage here. Cloning helps, although it's not the most beautiful solution.
Instead of
System.out.println("");
If it's possible I'd consider storing the interest field in
BitSet
s. Then it would be possible toand
two of them and get the number of common bits with thecardinality
method.Instead of
System.out.println("");
If it's possible I'd consider storing the interest data in
BitSet
s. Then it would be possible toand
two of them and get the number of common bits with thecardinality
method. Here is some test code:@Test public void testBitSet() { final BitSet interestBitSet = createBitSetFromString("11100111"); final BitSet otherInterestBitSet = createBitSetFromString("11001001"); final BitSet clone = (BitSet) interestBitSet.clone(); clone.and(otherInterestBitSet); assertEquals(3, clone.cardinality()); } private BitSet createBitSetFromString(final String input) { final BitSet result = new BitSet(); final char[] inputArray = input.toCharArray(); for (int index = 0; index < inputArray.length; index++) { if (inputArray[index] == '1') { result.set(index); } } return result; }
The and
method modifies the bitset which is a disadvantage here. Cloning helps, although it's not the most beautiful solution.
Instead of
System.out.println("");