Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  1. I'd create local variables for clientDetails[b] and clientDetails[c]. They are used a lot.

  2. 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 use ArrayLists I don't think that it's worth it.

  3. I don't know what's the type of the clientGender field. If it's String, you should not compare it with != or ==. See: Java String.equals versus == Java String.equals versus ==

  4. The anyMatch variable is duplicated, it could be eliminated. It only stores the state whether count == 0 or not.

     final boolean anyMatch = (count > 0);
     if (anyMatch) { 
     ... 
     }
    
  1. I'd create local variables for clientDetails[b] and clientDetails[c]. They are used a lot.

  2. 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 use ArrayLists I don't think that it's worth it.

  3. I don't know what's the type of the clientGender field. If it's String, you should not compare it with != or ==. See: Java String.equals versus ==

  4. The anyMatch variable is duplicated, it could be eliminated. It only stores the state whether count == 0 or not.

     final boolean anyMatch = (count > 0);
     if (anyMatch) { 
     ... 
     }
    
  1. I'd create local variables for clientDetails[b] and clientDetails[c]. They are used a lot.

  2. 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 use ArrayLists I don't think that it's worth it.

  3. I don't know what's the type of the clientGender field. If it's String, you should not compare it with != or ==. See: Java String.equals versus ==

  4. The anyMatch variable is duplicated, it could be eliminated. It only stores the state whether count == 0 or not.

     final boolean anyMatch = (count > 0);
     if (anyMatch) { 
     ... 
     }
    
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Source Link

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.)

added 993 characters in body
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
  1. If it's possible I'd consider storing the interest fielddata in BitSets. Then it would be possible to and two of them and get the number of common bits with the cardinality 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.

  1. Instead of

     System.out.println("");
    
  1. If it's possible I'd consider storing the interest field in BitSets. Then it would be possible to and two of them and get the number of common bits with the cardinality method.

  2. Instead of

     System.out.println("");
    
  1. If it's possible I'd consider storing the interest data in BitSets. Then it would be possible to and two of them and get the number of common bits with the cardinality 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.

  1. Instead of

     System.out.println("");
    
added 2804 characters in body
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
Loading
added 389 characters in body
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
Loading
Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /