target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testEqualsWithForwardSlashFilter() throws ParseException { String str = "(ou=people/in/my/company)"; SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertEquals( "people/in/my/company", node.getValue().getString() ); assertTrue( node instanceof EqualityNode ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm1() throws ParseException { String str = "(ou:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "stupidMatch", node.getMatchingRuleId() ); assertTrue( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm1WithNumericOid() throws ParseException { String str = "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( "1.2.3.4", node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "1.3434.23.2", node.getMatchingRuleId() ); assertTrue( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm1NoDnAttr() throws ParseException { String str = "(ou:stupidMatch:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "stupidMatch", node.getMatchingRuleId() ); assertFalse( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm1OptionOnRule() { try { FilterParser.parse( "(ou:stupidMatch;lang-de:=dummyAssertion\\23\\c4\\8d)" ); fail( "we should never get here" ); } catch ( ParseException e ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm1NoAttrNoMatchingRule() throws ParseException { String str = "(ou:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( null, node.getMatchingRuleId() ); assertFalse( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm2() throws ParseException { String str = "(:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( null, node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "stupidMatch", node.getMatchingRuleId() ); assertTrue( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm2OptionOnRule() { try { FilterParser.parse( "(:dn:stupidMatch;lang-en:=dummyAssertion\\23\\c4\\8d)" ); fail( "we should never get here" ); } catch ( ParseException e ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testYearMonthDayHourDotFractionZulu() throws ParseException { String gt = "200801021213.987Z"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void fromString() throws DecoderException { for ( int i = 0; i < 2; i++ ) { for ( int j = 0; j < 40; j++ ) { String oidStr = i + "." + j; byte[] expected = new byte[]{ ( byte ) ( i * 40 + j ) }; byte[] oidBytes = Oid.fromString( oidStr ).toBytes(); assertTrue( Arrays.equals( expected, oidBytes ) ); } } assertTrue( Arrays.equals( new byte[] { 0x2A, ( byte ) 0x86, 0x48, ( byte ) 0x86, ( byte ) 0xF7, 0x12, 0x01, 0x02, 0x02 }, Oid.fromString( "1.2.840.113554.1.2.2" ).toBytes() ) ); } | public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } | Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } } | Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private Oid( String oidString, byte[] oidBytes ); } | Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private Oid( String oidString, byte[] oidBytes ); @Override boolean equals( Object other ); static Oid fromBytes( byte[] oidBytes ); static Oid fromString( String oidString ); int getEncodedLength(); @Override int hashCode(); static boolean isOid( String oidString ); byte[] toBytes(); @Override String toString(); void writeBytesTo( ByteBuffer buffer ); void writeBytesTo( OutputStream outputStream ); } | Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private Oid( String oidString, byte[] oidBytes ); @Override boolean equals( Object other ); static Oid fromBytes( byte[] oidBytes ); static Oid fromString( String oidString ); int getEncodedLength(); @Override int hashCode(); static boolean isOid( String oidString ); byte[] toBytes(); @Override String toString(); void writeBytesTo( ByteBuffer buffer ); void writeBytesTo( OutputStream outputStream ); } |
@Test public void testExtensibleFilterForm2WithNumericOid() throws ParseException { String str = "(:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( null, node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "1.3434.23.2", node.getMatchingRuleId() ); assertTrue( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm2NoDnAttr() throws ParseException { String str = "(:stupidMatch:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( null, node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "stupidMatch", node.getMatchingRuleId() ); assertFalse( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm2NoDnAttrWithNumericOidNoAttr() throws ParseException { String str = "(:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)"; ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str ); assertEquals( null, node.getAttribute() ); assertEquals( "dummyAssertion#\u010D", node.getValue().getString() ); assertEquals( "1.3434.23.2", node.getMatchingRuleId() ); assertFalse( node.hasDnAttributes() ); assertTrue( node instanceof ExtensibleNode ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testExtensibleFilterForm3() throws ParseException { try { FilterParser.parse( "(:=dummyAssertion)" ); fail( "Should never reach this point" ); } catch ( ParseException pe ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testReuseParser() throws ParseException { FilterParser.parse( "(ou~=people)" ); FilterParser.parse( "(&(ou~=people)(age>=30)) " ); FilterParser.parse( "(|(ou~=people)(age>=30)) " ); FilterParser.parse( "(!(&(ou~=people)(age>=30)))" ); FilterParser.parse( "(ou;lang-de>=\\23\\42asdl fkajsd)" ); FilterParser.parse( "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)" ); FilterParser.parse( "(1.3.4.2;lang-de;version-124>=\\23\\42asdl fkajsd)" ); FilterParser.parse( "(ou=*)" ); FilterParser.parse( "(1.2.3.4=*)" ); FilterParser.parse( "(ou=people)" ); FilterParser.parse( "(ou=people/in/my/company)" ); FilterParser.parse( "(ou:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(ou:stupidMatch:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(ou:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(1.2.3.4:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(:stupidMatch:=dummyAssertion\\23\\c4\\8d)" ); FilterParser.parse( "(:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testReuseParserAfterFailures() throws ParseException { FilterParser.parse( "(ou~=people)" ); FilterParser.parse( "(&(ou~=people)(age>=30)) " ); FilterParser.parse( "(|(ou~=people)(age>=30)) " ); FilterParser.parse( "(!(&(ou~=people)(age>=30)))" ); FilterParser.parse( "(ou;lang-de>=\\23\\42asdl fkajsd)" ); FilterParser.parse( "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)" ); FilterParser.parse( "(1.3.4.2;lang-de;version-124>=\\23\\42asdl fkajsd)" ); try { FilterParser.parse( "(ou:stupidMatch;lang-de:=dummyAssertion\\23\\ac)" ); fail( "we should never get here" ); } catch ( ParseException e ) { assertTrue( true ); } FilterParser.parse( "(ou=*)" ); FilterParser.parse( "(1.2.3.4=*)" ); FilterParser.parse( "(ou=people)" ); FilterParser.parse( "(ou=people/in/my/company)" ); FilterParser.parse( "(ou:dn:stupidMatch:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(ou:stupidMatch:=dummyAssertion\\23\\ac)" ); try { FilterParser.parse( "(:dn:stupidMatch;lang-en:=dummyAssertion\\23\\ac)" ); fail( "we should never get here" ); } catch ( ParseException e ) { assertTrue( true ); } FilterParser.parse( "(ou:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(1.2.3.4:1.3434.23.2:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(:dn:stupidMatch:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(:dn:1.3434.23.2:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(:stupidMatch:=dummyAssertion\\23\\ac)" ); FilterParser.parse( "(:1.3434.23.2:=dummyAssertion\\23\\ac)" ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testNullOrEmptyString() throws ParseException { try { FilterParser.parse( (String)null ); fail( "Should not reach this point " ); } catch ( ParseException pe ) { assertTrue( true ); } try { FilterParser.parse( "" ); fail( "Should not reach this point " ); } catch ( ParseException pe ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoAnyNoFinal() throws ParseException { String str = "(ou=foo*)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 0, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertEquals( "foo", node.getInitial() ); assertEquals( null, node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoAny() throws ParseException { String str = "(ou=foo*bar)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 0, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertEquals( "foo", node.getInitial() ); assertEquals( "bar", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoAnyNoIni() throws ParseException { String str = "(ou=*bar)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 0, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertEquals( null, node.getInitial() ); assertEquals( "bar", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testYearMonthDayHourDotFractionPlusHour() throws ParseException { String gt = "2008010212.987+0100"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testSubstringOneAny() throws ParseException { String str = "(ou=foo*guy*bar)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 1, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertTrue( node.getAny().contains( "guy" ) ); assertEquals( "foo", node.getInitial() ); assertEquals( "bar", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringManyAny() throws ParseException { String str = "(ou=a*b*c*d*e*f)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 4, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertTrue( node.getAny().contains( "b" ) ); assertTrue( node.getAny().contains( "c" ) ); assertTrue( node.getAny().contains( "d" ) ); assertTrue( node.getAny().contains( "e" ) ); assertEquals( "a", node.getInitial() ); assertEquals( "f", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoIniManyAny() throws ParseException { String str = "(ou=*b*c*d*e*f)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 4, node.getAny().size() ); assertFalse( node.getAny().contains( new Value( "" ).getString() ) ); assertTrue( node.getAny().contains( "e" ) ); assertTrue( node.getAny().contains( "b" ) ); assertTrue( node.getAny().contains( "c" ) ); assertTrue( node.getAny().contains( "d" ) ); assertEquals( null, node.getInitial() ); assertEquals( "f", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringManyAnyNoFinal() throws ParseException { String str = "(ou=a*b*c*d*e*)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 4, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertTrue( node.getAny().contains( "e" ) ); assertTrue( node.getAny().contains( "b" ) ); assertTrue( node.getAny().contains( "c" ) ); assertTrue( node.getAny().contains( "d" ) ); assertEquals( "a", node.getInitial() ); assertEquals( null, node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoIniManyAnyNoFinal() throws ParseException { String str = "(ou=*b*c*d*e*)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 4, node.getAny().size() ); assertFalse( node.getAny().contains( new Value( "" ).getString() ) ); assertTrue( node.getAny().contains( "e" ) ); assertTrue( node.getAny().contains( "b" ) ); assertTrue( node.getAny().contains( "c" ) ); assertTrue( node.getAny().contains( "d" ) ); assertEquals( null, node.getInitial() ); assertEquals( null, node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringNoAnyDoubleSpaceStar() throws ParseException { String str = "(ou=foo* *bar)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 1, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertTrue( node.getAny().contains( " " ) ); assertEquals( "foo", node.getInitial() ); assertEquals( "bar", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringAnyDoubleSpaceStar() throws ParseException { String str = "(ou=foo* a *bar)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 1, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertTrue( node.getAny().contains( " a " ) ); assertEquals( "foo", node.getInitial() ); assertEquals( "bar", node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSubstringStarAnyStar() throws ParseException { String str = "(ou=*foo*)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 1, node.getAny().size() ); assertTrue( node.getAny().contains( "foo" ) ); assertNull( node.getInitial() ); assertNull( node.getFinal() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testTwoByteUTF8Raw() throws ParseException { byte[] bytes = { ( byte ) 0xC2, ( byte ) 0xA2 }; new String( bytes, StandardCharsets.UTF_8 ); String str = "(cn=\\C2\\A2)"; SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testTwoByteUTF8Escaped() throws ParseException { byte[] bytes = { ( byte ) 0xC2, ( byte ) 0xA2 }; String str = "(cn=\\C2\\A2)"; new String( bytes, StandardCharsets.UTF_8 ); SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testYearMonthDayHourDotFractionMinusHourMin() throws ParseException { String gt = "2008010212.987-1030"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testThreeByteUTF8Raw() throws ParseException { byte[] bytes = { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; new String( bytes, StandardCharsets.UTF_8 ); String str = "(cn=\\E2\\89\\A0)"; SimpleNode<?> node = (SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testThreeByteUTF8Escaped() throws ParseException { byte[] bytes = { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; String str = "(cn=\\E2\\89\\A0aa)"; String strEscaped = "(cn=\\E2\\89\\A0\\61\\61)"; new String( bytes, StandardCharsets.UTF_8 ); SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( strEscaped, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testThreeByteJapaneseUTF8Raw() throws ParseException { byte[] bytes = { ( byte ) 0xE3, ( byte ) 0x81, ( byte ) 0x99 }; new String( bytes, StandardCharsets.UTF_8 ); String str = "(cn=\\E3\\81\\99)"; SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "3059", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testThreeByteJapaneseUTF8Escaped() throws ParseException { byte[] bytes = { ( byte ) 0xE3, ( byte ) 0x81, ( byte ) 0x99 }; String str = "(cn=\\E3\\81\\99)"; new String( bytes, StandardCharsets.UTF_8 ); SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "cn", node.getAttribute() ); String val = node.getValue().getString(); assertEquals( "3059", Integer.toHexString( val.charAt( 0 ) ) ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testEqualsFilterWithPoundInValue() throws ParseException { String str = "(uid=#f1)"; SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str ); assertEquals( "uid", node.getAttribute() ); assertEquals( "#f1", node.getValue().getString() ); assertTrue( node instanceof EqualityNode ); assertEquals( str, node.toString() ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testSpecialCharsInMemberOf() { try { FilterParser .parse( "(memberOf=1.2.840.113556.1.4.1301=$#@&*()==,2.5.4.11=local,2.5.4.11=users,2.5.4.11=readimanager)" ); fail(); } catch ( ParseException pe ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testAndEqOr_EqEq() { try { BranchNode node = ( BranchNode ) FilterParser .parse( "(&(objectClass=nisNetgroup)(|(nisNetGroupTriple=a*a)(nisNetGroupTriple=\\28*,acc1,*\\29)))" ); assertEquals( 2, node.getChildren().size() ); assertTrue( node instanceof AndNode ); ExprNode aEqb = node.getFirstChild(); assertTrue( aEqb instanceof EqualityNode ); assertEquals( "objectClass", ( ( EqualityNode<?> ) aEqb ).getAttribute() ); assertEquals( "nisNetgroup", ( ( EqualityNode<?> ) aEqb ).getValue().getString() ); ExprNode orNode = node.getChildren().get( 1 ); assertTrue( orNode instanceof OrNode ); assertEquals( 2, ( ( OrNode ) orNode ).getChildren().size() ); ExprNode leftNode = ( ( OrNode ) orNode ).getChildren().get( 0 ); assertTrue( leftNode instanceof SubstringNode ); assertEquals( "nisNetGroupTriple", ( ( SubstringNode ) leftNode ).getAttribute() ); assertEquals( "a", ( ( SubstringNode ) leftNode ).getInitial() ); assertEquals( 0, ( ( SubstringNode ) leftNode ).getAny().size() ); assertEquals( "a", ( ( SubstringNode ) leftNode ).getFinal() ); ExprNode rightNode = ( ( OrNode ) orNode ).getChildren().get( 1 ); assertTrue( rightNode instanceof SubstringNode ); assertEquals( "nisNetGroupTriple", ( ( SubstringNode ) rightNode ).getAttribute() ); assertEquals( "(", ( ( SubstringNode ) rightNode ).getInitial() ); assertEquals( 1, ( ( SubstringNode ) rightNode ).getAny().size() ); assertEquals( ",acc1,", ( ( SubstringNode ) rightNode ).getAny().get( 0 ) ); assertEquals( ")", ( ( SubstringNode ) rightNode ).getFinal() ); } catch ( ParseException pe ) { assertTrue( true ); } } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testObjectClassAndFilterWithSpaces() throws ParseException { String str = "(&(objectClass=person)(objectClass=organizationalUnit))"; BranchNode node = ( BranchNode ) FilterParser.parse( str ); assertEquals( 2, node.getChildren().size() ); assertTrue( node instanceof AndNode ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testQuotedChars() throws ParseException { String str = "(cn='~%\\28'$'\\5C)"; ExprNode node = FilterParser.parse( str ); assertTrue( node instanceof EqualityNode ); assertEquals( "'~%('$'\\", ( ( EqualityNode<?> ) node ).getValue().getString() ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testQuotedCharsCase() throws ParseException { String str = "(cn='~%\\28'$'\\5Cac)"; ExprNode node = FilterParser.parse( str ); assertTrue( node instanceof EqualityNode ); assertEquals( "'~%('$'\\ac", ( ( EqualityNode<?> ) node ).getValue().getString() ); String str2 = node.toString(); assertEquals( Strings.upperCase( str ), Strings.upperCase( str2 ) ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testYearMonthDayHourCommaFractionZulu() throws ParseException { String gt = "2008010212,987Z"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testQuotedSubstringManyAny() throws ParseException { String str = "(ou=\\5C*\\00*\\3D*\\2Abb)"; SubstringNode node = ( SubstringNode ) FilterParser.parse( str ); assertEquals( "ou", node.getAttribute() ); assertTrue( node instanceof SubstringNode ); assertEquals( 2, node.getAny().size() ); assertFalse( node.getAny().contains( "" ) ); assertEquals( "\\", node.getInitial() ); assertTrue( node.getAny().contains( "\0" ) ); assertTrue( node.getAny().contains( "=" ) ); assertEquals( "*bb", node.getFinal() ); String str2 = node.toString(); assertEquals( "(ou=\\5C*\\00*=*\\2Abb)", str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testBinaryValueEscaped() throws ParseException { String str = "(objectguid=\\29\\4C\\04\\B5\\D4\\ED\\38\\46\\87\\EE\\77\\58\\5C\\32\\AD\\91)"; FilterParser.parse( str ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testAndFilterFollowed() throws ParseException { String str = "(&(ou~=people)(age>=30))} some more text"; BranchNode node = ( BranchNode ) FilterParser.parse( str ); assertEquals( 2, node.getChildren().size() ); assertTrue( node instanceof AndNode ); String str2 = node.toString(); assertTrue( str.startsWith( str2 ) ); assertEquals( "(&(ou~=people)(age>=30))", str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testFilterOrder() throws ParseException { String filterStr1 = "(&(&(jagplayUserGroup=Active)(!(jagplayUserGroup=Banned))(jagplayUserNickname=admin)))"; String filterStr2 = "(&(jagplayUserNickname=admin)(&(jagplayUserGroup=Active)(!(jagplayUserGroup=Banned)))) "; BranchNode node1 = ( BranchNode ) FilterParser.parse( filterStr1 ); BranchNode node2 = ( BranchNode ) FilterParser.parse( filterStr2 ); assertEquals( 1, node1.getChildren().size() ); assertTrue( node1 instanceof AndNode ); ExprNode andNode1 = node1.getChildren().get( 0 ); assertTrue( andNode1 instanceof AndNode ); List<ExprNode> children1 = ( ( AndNode ) andNode1 ).getChildren(); assertEquals( 3, children1.size() ); ExprNode child1 = children1.get( 0 ); assertTrue( child1 instanceof EqualityNode ); assertEquals( "jagplayUserGroup", ( ( EqualityNode<?> ) child1 ).getAttribute() ); assertEquals( "Active", ( ( EqualityNode<?> ) child1 ).getValue().getString() ); ExprNode child2 = children1.get( 1 ); assertTrue( child2 instanceof NotNode ); NotNode notNode1 = ( NotNode ) child2; ExprNode notNodeChild1 = notNode1.getFirstChild(); assertTrue( notNodeChild1 instanceof EqualityNode ); assertEquals( "jagplayUserGroup", ( ( EqualityNode<?> ) notNodeChild1 ).getAttribute() ); assertEquals( "Banned", ( ( EqualityNode<?> ) notNodeChild1 ).getValue().getString() ); ExprNode child3 = children1.get( 2 ); assertTrue( child3 instanceof EqualityNode ); assertEquals( "jagplayUserNickname", ( ( EqualityNode<?> ) child3 ).getAttribute() ); assertEquals( "admin", ( ( EqualityNode<?> ) child3 ).getValue().getString() ); assertEquals( 2, node2.getChildren().size() ); assertTrue( node2 instanceof AndNode ); child1 = node2.getChildren().get( 0 ); assertTrue( child1 instanceof EqualityNode ); assertEquals( "jagplayUserNickname", ( ( EqualityNode<?> ) child1 ).getAttribute() ); assertEquals( "admin", ( ( EqualityNode<?> ) child1 ).getValue().getString() ); child2 = node2.getChildren().get( 1 ); assertTrue( child2 instanceof AndNode ); AndNode andNode2 = ( ( AndNode ) child2 ); assertEquals( 2, andNode2.getChildren().size() ); child1 = andNode2.getChildren().get( 0 ); assertTrue( child1 instanceof EqualityNode ); assertEquals( "jagplayUserGroup", ( ( EqualityNode<?> ) child1 ).getAttribute() ); assertEquals( "Active", ( ( EqualityNode<?> ) child1 ).getValue().getString() ); child2 = andNode2.getChildren().get( 1 ); assertTrue( child2 instanceof NotNode ); notNode1 = ( NotNode ) child2; notNodeChild1 = notNode1.getFirstChild(); assertTrue( notNodeChild1 instanceof EqualityNode ); assertEquals( "jagplayUserGroup", ( ( EqualityNode<?> ) notNodeChild1 ).getAttribute() ); assertEquals( "Banned", ( ( EqualityNode<?> ) notNodeChild1 ).getValue().getString() ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testEqualsFilterWithUnderscoreRelaxed() throws ParseException { String str = "(a_b_=people)"; SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str, true ); assertEquals( "a_b_", node.getAttribute() ); assertEquals( "people", node.getValue().getString() ); assertTrue( node instanceof EqualityNode ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testEqualsFilterWithUnderscoreNotRelaxed() throws ParseException { String str = "(a_b_=people)"; assertThrows( ParseException.class, () -> { FilterParser.parse( str, false ); } ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testAndFilterWithUnderscoreRelaxed() throws ParseException { String str = "(&(o_u~=people)(a_g_e>=30))"; BranchNode node = ( BranchNode ) FilterParser.parse( str, true ); assertEquals( 2, node.getChildren().size() ); assertTrue( node instanceof AndNode ); String str2 = node.toString(); assertEquals( str, str2 ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testAndFilterWithUnderscoreNotRelaxed() throws ParseException { String str = "(&(o_u~=people)(a_g_e>=30))"; assertThrows( ParseException.class, () -> { FilterParser.parse( str, false ); } ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testRelaxedFilterParse() throws ParseException { String str = " ( cn =*) "; ExprNode node = FilterParser.parse( str, false ); assertTrue( node instanceof PresenceNode ); assertEquals( "cn", ((PresenceNode)node).attribute ); str = " ( & ( cn =*) ) "; node = FilterParser.parse( str, false ); assertTrue( node instanceof AndNode ); assertEquals( 1, ((AndNode)node).children.size() ); ExprNode child = ((AndNode)node).children.get( 0 ); assertTrue( child instanceof PresenceNode ); assertEquals( "cn", ((PresenceNode)child).attribute ); } | public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } | FilterParser { public static ExprNode parse( String filter ) throws ParseException { return parse( null, filter, false ); } private FilterParser(); static ExprNode parse( String filter ); static ExprNode parse( String filter, boolean relaxed ); static ExprNode parse( SchemaManager schemaManager, String filter ); static ExprNode parse( SchemaManager schemaManager, String filter, boolean relaxed ); } |
@Test public void testGetRegexpEmpty() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "" }, "" ); boolean b1 = pattern.matcher( "" ).matches(); assertTrue( b1 ); } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testYearMonthDayHourCommaFractionPlusHour() throws ParseException { String gt = "2008010212,987+0100"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testGetRegexpInitial() throws Exception { Pattern pattern = SubstringNode.getRegex( "Test", new String[] { "" }, "" ); boolean b1 = pattern.matcher( "Test just a test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just a test" ).matches(); assertFalse( b3 ); } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testGetRegexpFinal() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "" }, "Test" ); boolean b1 = pattern.matcher( "test just a Test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just a test" ).matches(); assertFalse( b3 ); } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testGetRegexpAny() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "just", "a" }, "" ); boolean b1 = pattern.matcher( "test just a Test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just A test" ).matches(); assertFalse( b3 ); } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testGetRegexpFull() throws Exception { Pattern pattern = SubstringNode.getRegex( "Test", new String[] { "just", "a" }, "test" ); boolean b1 = pattern.matcher( "Test (this is) just (truly !) a (little) test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "Test (this is) just (truly !) A (little) test" ).matches(); assertFalse( b3 ); } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testGetRegexpWithLdapFilterSpecialChars() throws Exception { Pattern[] patterns = new Pattern[] { SubstringNode.getRegex( null, new String[] { "(" }, null ), SubstringNode.getRegex( null, new String[] { ")" }, null ), SubstringNode.getRegex( null, new String[] { "*" }, null ), SubstringNode.getRegex( null, new String[] { "\\" }, null ), }; for ( Pattern pattern : patterns ) { boolean b1 = pattern.matcher( "a(b*c\\d)e" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "Test test" ).matches(); assertFalse( b3 ); } } | public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } | SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern ); SubstringNode( String attribute, String initialPattern, String finalPattern ); SubstringNode( AttributeType attribute ); SubstringNode( String attributeType ); SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
String finalPattern ); SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString(); } |
@Test public void testFormatWithNoPlaceholdersAndCorrectArgumentCount() { assertEquals( "(cn=foo)", FilterEncoder.format( "(cn=foo)", (String[])null ) ); assertEquals( "(cn=foo)", FilterEncoder.format( "(cn=foo)", ZERO ) ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testFormatWithNoPlaceholdersAndTooManyArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn=foo)", ONE ); } ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testFormatWithPlaceholdersAndTooFewArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn={0})", ZERO ); } ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testFormatWithPlaceholdersAndCorrectArgumentCount() { assertEquals( "(cn=foo)", FilterEncoder.format( "(cn={0})", ONE ) ); assertEquals( "(&(cn=foo)(uid=bar))", FilterEncoder.format( "(&(cn={0})(uid={1}))", TWO ) ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testFormatWithPlaceholdersAndTooManyArguments() { assertThrows( IllegalArgumentException.class, () -> { FilterEncoder.format( "(cn={0})", TWO ); } ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testYearMonthDayHourCommaFractionMinusHourMin() throws ParseException { String gt = "2008010212,987-1030"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testFormatWithPlaceholdersAndSpecialChars() { assertEquals( "(cn=\\28\\5C\\2A\\00\\29)", FilterEncoder.format( "(cn={0})", SPECIAL_CHARS ) ); } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testExceptionMessage() { try { FilterEncoder.format( "(&(cn={0})(uid={1}))", ONE ); fail( "IllegalArgumentException expected" ); } catch ( IllegalArgumentException e ) { String message = e.getMessage(); assertTrue( message.contains( " (&(cn={0})(uid={1})) " ) ); assertTrue( message.contains( " 2 " ) ); assertTrue( message.contains( " 1 " ) ); } } | public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String format( String filterTemplate, String... values ) { if ( values == null ) { values = Strings.EMPTY_STRING_ARRAY; } MessageFormat mf = new MessageFormat( filterTemplate, Locale.ROOT ); Format[] formats = mf.getFormatsByArgumentIndex(); if ( formats.length != values.length ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13300_BAD_PLACE_HOLDERS_NUMBER, filterTemplate, formats.length, values.length ) ); } for ( int i = 0; i < values.length; i++ ) { values[i] = encodeFilterValue( values[i] ); } return mf.format( values ); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void testEncodeFilterValue() { assertEquals( "1234567890", FilterEncoder.encodeFilterValue( "1234567890" ) ); assertEquals( "\\28", FilterEncoder.encodeFilterValue( "(" ) ); assertEquals( "\\29", FilterEncoder.encodeFilterValue( ")" ) ); assertEquals( "\\2A", FilterEncoder.encodeFilterValue( "*" ) ); assertEquals( "\\5C", FilterEncoder.encodeFilterValue( "\\" ) ); assertEquals( "\\00", FilterEncoder.encodeFilterValue( "\0" ) ); assertEquals( "\\28\\2A\\29", FilterEncoder.encodeFilterValue( "(*)" ) ); assertEquals( "a test \\2A \\5Cend", FilterEncoder.encodeFilterValue( "a test \\2A \\end" ) ); } | public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } | FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } } | FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private FilterEncoder(); } | FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } | FilterEncoder { public static String encodeFilterValue( String value ) { StringBuilder sb = new StringBuilder( value.length() ); boolean escaped = false; boolean hexPair = false; char hex = '\0'; for ( int i = 0; i < value.length(); i++ ) { char ch = value.charAt( i ); switch ( ch ) { case '*': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\2A" ); break; case '(': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\28" ); break; case ')': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\29" ); break; case '\0': if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( "\\00" ); break; case '\\': if ( escaped ) { sb.append( "\\5C" ); escaped = false; } else { escaped = true; hexPair = false; } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': if ( escaped ) { if ( hexPair ) { sb.append( '\\' ).append( hex ).append( ch ); escaped = false; hexPair = false; } else { hexPair = true; hex = ch; } } else { sb.append( ch ); } break; default: if ( escaped ) { sb.append( "\\5C" ); if ( hexPair ) { sb.append( hex ); hexPair = false; } escaped = false; } sb.append( ch ); } } if ( escaped ) { sb.append( "\\5C" ); } return sb.toString(); } private FilterEncoder(); static String format( String filterTemplate, String... values ); static String encodeFilterValue( String value ); } |
@Test public void compareCredentialTest() { assertTrue( PasswordUtil.compareCredentials( null, null ) ); assertTrue( PasswordUtil.compareCredentials( new byte[] {}, new byte[] {} ) ); assertTrue( PasswordUtil.compareCredentials( new byte[] { 0x01 }, new byte[] { 0x01 } ) ); assertFalse( PasswordUtil.compareCredentials( null, new byte[] { 0x01 } ) ); assertFalse( PasswordUtil.compareCredentials( new byte[] { 0x01 }, null ) ); assertFalse( PasswordUtil.compareCredentials( new byte[] { 0x01 }, new byte[] { 0x02 } ) ); assertFalse( PasswordUtil.compareCredentials( Strings.getBytesUtf8( "Password1" ), Strings.getBytesUtf8( "Password1 " ) ) ); assertFalse( PasswordUtil.compareCredentials( Strings.getBytesUtf8( "Password1" ), Strings.getBytesUtf8( "password1" ) ) ); assertTrue( PasswordUtil.compareCredentials( Strings.getBytesUtf8( "Password1" ), Strings.getBytesUtf8( "Password1" ) ) ); } | public static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ) { LdapSecurityConstants algorithm = findAlgorithm( storedCredentials ); if ( algorithm != null ) { PasswordDetails passwordDetails = PasswordUtil.splitCredentials( storedCredentials ); byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() ); } else { return compareBytes( receivedCredentials, storedCredentials ); } } | PasswordUtil { public static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ) { LdapSecurityConstants algorithm = findAlgorithm( storedCredentials ); if ( algorithm != null ) { PasswordDetails passwordDetails = PasswordUtil.splitCredentials( storedCredentials ); byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() ); } else { return compareBytes( receivedCredentials, storedCredentials ); } } } | PasswordUtil { public static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ) { LdapSecurityConstants algorithm = findAlgorithm( storedCredentials ); if ( algorithm != null ) { PasswordDetails passwordDetails = PasswordUtil.splitCredentials( storedCredentials ); byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() ); } else { return compareBytes( receivedCredentials, storedCredentials ); } } private PasswordUtil(); } | PasswordUtil { public static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ) { LdapSecurityConstants algorithm = findAlgorithm( storedCredentials ); if ( algorithm != null ) { PasswordDetails passwordDetails = PasswordUtil.splitCredentials( storedCredentials ); byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() ); } else { return compareBytes( receivedCredentials, storedCredentials ); } } private PasswordUtil(); static LdapSecurityConstants findAlgorithm( byte[] credentials ); static byte[] createStoragePassword( String credentials, LdapSecurityConstants algorithm ); static byte[] createStoragePassword( byte[] credentials, LdapSecurityConstants algorithm ); static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ); static PasswordDetails splitCredentials( byte[] credentials ); static boolean isPwdExpired( String pwdChangedZtime, int pwdMaxAgeSec, TimeProvider timeProvider ); } | PasswordUtil { public static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ) { LdapSecurityConstants algorithm = findAlgorithm( storedCredentials ); if ( algorithm != null ) { PasswordDetails passwordDetails = PasswordUtil.splitCredentials( storedCredentials ); byte[] userPassword = PasswordUtil.encryptPassword( receivedCredentials, passwordDetails.getAlgorithm(), passwordDetails.getSalt() ); return compareBytes( userPassword, passwordDetails.getPassword() ); } else { return compareBytes( receivedCredentials, storedCredentials ); } } private PasswordUtil(); static LdapSecurityConstants findAlgorithm( byte[] credentials ); static byte[] createStoragePassword( String credentials, LdapSecurityConstants algorithm ); static byte[] createStoragePassword( byte[] credentials, LdapSecurityConstants algorithm ); static boolean compareCredentials( byte[] receivedCredentials, byte[] storedCredentials ); static PasswordDetails splitCredentials( byte[] credentials ); static boolean isPwdExpired( String pwdChangedZtime, int pwdMaxAgeSec, TimeProvider timeProvider ); static final int SHA1_LENGTH; static final int SHA256_LENGTH; static final int SHA384_LENGTH; static final int SHA512_LENGTH; static final int MD5_LENGTH; static final int PKCS5S2_LENGTH; static final int CRYPT_LENGTH; static final int CRYPT_MD5_LENGTH; static final int CRYPT_SHA256_LENGTH; static final int CRYPT_SHA512_LENGTH; static final int CRYPT_BCRYPT_LENGTH; } |
@Test public void testApplyAddModificationToEmptyEntry() throws LdapException { Entry entry = new DefaultEntry(); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); assertEquals( attr, entry.get( "cn" ) ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyAddModificationToEntry() throws LdapException { Entry entry = new DefaultEntry(); entry.add( "dc", "apache" ); assertEquals( 1, entry.size() ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 2, entry.size() ); assertEquals( attr, entry.get( "cn" ) ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyAddModificationToEntryWithValues() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "apache" ); assertEquals( 1, entry.size() ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); Attribute attribute = entry.get( "cn" ); assertTrue( attribute.size() != 0 ); Set<String> expectedValues = new HashSet<String>(); expectedValues.add( "apache" ); expectedValues.add( "test" ); for ( Value value : attribute ) { String valueStr = value.getString(); assertTrue( expectedValues.contains( valueStr ) ); expectedValues.remove( valueStr ); } assertEquals( 0, expectedValues.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyAddModificationToEntryWithSameValue() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "test", "apache" ); assertEquals( 1, entry.size() ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); Attribute cnAttr = entry.get( "cn" ); assertTrue( cnAttr.size() != 0 ); Set<String> expectedValues = new HashSet<String>(); expectedValues.add( "apache" ); expectedValues.add( "test" ); for ( Value value : cnAttr ) { String valueStr = value.getString(); assertTrue( expectedValues.contains( valueStr ) ); expectedValues.remove( valueStr ); } assertEquals( 0, expectedValues.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyRemoveModificationFromEmptyEntry() throws LdapException { Entry entry = new DefaultEntry(); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNull( entry.get( "cn" ) ); assertEquals( 0, entry.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyRemoveModificationFromEntryAttributeNotPresent() throws LdapException { Entry entry = new DefaultEntry(); Attribute dc = new DefaultAttribute( "dc", "apache" ); entry.put( dc ); Attribute cn = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, cn ); AttributeUtils.applyModification( entry, modification ); assertNull( entry.get( "cn" ) ); assertNotNull( entry.get( "dc" ) ); assertEquals( 1, entry.size() ); assertEquals( dc, entry.get( "dc" ) ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testFormatting() throws ParseException { String gt = "20080102121314Z"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); result = generalizedTime.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR_MIN, null, 0, TimeZoneFormat.Z ); assertEquals( "200801021213Z", result ); result = generalizedTime.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR, null, 0, TimeZoneFormat.Z ); assertEquals( "2008010212Z", result ); result = generalizedTime.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR_MIN, null, 0, TimeZoneFormat.DIFF_HOUR_MINUTE ); assertEquals( "200801021213+0000", result ); result = generalizedTime.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR, null, 0, TimeZoneFormat.DIFF_HOUR_MINUTE ); assertEquals( "2008010212+0000", result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testApplyRemoveModificationFromEntryAttributeNotSameValue() throws LdapException { Entry entry = new DefaultEntry(); Attribute cn = new DefaultAttribute( "cn", "apache" ); entry.put( cn ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); assertEquals( cn, entry.get( "cn" ) ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyRemoveModificationFromEntrySameAttributeSameValue() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "test" ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNull( entry.get( "cn" ) ); assertEquals( 0, entry.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyRemoveModificationFromEntrySameAttributeValues() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "test", "apache" ); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); Attribute modifiedAttr = entry.get( "cn" ); assertTrue( modifiedAttr.size() != 0 ); boolean isFirst = true; for ( Value value : modifiedAttr ) { assertTrue( isFirst ); isFirst = false; assertEquals( "apache", value.getString() ); } } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyModifyModificationFromEmptyEntry() throws LdapException { Entry entry = new DefaultEntry(); Attribute attr = new DefaultAttribute( "cn", "test" ); Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNotNull( entry.get( "cn" ) ); assertEquals( 1, entry.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyModifyEmptyModificationFromEmptyEntry() throws LdapException { Entry entry = new DefaultEntry(); Attribute attr = new DefaultAttribute( "cn" ); Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, attr ); AttributeUtils.applyModification( entry, modification ); assertNull( entry.get( "cn" ) ); assertEquals( 0, entry.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyModifyAttributeModification() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "test" ); entry.put( "ou", "apache", "acme corp" ); Attribute newOu = new DefaultAttribute( "ou", "Big Company", "directory" ); Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, newOu ); AttributeUtils.applyModification( entry, modification ); assertEquals( 2, entry.size() ); assertNotNull( entry.get( "cn" ) ); assertNotNull( entry.get( "ou" ) ); Attribute modifiedAttr = entry.get( "ou" ); assertTrue( modifiedAttr.size() != 0 ); Set<String> expectedValues = new HashSet<String>(); expectedValues.add( "Big Company" ); expectedValues.add( "directory" ); for ( Value value : modifiedAttr ) { String valueStr = value.getString(); assertTrue( expectedValues.contains( valueStr ) ); expectedValues.remove( valueStr ); } assertEquals( 0, expectedValues.size() ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testApplyModifyModificationRemoveAttribute() throws LdapException { Entry entry = new DefaultEntry(); entry.put( "cn", "test" ); entry.put( "ou", "apache", "acme corp" ); Attribute newOu = new DefaultAttribute( "ou" ); Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, newOu ); AttributeUtils.applyModification( entry, modification ); assertEquals( 1, entry.size() ); assertNotNull( entry.get( "cn" ) ); assertNull( entry.get( "ou" ) ); } | public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } | AttributeUtils { public static void applyModification( Entry entry, Modification modification ) throws LdapException { Attribute modAttr = modification.getAttribute(); String modificationId = modAttr.getUpId(); switch ( modification.getOperation() ) { case ADD_ATTRIBUTE: Attribute modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { entry.put( modAttr ); } else { for ( Value value : modAttr ) { modifiedAttr.add( value ); } } break; case REMOVE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { modifiedAttr = entry.get( modificationId ); if ( modifiedAttr == null ) { break; } for ( Value value : modAttr ) { modifiedAttr.remove( value ); } if ( modifiedAttr.size() == 0 ) { entry.removeAttributes( modifiedAttr.getUpId() ); } } break; case REPLACE_ATTRIBUTE: if ( modAttr.get() == null ) { entry.removeAttributes( modificationId ); } else { entry.put( modAttr ); } break; default: break; } } private AttributeUtils(); static boolean containsValueCaseIgnore( javax.naming.directory.Attribute attr, Object value ); static Attributes toCaseInsensitive( Attributes attributes ); static String parseAttribute( char[] str, Position pos, boolean withOption, boolean relaxed ); static String parseAttribute( byte[] bytes, Position pos, boolean withOption, boolean relaxed ); static void applyModification( Entry entry, Modification modification ); static Entry toEntry( Attributes attributes, Dn dn ); static Attributes toAttributes( Entry entry ); static javax.naming.directory.Attribute toJndiAttribute( Attribute attribute ); static Attribute toApiAttribute( javax.naming.directory.Attribute jndiAttribute ); } |
@Test public void testUnique() { int replicaId = 001; CsnFactory defaultCSNFactory = new CsnFactory( replicaId ); Csn[] csns = new Csn[NUM_GENERATES]; for ( int i = 0; i < NUM_GENERATES; i++ ) { csns[i] = defaultCSNFactory.newInstance(); } for ( int i = 0; i < NUM_GENERATES; i++ ) { for ( int j = i + 1; j < NUM_GENERATES; j++ ) { assertFalse( csns[i].equals( csns[j] ) ); } } } | public Csn newInstance() { int tmpChangeCount; synchronized ( lock ) { long newTimestamp = System.currentTimeMillis(); if ( lastTimestamp == newTimestamp ) { changeCount++; } else { lastTimestamp = newTimestamp; changeCount = 0; } tmpChangeCount = changeCount; } return new Csn( lastTimestamp, tmpChangeCount, replicaId, 0 ); } | CsnFactory { public Csn newInstance() { int tmpChangeCount; synchronized ( lock ) { long newTimestamp = System.currentTimeMillis(); if ( lastTimestamp == newTimestamp ) { changeCount++; } else { lastTimestamp = newTimestamp; changeCount = 0; } tmpChangeCount = changeCount; } return new Csn( lastTimestamp, tmpChangeCount, replicaId, 0 ); } } | CsnFactory { public Csn newInstance() { int tmpChangeCount; synchronized ( lock ) { long newTimestamp = System.currentTimeMillis(); if ( lastTimestamp == newTimestamp ) { changeCount++; } else { lastTimestamp = newTimestamp; changeCount = 0; } tmpChangeCount = changeCount; } return new Csn( lastTimestamp, tmpChangeCount, replicaId, 0 ); } CsnFactory( int replicaId ); } | CsnFactory { public Csn newInstance() { int tmpChangeCount; synchronized ( lock ) { long newTimestamp = System.currentTimeMillis(); if ( lastTimestamp == newTimestamp ) { changeCount++; } else { lastTimestamp = newTimestamp; changeCount = 0; } tmpChangeCount = changeCount; } return new Csn( lastTimestamp, tmpChangeCount, replicaId, 0 ); } CsnFactory( int replicaId ); Csn newInstance(); Csn newInstance( long timestamp, int changeCount ); Csn newPurgeCsn( long expirationDate ); void setReplicaId( int replicaId ); } | CsnFactory { public Csn newInstance() { int tmpChangeCount; synchronized ( lock ) { long newTimestamp = System.currentTimeMillis(); if ( lastTimestamp == newTimestamp ) { changeCount++; } else { lastTimestamp = newTimestamp; changeCount = 0; } tmpChangeCount = changeCount; } return new Csn( lastTimestamp, tmpChangeCount, replicaId, 0 ); } CsnFactory( int replicaId ); Csn newInstance(); Csn newInstance( long timestamp, int changeCount ); Csn newPurgeCsn( long expirationDate ); void setReplicaId( int replicaId ); } |
@Test public void testCSN() { synchronized ( SDF ) { long ts = System.currentTimeMillis(); Csn csn = new Csn( SDF.format( new Date( ts ) ) + "#123456#abc#654321" ); assertEquals( ts / 1000, csn.getTimestamp() / 1000 ); assertEquals( 1193046, csn.getChangeCount() ); assertEquals( 6636321, csn.getOperationNumber() ); assertEquals( 2748, csn.getReplicaId() ); } } | public Csn( long timestamp, int changeCount, int replicaId, int operationNumber ) { this.timestamp = timestamp; this.replicaId = replicaId; this.operationNumber = operationNumber; this.changeCount = changeCount; sdf.setTimeZone( UTC_TIME_ZONE ); } | Csn implements Comparable<Csn> { public Csn( long timestamp, int changeCount, int replicaId, int operationNumber ) { this.timestamp = timestamp; this.replicaId = replicaId; this.operationNumber = operationNumber; this.changeCount = changeCount; sdf.setTimeZone( UTC_TIME_ZONE ); } } | Csn implements Comparable<Csn> { public Csn( long timestamp, int changeCount, int replicaId, int operationNumber ) { this.timestamp = timestamp; this.replicaId = replicaId; this.operationNumber = operationNumber; this.changeCount = changeCount; sdf.setTimeZone( UTC_TIME_ZONE ); } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); } | Csn implements Comparable<Csn> { public Csn( long timestamp, int changeCount, int replicaId, int operationNumber ) { this.timestamp = timestamp; this.replicaId = replicaId; this.operationNumber = operationNumber; this.changeCount = changeCount; sdf.setTimeZone( UTC_TIME_ZONE ); } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); static boolean isValid( String value ); byte[] getBytes(); long getTimestamp(); int getChangeCount(); int getReplicaId(); int getOperationNumber(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object o ); @Override int compareTo( Csn csn ); } | Csn implements Comparable<Csn> { public Csn( long timestamp, int changeCount, int replicaId, int operationNumber ) { this.timestamp = timestamp; this.replicaId = replicaId; this.operationNumber = operationNumber; this.changeCount = changeCount; sdf.setTimeZone( UTC_TIME_ZONE ); } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); static boolean isValid( String value ); byte[] getBytes(); long getTimestamp(); int getChangeCount(); int getReplicaId(); int getOperationNumber(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object o ); @Override int compareTo( Csn csn ); } |
@Test public void testIsValidCsn() { assertTrue( Csn.isValid( "20100111202217.914000Z#000000#000#000000" ) ); } | public static boolean isValid( String value ) { if ( Strings.isEmpty( value ) ) { return false; } char[] chars = value.toCharArray(); if ( chars.length != 40 ) { return false; } for ( int pos = 0; pos < 4; pos++ ) { if ( !Chars.isDigit( chars[pos] ) ) { return false; } } switch ( chars[4] ) { case '0' : if ( !Chars.isDigit( chars[5] ) ) { return false; } if ( chars[5] == '0' ) { return false; } break; case '1' : if ( ( chars[5] != '0' ) && ( chars[5] != '1' ) && ( chars[5] != '2' ) ) { return false; } break; default : return false; } switch ( chars[6] ) { case '0' : if ( !Chars.isDigit( chars[7] ) ) { return false; } if ( chars[7] == '0' ) { return false; } break; case '1' : case '2' : if ( !Chars.isDigit( chars[7] ) ) { return false; } break; case '3' : if ( ( chars[7] != '0' ) && ( chars[7] != '1' ) ) { return false; } break; default : return false; } switch ( chars[8] ) { case '0' : case '1' : if ( !Chars.isDigit( chars[9] ) ) { return false; } break; case '2' : if ( ( chars[9] != '0' ) && ( chars[9] != '1' ) && ( chars[9] != '2' ) && ( chars[9] != '3' ) ) { return false; } break; default : return false; } switch ( chars[10] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[11] ) ) { return false; } switch ( chars[12] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[13] ) ) { return false; } if ( chars[14] != '.' ) { return false; } for ( int i = 0; i < 6; i++ ) { if ( !Chars.isDigit( chars[15 + i] ) ) { return false; } } if ( chars[21] != 'Z' ) { return false; } if ( chars[22] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[23] ) || !Chars.isHex( ( byte ) chars[24] ) || !Chars.isHex( ( byte ) chars[25] ) || !Chars.isHex( ( byte ) chars[26] ) || !Chars.isHex( ( byte ) chars[27] ) || !Chars.isHex( ( byte ) chars[28] ) ) { return false; } if ( chars[29] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[30] ) || !Chars.isHex( ( byte ) chars[31] ) || !Chars.isHex( ( byte ) chars[32] ) ) { return false; } if ( chars[33] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[34] ) || !Chars.isHex( ( byte ) chars[35] ) || !Chars.isHex( ( byte ) chars[36] ) || !Chars.isHex( ( byte ) chars[37] ) || !Chars.isHex( ( byte ) chars[38] ) || !Chars.isHex( ( byte ) chars[39] ) ) { return false; } return true; } | Csn implements Comparable<Csn> { public static boolean isValid( String value ) { if ( Strings.isEmpty( value ) ) { return false; } char[] chars = value.toCharArray(); if ( chars.length != 40 ) { return false; } for ( int pos = 0; pos < 4; pos++ ) { if ( !Chars.isDigit( chars[pos] ) ) { return false; } } switch ( chars[4] ) { case '0' : if ( !Chars.isDigit( chars[5] ) ) { return false; } if ( chars[5] == '0' ) { return false; } break; case '1' : if ( ( chars[5] != '0' ) && ( chars[5] != '1' ) && ( chars[5] != '2' ) ) { return false; } break; default : return false; } switch ( chars[6] ) { case '0' : if ( !Chars.isDigit( chars[7] ) ) { return false; } if ( chars[7] == '0' ) { return false; } break; case '1' : case '2' : if ( !Chars.isDigit( chars[7] ) ) { return false; } break; case '3' : if ( ( chars[7] != '0' ) && ( chars[7] != '1' ) ) { return false; } break; default : return false; } switch ( chars[8] ) { case '0' : case '1' : if ( !Chars.isDigit( chars[9] ) ) { return false; } break; case '2' : if ( ( chars[9] != '0' ) && ( chars[9] != '1' ) && ( chars[9] != '2' ) && ( chars[9] != '3' ) ) { return false; } break; default : return false; } switch ( chars[10] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[11] ) ) { return false; } switch ( chars[12] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[13] ) ) { return false; } if ( chars[14] != '.' ) { return false; } for ( int i = 0; i < 6; i++ ) { if ( !Chars.isDigit( chars[15 + i] ) ) { return false; } } if ( chars[21] != 'Z' ) { return false; } if ( chars[22] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[23] ) || !Chars.isHex( ( byte ) chars[24] ) || !Chars.isHex( ( byte ) chars[25] ) || !Chars.isHex( ( byte ) chars[26] ) || !Chars.isHex( ( byte ) chars[27] ) || !Chars.isHex( ( byte ) chars[28] ) ) { return false; } if ( chars[29] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[30] ) || !Chars.isHex( ( byte ) chars[31] ) || !Chars.isHex( ( byte ) chars[32] ) ) { return false; } if ( chars[33] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[34] ) || !Chars.isHex( ( byte ) chars[35] ) || !Chars.isHex( ( byte ) chars[36] ) || !Chars.isHex( ( byte ) chars[37] ) || !Chars.isHex( ( byte ) chars[38] ) || !Chars.isHex( ( byte ) chars[39] ) ) { return false; } return true; } } | Csn implements Comparable<Csn> { public static boolean isValid( String value ) { if ( Strings.isEmpty( value ) ) { return false; } char[] chars = value.toCharArray(); if ( chars.length != 40 ) { return false; } for ( int pos = 0; pos < 4; pos++ ) { if ( !Chars.isDigit( chars[pos] ) ) { return false; } } switch ( chars[4] ) { case '0' : if ( !Chars.isDigit( chars[5] ) ) { return false; } if ( chars[5] == '0' ) { return false; } break; case '1' : if ( ( chars[5] != '0' ) && ( chars[5] != '1' ) && ( chars[5] != '2' ) ) { return false; } break; default : return false; } switch ( chars[6] ) { case '0' : if ( !Chars.isDigit( chars[7] ) ) { return false; } if ( chars[7] == '0' ) { return false; } break; case '1' : case '2' : if ( !Chars.isDigit( chars[7] ) ) { return false; } break; case '3' : if ( ( chars[7] != '0' ) && ( chars[7] != '1' ) ) { return false; } break; default : return false; } switch ( chars[8] ) { case '0' : case '1' : if ( !Chars.isDigit( chars[9] ) ) { return false; } break; case '2' : if ( ( chars[9] != '0' ) && ( chars[9] != '1' ) && ( chars[9] != '2' ) && ( chars[9] != '3' ) ) { return false; } break; default : return false; } switch ( chars[10] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[11] ) ) { return false; } switch ( chars[12] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[13] ) ) { return false; } if ( chars[14] != '.' ) { return false; } for ( int i = 0; i < 6; i++ ) { if ( !Chars.isDigit( chars[15 + i] ) ) { return false; } } if ( chars[21] != 'Z' ) { return false; } if ( chars[22] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[23] ) || !Chars.isHex( ( byte ) chars[24] ) || !Chars.isHex( ( byte ) chars[25] ) || !Chars.isHex( ( byte ) chars[26] ) || !Chars.isHex( ( byte ) chars[27] ) || !Chars.isHex( ( byte ) chars[28] ) ) { return false; } if ( chars[29] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[30] ) || !Chars.isHex( ( byte ) chars[31] ) || !Chars.isHex( ( byte ) chars[32] ) ) { return false; } if ( chars[33] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[34] ) || !Chars.isHex( ( byte ) chars[35] ) || !Chars.isHex( ( byte ) chars[36] ) || !Chars.isHex( ( byte ) chars[37] ) || !Chars.isHex( ( byte ) chars[38] ) || !Chars.isHex( ( byte ) chars[39] ) ) { return false; } return true; } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); } | Csn implements Comparable<Csn> { public static boolean isValid( String value ) { if ( Strings.isEmpty( value ) ) { return false; } char[] chars = value.toCharArray(); if ( chars.length != 40 ) { return false; } for ( int pos = 0; pos < 4; pos++ ) { if ( !Chars.isDigit( chars[pos] ) ) { return false; } } switch ( chars[4] ) { case '0' : if ( !Chars.isDigit( chars[5] ) ) { return false; } if ( chars[5] == '0' ) { return false; } break; case '1' : if ( ( chars[5] != '0' ) && ( chars[5] != '1' ) && ( chars[5] != '2' ) ) { return false; } break; default : return false; } switch ( chars[6] ) { case '0' : if ( !Chars.isDigit( chars[7] ) ) { return false; } if ( chars[7] == '0' ) { return false; } break; case '1' : case '2' : if ( !Chars.isDigit( chars[7] ) ) { return false; } break; case '3' : if ( ( chars[7] != '0' ) && ( chars[7] != '1' ) ) { return false; } break; default : return false; } switch ( chars[8] ) { case '0' : case '1' : if ( !Chars.isDigit( chars[9] ) ) { return false; } break; case '2' : if ( ( chars[9] != '0' ) && ( chars[9] != '1' ) && ( chars[9] != '2' ) && ( chars[9] != '3' ) ) { return false; } break; default : return false; } switch ( chars[10] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[11] ) ) { return false; } switch ( chars[12] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[13] ) ) { return false; } if ( chars[14] != '.' ) { return false; } for ( int i = 0; i < 6; i++ ) { if ( !Chars.isDigit( chars[15 + i] ) ) { return false; } } if ( chars[21] != 'Z' ) { return false; } if ( chars[22] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[23] ) || !Chars.isHex( ( byte ) chars[24] ) || !Chars.isHex( ( byte ) chars[25] ) || !Chars.isHex( ( byte ) chars[26] ) || !Chars.isHex( ( byte ) chars[27] ) || !Chars.isHex( ( byte ) chars[28] ) ) { return false; } if ( chars[29] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[30] ) || !Chars.isHex( ( byte ) chars[31] ) || !Chars.isHex( ( byte ) chars[32] ) ) { return false; } if ( chars[33] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[34] ) || !Chars.isHex( ( byte ) chars[35] ) || !Chars.isHex( ( byte ) chars[36] ) || !Chars.isHex( ( byte ) chars[37] ) || !Chars.isHex( ( byte ) chars[38] ) || !Chars.isHex( ( byte ) chars[39] ) ) { return false; } return true; } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); static boolean isValid( String value ); byte[] getBytes(); long getTimestamp(); int getChangeCount(); int getReplicaId(); int getOperationNumber(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object o ); @Override int compareTo( Csn csn ); } | Csn implements Comparable<Csn> { public static boolean isValid( String value ) { if ( Strings.isEmpty( value ) ) { return false; } char[] chars = value.toCharArray(); if ( chars.length != 40 ) { return false; } for ( int pos = 0; pos < 4; pos++ ) { if ( !Chars.isDigit( chars[pos] ) ) { return false; } } switch ( chars[4] ) { case '0' : if ( !Chars.isDigit( chars[5] ) ) { return false; } if ( chars[5] == '0' ) { return false; } break; case '1' : if ( ( chars[5] != '0' ) && ( chars[5] != '1' ) && ( chars[5] != '2' ) ) { return false; } break; default : return false; } switch ( chars[6] ) { case '0' : if ( !Chars.isDigit( chars[7] ) ) { return false; } if ( chars[7] == '0' ) { return false; } break; case '1' : case '2' : if ( !Chars.isDigit( chars[7] ) ) { return false; } break; case '3' : if ( ( chars[7] != '0' ) && ( chars[7] != '1' ) ) { return false; } break; default : return false; } switch ( chars[8] ) { case '0' : case '1' : if ( !Chars.isDigit( chars[9] ) ) { return false; } break; case '2' : if ( ( chars[9] != '0' ) && ( chars[9] != '1' ) && ( chars[9] != '2' ) && ( chars[9] != '3' ) ) { return false; } break; default : return false; } switch ( chars[10] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[11] ) ) { return false; } switch ( chars[12] ) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : break; default : return false; } if ( !Chars.isDigit( chars[13] ) ) { return false; } if ( chars[14] != '.' ) { return false; } for ( int i = 0; i < 6; i++ ) { if ( !Chars.isDigit( chars[15 + i] ) ) { return false; } } if ( chars[21] != 'Z' ) { return false; } if ( chars[22] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[23] ) || !Chars.isHex( ( byte ) chars[24] ) || !Chars.isHex( ( byte ) chars[25] ) || !Chars.isHex( ( byte ) chars[26] ) || !Chars.isHex( ( byte ) chars[27] ) || !Chars.isHex( ( byte ) chars[28] ) ) { return false; } if ( chars[29] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[30] ) || !Chars.isHex( ( byte ) chars[31] ) || !Chars.isHex( ( byte ) chars[32] ) ) { return false; } if ( chars[33] != '#' ) { return false; } if ( !Chars.isHex( ( byte ) chars[34] ) || !Chars.isHex( ( byte ) chars[35] ) || !Chars.isHex( ( byte ) chars[36] ) || !Chars.isHex( ( byte ) chars[37] ) || !Chars.isHex( ( byte ) chars[38] ) || !Chars.isHex( ( byte ) chars[39] ) ) { return false; } return true; } Csn( long timestamp, int changeCount, int replicaId, int operationNumber ); Csn( String value ); Csn( byte[] value ); static boolean isValid( String value ); byte[] getBytes(); long getTimestamp(); int getChangeCount(); int getReplicaId(); int getOperationNumber(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object o ); @Override int compareTo( Csn csn ); } |
@Test public void testAdjustWhileFormatting() throws ParseException { String gt = "20080102121314+0130"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); result = generalizedTime.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR_MIN_SEC, null, 0, TimeZoneFormat.Z ); assertEquals( "20080102104314Z", result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testEmptyList() throws Exception { ListCursor<String> cursor = new ListCursor<String>(); cursor.close(); assertClosed( cursor, "cursor.isClosed() should return true after closing the cursor", true ); } | @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } |
@Test public void testSingleElementList() throws Exception { ListCursor<String> cursor = new ListCursor<String>( Collections.singletonList( "singleton" ) ); cursor.close(); assertClosed( cursor, "cursor.isClosed() should return true after closing the cursor", true ); try { cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 0 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( 1, Collections.singletonList( "singleton" ) ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( 5, Collections.singletonList( "singleton" ) ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), -5 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( -5, Collections.singletonList( "singleton" ) ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( Collections.singletonList( "singleton" ), 5 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } } | @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } |
@Test public void testManyElementList() throws Exception { List<String> list = new ArrayList<String>(); list.add( "item 1" ); list.add( "item 2" ); list.add( "item 3" ); list.add( "item 4" ); list.add( "item 5" ); ListCursor<String> cursor = new ListCursor<String>( list ); cursor.close(); cursor = new ListCursor<String>( 1, list ); cursor.close(); cursor = new ListCursor<String>( 1, list, 4 ); cursor.close(); assertClosed( cursor, "cursor.isClosed() should return true after closing the cursor", true ); try { cursor = new ListCursor<String>( list, 0 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( 5, list ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( 10, list ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( list, -5 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( -5, list ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } try { cursor = new ListCursor<String>( list, 10 ); cursor.close(); fail( "when the start = end bounds this is senseless and should complain" ); } catch ( IllegalArgumentException e ) { assertNotNull( e ); } } | @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } | ListCursor extends AbstractCursor<E> { @Override public void close() throws IOException { if ( LOG_CURSOR.isDebugEnabled() ) { LOG_CURSOR.debug( I18n.msg( I18n.MSG_13101_CLOSING_LIST_CURSOR, this ) ); } super.close(); } ListCursor( Comparator<E> comparator, int start, List<E> list, int end ); ListCursor( int start, List<E> list, int end ); ListCursor( List<E> list, int end ); ListCursor( Comparator<E> comparator, List<E> list, int end ); ListCursor( int start, List<E> list ); ListCursor( Comparator<E> comparator, int start, List<E> list ); ListCursor( List<E> list ); ListCursor( Comparator<E> comparator, List<E> list ); @SuppressWarnings("unchecked") ListCursor(); @SuppressWarnings("unchecked") ListCursor( Comparator<E> comparator ); @Override boolean available(); @Override void before( E element ); @Override void after( E element ); @Override void beforeFirst(); @Override void afterLast(); @Override boolean first(); @Override boolean last(); @Override boolean isFirst(); @Override boolean isLast(); @Override boolean isAfterLast(); @Override boolean isBeforeFirst(); @Override boolean previous(); @Override boolean next(); @Override E get(); @Override void close(); @Override void close( Exception cause ); } |
@Test public void testNullCSNs() { assertEquals( 0, comparator.compare( null, null ) ); Csn csn2 = new Csn( System.currentTimeMillis(), 1, 1, 1 ); assertEquals( -1, comparator.compare( null, csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), null ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testEqualsCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 0, 0 ); assertEquals( 0, comparator.compare( csn1.toString(), csn2.toString() ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testDifferentTimeStampCSNs() { long t0 = System.currentTimeMillis(); long t1 = System.currentTimeMillis() + 1000; Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t1, 0, 0, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testDifferentChangeCountCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 1, 0, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testDifferentReplicaIdCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 1, 0 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testDifferentOperationNumberCSNs() { long t0 = System.currentTimeMillis(); Csn csn1 = new Csn( t0, 0, 0, 0 ); Csn csn2 = new Csn( t0, 0, 0, 1 ); assertEquals( -1, comparator.compare( csn1.toString(), csn2.toString() ) ); assertEquals( 1, comparator.compare( csn2.toString(), csn1.toString() ) ); } | @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } | CsnComparator extends LdapComparator<Object> { @Override public int compare( Object csnObj1, Object csnObj2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13745_COMPARING_CSN, csnObj1, csnObj2 ) ); } if ( csnObj1 == csnObj2 ) { return 0; } if ( csnObj1 == null ) { return -1; } if ( csnObj2 == null ) { return 1; } String csnStr1; String csnStr2; if ( csnObj1 instanceof Value ) { csnStr1 = ( ( Value ) csnObj1 ).getString(); } else { csnStr1 = csnObj1.toString(); } if ( csnObj2 instanceof Value ) { csnStr2 = ( ( Value ) csnObj2 ).getString(); } else { csnStr2 = csnObj2.toString(); } return csnStr1.compareTo( csnStr2 ); } CsnComparator( String oid ); @Override int compare( Object csnObj1, Object csnObj2 ); } |
@Test public void testNullIntegers() { assertEquals( 0, comparator.compare( null, null ) ); String int1 = "1"; assertEquals( -1, comparator.compare( ( String ) null, int1 ) ); assertEquals( 1, comparator.compare( int1, ( String ) null ) ); } | @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); @Override int compare( Object v1, Object v2 ); } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); @Override int compare( Object v1, Object v2 ); } |
@Test public void testFebruary29inLeapYear() throws ParseException { String gt = "20080229000000Z"; GeneralizedTime generalizedTime = new GeneralizedTime( gt ); String result = generalizedTime.toGeneralizedTime(); assertEquals( gt, result ); } | public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } | GeneralizedTime implements Comparable<GeneralizedTime> { public String toGeneralizedTime() { return toGeneralizedTime( upFormat, upFractionDelimiter, upFractionLength, upTimeZoneFormat ); } GeneralizedTime( Date date ); GeneralizedTime( Calendar calendar ); GeneralizedTime( long timeInMillis ); GeneralizedTime( String generalizedTime ); String toGeneralizedTime(); String toGeneralizedTimeWithoutFraction(); String toGeneralizedTime( Format format, FractionDelimiter fractionDelimiter, int fractionLength,
TimeZoneFormat timeZoneFormat ); Calendar getCalendar(); @Override String toString(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override int compareTo( GeneralizedTime other ); long getTime(); Date getDate(); int getYear(); int getMonth(); int getDay(); int getHour(); int getMinutes(); int getSeconds(); int getFraction(); static Date getDate( String zuluTime ); } |
@Test public void testBigIntegerValues() { assertEquals( -1, comparator.compare( null, "1000000000000000000000000" ) ); assertEquals( 1, comparator.compare( "1000000000000000000000000", null ) ); assertEquals( 0, comparator.compare( "1000000000000000000000000", "1000000000000000000000000" ) ); long t0 = System.currentTimeMillis(); for ( int i = 0; i < 10000000; i++ ) { assertEquals( -1, comparator.compare( "9223372036854775805", "9223372036854775806" ) ); } long t1 = System.currentTimeMillis(); System.out.println( "Delta = " + ( t1 - t0 ) ); assertEquals( 1, comparator.compare( "1000000000000000000000001", "1000000000000000000000000" ) ); } | @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); @Override int compare( Object v1, Object v2 ); } | IntegerComparator extends LdapComparator<Object> implements Serializable { @Override public int compare( Object v1, Object v2 ) { if ( v1 == null ) { if ( v2 == null ) { return 0; } else { return -1; } } else if ( v2 == null ) { return 1; } if ( v1 instanceof String ) { return compare( ( String ) v1, ( String ) v2 ); } else if ( v1 instanceof Value ) { return compare( ( ( Value ) v1 ).getString(), ( ( Value ) v2 ).getString() ); } else { return Long.compare( ( Long ) v1, ( Long ) v2 ); } } IntegerComparator( String oid ); @Override int compare( Object v1, Object v2 ); } |
@Test public void testNullSids() { assertEquals( 0, comparator.compare( null, null ) ); assertEquals( -1, comparator.compare( null, "000" ) ); assertEquals( 1, comparator.compare( "000", null ) ); } | public int compare( String sidStr1, String sidStr2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) ); } if ( sidStr1 == null ) { return ( sidStr2 == null ) ? 0 : -1; } if ( sidStr2 == null ) { return 1; } int sid1 = 0; int sid2; try { sid1 = Integer.parseInt( sidStr1, 16 ); } catch ( NumberFormatException nfe ) { return -1; } try { sid2 = Integer.parseInt( sidStr2, 16 ); } catch ( NumberFormatException nfe ) { return 1; } if ( sid1 > sid2 ) { return 1; } else if ( sid2 > sid1 ) { return -1; } return 0; } | CsnSidComparator extends LdapComparator<String> { public int compare( String sidStr1, String sidStr2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) ); } if ( sidStr1 == null ) { return ( sidStr2 == null ) ? 0 : -1; } if ( sidStr2 == null ) { return 1; } int sid1 = 0; int sid2; try { sid1 = Integer.parseInt( sidStr1, 16 ); } catch ( NumberFormatException nfe ) { return -1; } try { sid2 = Integer.parseInt( sidStr2, 16 ); } catch ( NumberFormatException nfe ) { return 1; } if ( sid1 > sid2 ) { return 1; } else if ( sid2 > sid1 ) { return -1; } return 0; } } | CsnSidComparator extends LdapComparator<String> { public int compare( String sidStr1, String sidStr2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) ); } if ( sidStr1 == null ) { return ( sidStr2 == null ) ? 0 : -1; } if ( sidStr2 == null ) { return 1; } int sid1 = 0; int sid2; try { sid1 = Integer.parseInt( sidStr1, 16 ); } catch ( NumberFormatException nfe ) { return -1; } try { sid2 = Integer.parseInt( sidStr2, 16 ); } catch ( NumberFormatException nfe ) { return 1; } if ( sid1 > sid2 ) { return 1; } else if ( sid2 > sid1 ) { return -1; } return 0; } CsnSidComparator( String oid ); } | CsnSidComparator extends LdapComparator<String> { public int compare( String sidStr1, String sidStr2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) ); } if ( sidStr1 == null ) { return ( sidStr2 == null ) ? 0 : -1; } if ( sidStr2 == null ) { return 1; } int sid1 = 0; int sid2; try { sid1 = Integer.parseInt( sidStr1, 16 ); } catch ( NumberFormatException nfe ) { return -1; } try { sid2 = Integer.parseInt( sidStr2, 16 ); } catch ( NumberFormatException nfe ) { return 1; } if ( sid1 > sid2 ) { return 1; } else if ( sid2 > sid1 ) { return -1; } return 0; } CsnSidComparator( String oid ); int compare( String sidStr1, String sidStr2 ); } | CsnSidComparator extends LdapComparator<String> { public int compare( String sidStr1, String sidStr2 ) { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13744_COMPARING_CSN_SID, sidStr1, sidStr2 ) ); } if ( sidStr1 == null ) { return ( sidStr2 == null ) ? 0 : -1; } if ( sidStr2 == null ) { return 1; } int sid1 = 0; int sid2; try { sid1 = Integer.parseInt( sidStr1, 16 ); } catch ( NumberFormatException nfe ) { return -1; } try { sid2 = Integer.parseInt( sidStr2, 16 ); } catch ( NumberFormatException nfe ) { return 1; } if ( sid1 > sid2 ) { return 1; } else if ( sid2 > sid1 ) { return -1; } return 0; } CsnSidComparator( String oid ); int compare( String sidStr1, String sidStr2 ); } |
Subsets and Splits