CPD Results

The following document contains the results of PMD's CPD 6.21.0.

Duplications

File Line
de\powerstat\validation\ValidationUtils.java 316
de\powerstat\validation\values\IPV6Address.java 84
    String newAddress = address.substring(0, blockStart + 1);
      final String[] parts = ipv4.split("\\."); //$NON-NLS-1$
      final int block1 = Integer.parseInt(parts[0]);
      final int block2 = Integer.parseInt(parts[1]);
      final int block3 = Integer.parseInt(parts[2]);
      final int block4 = Integer.parseInt(parts[3]);
    newAddress += Integer.toHexString(block1) + String.format("%02x", block2) + ':' + Integer.toHexString(block3) + String.format("%02x", block4); //$NON-NLS-1$ //$NON-NLS-2$
    return newAddress;
   }


  /**
   * Count colons.
   *
   * @param str String to count coolons in
   * @return Numbe rof colons found
   */
  private static int countColons(final String str)
   {
    int colons = 0;
    int expPos = -1;
    do
     {
      expPos = str.indexOf(':', expPos + 1);
      if (expPos > -1)
       {
        ++colons;
       }
     }
    while (expPos > -1);
    return colons;
   }


  /**
   * Expand possible expansion block.
   *
   * @param address IP V6 address
   * @return IP V6 address
   */
  private static String expandExpansionBlock(final String address)
   {
    assert address != null;
    final int expPos = address.indexOf("::"); //$NON-NLS-1$
    if ((expPos == -1))
     {
      return address;
     }
    if (address.indexOf("::", expPos + 1) != -1) //$NON-NLS-1$
     {
      throw new IllegalArgumentException("Not an IP V6 address (more than one expansion block)"); //$NON-NLS-1$
     }
    final String start = address.substring(0, expPos);
    final String end = address.substring(expPos + 2);
    int blocks = 8;
    if (start.length() > 0)
     {
      blocks -= countColons(start) + 1;
     }
    if (end.length() > 0)
     {
      blocks -= countColons(end) + 1;
     }
    final StringBuilder replace = new StringBuilder();
    if (start.length() > 0)
       {
      replace.append(':');
       }
    while (blocks > 0)
       {
      replace.append("0000"); //$NON-NLS-1$
        --blocks;
      if (blocks > 0)
       {
        replace.append(':');
       }
       }
    if (end.length() > 0)
       {
      replace.append(':');
       }
    return start + replace.toString() + end;
     }


  /**
   * Normalize IP V6 address.
   *
   * @param address IP V6 address
   * @return Normalized IP V6 address
   */
  private static String normalizeIPV6Address(final String address)
     {
    assert address != null;
    final String[] parts = address.split(":"); //$NON-NLS-1$
    final StringBuilder normalizedAddress = new StringBuilder();
    for (final String part : parts)
     {
      String newPart = ""; //$NON-NLS-1$
      for (int pos = 0; pos < (4 - part.length()); ++pos)
       {
        newPart += "0"; //$NON-NLS-1$
        // part = "0" + part; //$NON-NLS-1$
       }
      newPart += part;
      normalizedAddress.append(newPart).append(':');
     }
    normalizedAddress.setLength(normalizedAddress.length() - 1);
    return normalizedAddress.toString();
   }
File Line
de\powerstat\validation\values\test\IPV4AddressTests.java 418
de\powerstat\validation\values\test\IPV6AddressTests.java 299
    final IPV4Address address5 = new IPV4Address(PRIVATE_IP_192_168_1_1);
    assertAll("testCompareTo", //$NON-NLS-1$
      () -> assertTrue(address1.compareTo(address2) == -address2.compareTo(address1), "reflexive1"), //$NON-NLS-1$
      () -> assertTrue(address1.compareTo(address3) == -address3.compareTo(address1), "reflexive2"), //$NON-NLS-1$
      () -> assertTrue((address4.compareTo(address3) > 0) && (address3.compareTo(address1) > 0) && (address4.compareTo(address1) > 0), "transitive1"), //$NON-NLS-1$
      () -> assertTrue((address1.compareTo(address2) == 0) && (Math.abs(address1.compareTo(address5)) == Math.abs(address2.compareTo(address5))), "sgn1"), //$NON-NLS-1$
      () -> assertTrue((address1.compareTo(address2) == 0) && address1.equals(address2), "equals") //$NON-NLS-1$
    );
   }

 }
