ParticipantIdentifierValidatorNorwayOrgNumber implements IParticipantIdentifierValidatorSPI { public static boolean isValidOrganisationNumber (@Nullable final String sValue) { if (StringHelper.getLength (sValue) != 9) return false; final char [] aData = sValue.toCharArray (); if (!Character.isDigit (aData[8])) return false; final int nActualCheckDigit = aData[8] - 48; int nSum = 0; for (int i = 0; i < 8; i++) { final char cNext = aData[i]; if (!Character.isDigit (cNext)) return false; final int nDigit = cNext - 48; nSum += nDigit * WEIGHTS[i]; } final int nModulus = nSum % 11; if (nModulus == 0 && nActualCheckDigit == 0) return true; final int nCalculatedCheckDigit = 11 - nModulus; return nActualCheckDigit == nCalculatedCheckDigit; }  @SuppressWarnings ("deprecation") boolean isSupportedIssuingAgency(@Nonnull @Nonempty final String sIssuingAgencyID); boolean isValueValid(@Nonnull @Nonempty final String sValue); static boolean isValidOrganisationNumber(@Nullable final String sValue);  }
@Test public void test02 () { assertTrue (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("123456785")); assertTrue (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("976098897")); assertTrue (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("991618112")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber (null)); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("976098897 ")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("12345678-")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("-23456789")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("123456784")); assertFalse (ParticipantIdentifierValidatorNorwayOrgNumber.isValidOrganisationNumber ("323456780")); }