File Line
de\powerstat\validation\values\test\IPV4MaskTests.java 383
de\powerstat\validation\values\test\IPV6MaskTests.java 147
    final IPV4Mask mask5 = new IPV4Mask(IPMASK_255_0_0_0);
    assertAll("testCompareTo", //$NON-NLS-1$
      () -> assertTrue(mask1.compareTo(mask2) == -mask2.compareTo(mask1), "reflexive1"), //$NON-NLS-1$
      () -> assertTrue(mask1.compareTo(mask3) == -mask3.compareTo(mask1), "reflexive2"), //$NON-NLS-1$
      () -> assertTrue((mask4.compareTo(mask3) > 0) && (mask3.compareTo(mask1) > 0) && (mask4.compareTo(mask1) > 0), "transitive1"), //$NON-NLS-1$
      () -> assertTrue((mask1.compareTo(mask2) == 0) && (Math.abs(mask1.compareTo(mask5)) == Math.abs(mask2.compareTo(mask5))), "sgn1"), //$NON-NLS-1$
      () -> assertTrue((mask1.compareTo(mask2) == 0) && mask1.equals(mask2), "equals") //$NON-NLS-1$
    );
   }

 }
File Line
de\powerstat\validation\values\test\IPV4AddressTests.java 383
de\powerstat\validation\values\test\IPV6AddressTests.java 264
    final IPV4Address address4 = new IPV4Address(PRIVATE_IP_192_168_1_1);
    assertAll("testEquals", //$NON-NLS-1$
      () -> assertTrue(address1.equals(address1), "address11 is not equal"), //$NON-NLS-1$
      () -> assertTrue(address1.equals(address2), "address12 are not equal"), //$NON-NLS-1$
      () -> assertTrue(address2.equals(address1), "address21 are not equal"), //$NON-NLS-1$
      () -> assertTrue(address2.equals(address4), "address24 are not equal"), //$NON-NLS-1$
      () -> assertTrue(address1.equals(address4), "address14 are not equal"), //$NON-NLS-1$
      () -> assertFalse(address1.equals(address3), "address13 are equal"), //$NON-NLS-1$
      () -> assertFalse(address3.equals(address1), "address31 are equal"), //$NON-NLS-1$
      () -> assertFalse(address1.equals(null), "address10 is equal") //$NON-NLS-1$
    );
   }


  /**
   * Test toString.
   */
  @Test
  public void testToString()
   {
    final IPV4Address address = new IPV4Address(PRIVATE_IP_192_168_1_1);
File Line
de\powerstat\validation\values\test\IPV4MaskTests.java 348
de\powerstat\validation\values\test\IPV6MaskTests.java 112
    final IPV4Mask mask4 = new IPV4Mask(IPMASK_255_255_255_0);
    assertAll("testEquals", //$NON-NLS-1$
      () -> assertTrue(mask1.equals(mask1), "mask11 is not equal"), //$NON-NLS-1$
      () -> assertTrue(mask1.equals(mask2), "mask12 are not equal"), //$NON-NLS-1$
      () -> assertTrue(mask2.equals(mask1), "mask21 are not equal"), //$NON-NLS-1$
      () -> assertTrue(mask2.equals(mask4), "mask24 are not equal"), //$NON-NLS-1$
      () -> assertTrue(mask1.equals(mask4), "mask14 are not equal"), //$NON-NLS-1$
      () -> assertFalse(mask1.equals(mask3), "mask13 are equal"), //$NON-NLS-1$
      () -> assertFalse(mask3.equals(mask1), "mask31 are equal"), //$NON-NLS-1$
      () -> assertFalse(mask1.equals(null), "mask10 is equal") //$NON-NLS-1$
    );
   }


  /**
   * Test toString.
   */
  @Test
  public void testToString()
   {
    final IPV4Mask mask = new IPV4Mask(IPMASK_255_255_255_0);