当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.clear方法代码示例

本文整理汇总了Java中org.apache.directory.api.ldap.model.entry.Attribute.clear方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.clear方法的具体用法?Java Attribute.clear怎么用?Java Attribute.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.directory.api.ldap.model.entry.Attribute的用法示例。


在下文中一共展示了Attribute.clear方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClear

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method clear()
 */
@Test
public void testClear() throws LdapException
{
    Attribute attr = new DefaultAttribute( "email", atEMail );

    assertEquals( 0, attr.size() );

    attr.add( ( String ) null, "a", "b" );
    assertEquals( 3, attr.size() );

    attr.clear();
    assertTrue( attr.isHumanReadable() );
    assertEquals( 0, attr.size() );
    assertEquals( atEMail, attr.getAttributeType() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:19,代码来源:SchemaAwareAttributeTest.java

示例2: testToString

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method toString
 */
@Test
public void testToString() throws LdapException
{
    Attribute attr = new DefaultAttribute( atEMail );

    assertEquals( "email: (null)", attr.toString() );

    attr.setUpId( "EMail" );
    assertEquals( "EMail: (null)", attr.toString() );

    attr.add( ( String ) null );
    assertEquals( "EMail: ''", attr.toString() );

    attr.clear();
    attr.add( "a", "b" );
    assertEquals( "EMail: a\nEMail: b", attr.toString() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:21,代码来源:SchemaAwareAttributeTest.java

示例3: testIsValid

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method isValid()
 */
@Test
public void testIsValid() throws Exception
{
    Attribute attr = new DefaultAttribute( atCN );

    // No value, this should not be valid
    assertFalse( attr.isValid( atCN ) );

    attr.add( "test", "test2", "A123\\;" );
    assertTrue( attr.isValid( atCN ) );

    // If we try to add a wrong value, it will not be added. The
    // attribute remains valid.
    assertEquals( 0, attr.add( new byte[]
        { 0x01 } ) );
    assertTrue( attr.isValid( atCN ) );

    // test a SINGLE-VALUE attribute. CountryName is SINGLE-VALUE
    attr.clear();
    attr.apply( atC );
    attr.add( "FR" );
    assertTrue( attr.isValid( atC ) );
    assertEquals( 0, attr.add( "US" ) );
    assertFalse( attr.contains( "US" ) );
    assertTrue( attr.isValid( atC ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:30,代码来源:SchemaAwareAttributeTest.java

示例4: testIterator2

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method getAll()
 */
@Test
public void testIterator2() throws LdapException
{
    Attribute attr = new DefaultAttribute( atEMail );

    Iterator<Value> iterator = attr.iterator();
    assertFalse( iterator.hasNext() );

    attr.add( nullStringValue );
    iterator = attr.iterator();
    assertTrue( iterator.hasNext() );

    Value value = iterator.next();
    assertEquals( nullStringValue, value );

    attr.clear();
    iterator = attr.iterator();
    assertFalse( iterator.hasNext() );

    attr.add( "a", "b", "c" );
    iterator = attr.iterator();
    assertTrue( iterator.hasNext() );
    assertEquals( "a", iterator.next().getValue() );
    assertEquals( "b", iterator.next().getValue() );
    assertEquals( "c", iterator.next().getValue() );
    assertFalse( iterator.hasNext() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:31,代码来源:SchemaAwareAttributeTest.java

示例5: testSize

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method size()
 */
@Test
public void testSize() throws Exception
{
    Attribute attr1 = new DefaultAttribute( atDC );

    assertEquals( 0, attr1.size() );

    attr1.add( ( String ) null );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( atCN );

    attr2.add( "a", "b" );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    assertEquals( 0, attr2.size() );

    Attribute attr3 = new DefaultAttribute( atC );

    attr3.add( "US" );
    assertEquals( 1, attr3.size() );

    // TODO : forbid addition of more than 1 value for SINGLE-VALUE attributes
    attr3.add( "FR" );
    assertEquals( 1, attr3.size() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:31,代码来源:SchemaAwareAttributeTest.java

示例6: testRemoveByteArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method remove( byte... )
 */
@Test
public void testRemoveByteArray() throws Exception
{
    Attribute attr1 = new DefaultAttribute( atPwd );

    assertFalse( attr1.remove( BYTES1 ) );

    attr1.add( BYTES1, BYTES2, BYTES3 );
    assertTrue( attr1.remove( BYTES1 ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( BYTES2, BYTES3 ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( BYTES4 ) );

    attr1.clear();
    attr1.add( BYTES1, BYTES2, BYTES3 );
    assertFalse( attr1.remove( BYTES3, BYTES4 ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( BYTES1, ( byte[] ) null, BYTES2 );
    assertTrue( attr1.remove( ( byte[] ) null, BYTES1 ) );
    assertEquals( 1, attr1.size() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:30,代码来源:SchemaAwareAttributeTest.java

示例7: testRemoveStringArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method remove( String... )
 */
@Test
public void testRemoveStringArray() throws Exception
{
    Attribute attr1 = new DefaultAttribute( atEMail );

    assertFalse( attr1.remove( "a" ) );

    attr1.add( "a", "b", "c" );
    assertTrue( attr1.remove( "a" ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( "b", "c" ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( "d" ) );

    attr1.clear();
    attr1.add( "a", "b", "c" );
    assertFalse( attr1.remove( "b", "e" ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    assertTrue( attr1.remove( ( String ) null, "a" ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( "test" );

    attr2.add( BYTES1, BYTES2, BYTES3 );

    assertFalse( attr2.remove( ( String ) null ) );
    assertTrue( attr2.remove( "ab", "c" ) );
    assertFalse( attr2.remove( "d" ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:38,代码来源:SchemaAwareAttributeTest.java

示例8: testAddEntryAttributeArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method for add( EntryAttribute... )
 */
@Test
public void testAddEntryAttributeArray() throws LdapException
{
    Entry entry = createEntry();

    assertEquals( 4, entry.size() );
    assertTrue( entry.containsAttribute( "ObjectClass" ) );
    assertTrue( entry.containsAttribute( "CN" ) );
    assertTrue( entry.containsAttribute( "  sn  " ) );
    assertTrue( entry.containsAttribute( "userPassword" ) );

    Attribute attr = entry.get( "objectclass" );
    assertEquals( 2, attr.size() );

    Attribute attrCN2 = new DefaultAttribute( "cn", "test1", "test3" );
    entry.add( attrCN2 );
    assertEquals( 4, entry.size() );
    attr = entry.get( "cn" );
    assertEquals( 3, attr.size() );
    assertTrue( attr.contains( "test1", "test2", "test3" ) );

    // Check adding some byte[] values (they will not be transformed to Strings)
    attrCN2.clear();
    attrCN2.add( BYTES1, BYTES2 );
    entry.add( attrCN2 );
    assertEquals( 4, entry.size() );
    attr = entry.get( "cn" );
    assertEquals( 3, attr.size() );
    assertTrue( attr.contains( "test1", "test2", "test3" ) );
    assertFalse( attr.contains( "ab", "b" ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:35,代码来源:SchemaAwareEntryTest.java

示例9: testHashCode

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method hashCode()
 */
@Test
public void testHashCode() throws LdapException
{
    Attribute attr1 = new DefaultAttribute( atDC );
    Attribute attr2 = new DefaultAttribute( atSN );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    attr2.apply( atDC );
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    attr1.add( ( String ) null );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    attr1.clear();
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    attr1.add( "a", "b" );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    attr2.add( "a", "b" );
    assertEquals( attr1.hashCode(), attr2.hashCode() );

    // Order matters
    attr2.clear();
    attr2.add( "b", "a" );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    Attribute attr3 = new DefaultAttribute( atPwd );
    Attribute attr4 = new DefaultAttribute( atPwd );
    assertNotSame( attr3.hashCode(), attr4.hashCode() );

    attr3.add( ( byte[] ) null );
    assertNotSame( attr3.hashCode(), attr4.hashCode() );

    attr3.clear();
    assertEquals( attr3.hashCode(), attr4.hashCode() );

    attr3.add( new byte[]
        { 0x01, 0x02 }, new byte[]
        { 0x03, 0x04 } );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    attr4.add( new byte[]
        { 0x01, 0x02 }, new byte[]
        { 0x03, 0x04 } );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );

    // Order matters
    attr4.clear();
    attr4.add( new byte[]
        { 0x03, 0x04 }, new byte[]
        { 0x01, 0x02 } );
    assertNotSame( attr1.hashCode(), attr2.hashCode() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:58,代码来源:SchemaAwareAttributeTest.java

示例10: testPutByteArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method put( byte[]... )
 */
@Test
public void testPutByteArray() throws LdapException, Exception
{
    Attribute attr1 = new DefaultAttribute( atPwd );

    int nbAdded = attr1.add( ( byte[] ) null );
    assertEquals( 1, nbAdded );
    assertFalse( attr1.isHumanReadable() );
    assertTrue( Arrays.equals( nullBinaryValue.getBytes(), attr1.getBytes() ) );

    Attribute attr2 = new DefaultAttribute( atPwd );

    nbAdded = attr2.add( Strings.EMPTY_BYTES );
    assertEquals( 1, nbAdded );
    assertFalse( attr2.isHumanReadable() );
    assertTrue( Arrays.equals( Strings.EMPTY_BYTES, attr2.getBytes() ) );

    Attribute attr3 = new DefaultAttribute( atPwd );

    nbAdded = attr3.add( BYTES1 );
    assertEquals( 1, nbAdded );
    assertFalse( attr3.isHumanReadable() );
    assertTrue( Arrays.equals( BYTES1, attr3.getBytes() ) );

    Attribute attr4 = new DefaultAttribute( atPwd );

    nbAdded = attr4.add( BYTES1, BYTES2 );
    assertEquals( 2, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES1 ) );
    assertTrue( attr4.contains( BYTES2 ) );

    attr4.clear();
    nbAdded = attr4.add( BYTES3, BYTES4 );
    assertEquals( 2, nbAdded );
    assertFalse( attr4.isHumanReadable() );
    assertTrue( attr4.contains( BYTES3 ) );
    assertTrue( attr4.contains( BYTES4 ) );

    Attribute attr5 = new DefaultAttribute( atPwd );

    nbAdded = attr5.add( BYTES1, BYTES2, ( byte[] ) null, BYTES3 );
    assertEquals( 4, nbAdded );
    assertFalse( attr5.isHumanReadable() );
    assertTrue( attr5.contains( BYTES1 ) );
    assertTrue( attr5.contains( BYTES2 ) );
    assertTrue( attr5.contains( ( byte[] ) null ) );
    assertTrue( attr5.contains( BYTES3 ) );

    Attribute attr6 = new DefaultAttribute( atPwd );

    assertFalse( attr6.isHumanReadable() );
    nbAdded = attr6.add( BYTES1, ( byte[] ) null );
    assertEquals( 2, nbAdded );
    assertTrue( attr6.contains( BYTES1 ) );
    assertTrue( attr6.contains( ( byte[] ) null ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:61,代码来源:SchemaAwareAttributeTest.java

示例11: testPutStringArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method put( String... )
 */
@Test
public void testPutStringArray() throws LdapInvalidAttributeValueException
{
    Attribute attr1 = new DefaultAttribute( atDC );

    int nbAdded = attr1.add( ( String ) null );
    assertEquals( 1, nbAdded );
    assertTrue( attr1.isHumanReadable() );
    assertEquals( nullStringValue, attr1.get() );

    Attribute attr2 = new DefaultAttribute( atDC );

    nbAdded = attr2.add( "" );
    assertEquals( 1, nbAdded );
    assertTrue( attr2.isHumanReadable() );
    assertEquals( "", attr2.getString() );

    Attribute attr3 = new DefaultAttribute( atDC );

    nbAdded = attr3.add( "t" );
    assertEquals( 1, nbAdded );
    assertTrue( attr3.isHumanReadable() );
    assertEquals( "t", attr3.getString() );

    Attribute attr4 = new DefaultAttribute( atEMail );

    nbAdded = attr4.add( "a", "b", "c", "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertEquals( "a", attr4.getString() );
    assertTrue( attr4.contains( "a" ) );
    assertTrue( attr4.contains( "b" ) );
    assertTrue( attr4.contains( "c" ) );
    assertTrue( attr4.contains( "d" ) );

    attr4.clear();
    nbAdded = attr4.add( "e" );
    assertEquals( 1, nbAdded );
    assertTrue( attr4.isHumanReadable() );
    assertEquals( "e", attr4.getString() );
    assertFalse( attr4.contains( "a" ) );
    assertFalse( attr4.contains( "b" ) );
    assertFalse( attr4.contains( "c" ) );
    assertFalse( attr4.contains( "d" ) );
    assertTrue( attr4.contains( "e" ) );

    attr4.clear();
    nbAdded = attr4.add( BYTES1 );
    assertEquals( 0, nbAdded );
    assertTrue( attr4.isHumanReadable() );

    Attribute attr5 = new DefaultAttribute( atEMail );

    nbAdded = attr5.add( "a", "b", ( String ) null, "d" );
    assertEquals( 4, nbAdded );
    assertTrue( attr5.isHumanReadable() );
    assertTrue( attr5.contains( "a" ) );
    assertTrue( attr5.contains( "b" ) );
    assertTrue( attr5.contains( nullStringValue ) );
    assertTrue( attr5.contains( "d" ) );

    Attribute attr6 = new DefaultAttribute( atPwd );

    nbAdded = attr6.add( "a", ( String ) null );
    assertEquals( 2, nbAdded );
    assertFalse( attr6.isHumanReadable() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:71,代码来源:SchemaAwareAttributeTest.java

示例12: testPutValueArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method put( Value... )
 */
@Test
public void testPutValueArray() throws Exception
{
    Attribute attr1 = new DefaultAttribute( atDC );

    assertEquals( 0, attr1.size() );

    attr1.add( nullStringValue );
    assertEquals( 1, attr1.size() );
    assertTrue( attr1.contains( nullStringValue ) );

    attr1.clear();
    attr1.add( stringValue1, stringValue2, stringValue3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( stringValue1 ) );
    assertTrue( attr1.contains( stringValue2 ) );
    assertTrue( attr1.contains( stringValue3 ) );

    attr1.clear();
    attr1.add( stringValue1, nullStringValue, stringValue3 );
    assertEquals( 3, attr1.size() );
    assertTrue( attr1.contains( stringValue1 ) );
    assertTrue( attr1.contains( nullStringValue ) );
    assertTrue( attr1.contains( stringValue3 ) );

    attr1.clear();
    attr1.add( stringValue1, nullStringValue, binaryValue3 );
    assertEquals( 2, attr1.size() );
    assertTrue( attr1.contains( stringValue1 ) );
    assertTrue( attr1.contains( nullStringValue ) );
    assertFalse( attr1.contains( stringValue3 ) );

    Attribute attr2 = new DefaultAttribute( atPwd );
    assertEquals( 0, attr2.size() );

    attr2.add( nullBinaryValue );
    assertEquals( 1, attr2.size() );
    assertTrue( attr2.contains( nullBinaryValue ) );

    attr2.clear();
    attr2.add( binaryValue1, binaryValue2, binaryValue3 );
    assertEquals( 3, attr2.size() );
    assertTrue( attr2.contains( binaryValue1 ) );
    assertTrue( attr2.contains( binaryValue2 ) );
    assertTrue( attr2.contains( binaryValue3 ) );

    attr2.clear();
    attr2.add( binaryValue1, nullBinaryValue, stringValue3 );
    assertEquals( 2, attr2.size() );
    assertTrue( attr2.contains( binaryValue1 ) );
    assertTrue( attr2.contains( nullBinaryValue ) );
    assertFalse( attr2.contains( binaryValue3 ) );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:57,代码来源:SchemaAwareAttributeTest.java

示例13: testRemoveValueArray

import org.apache.directory.api.ldap.model.entry.Attribute; //导入方法依赖的package包/类
/**
 * Test method remove( Value... )
 */
@Test
public void testRemoveValueArray() throws Exception
{
    Attribute attr1 = new DefaultAttribute( atEMail );

    assertFalse( attr1.remove( stringValue1 ) );

    attr1.add( "a", "b", "c" );
    assertTrue( attr1.remove( stringValue1 ) );
    assertEquals( 2, attr1.size() );

    assertTrue( attr1.remove( stringValue2, stringValue3 ) );
    assertEquals( 0, attr1.size() );

    assertFalse( attr1.remove( stringValue4 ) );

    attr1.clear();
    attr1.add( "a", "b", "c" );
    assertFalse( attr1.remove( stringValue2, stringValue4 ) );
    assertEquals( 2, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    assertTrue( attr1.remove( nullStringValue, stringValue1 ) );
    assertEquals( 1, attr1.size() );

    attr1.clear();
    attr1.add( "a", ( String ) null, "b" );
    attr1.add( BYTES3 );
    assertFalse( attr1.remove( nullStringValue, stringValue1, binaryValue3 ) );
    assertEquals( 1, attr1.size() );

    Attribute attr2 = new DefaultAttribute( atPwd );

    assertFalse( attr2.remove( binaryValue1 ) );

    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertTrue( attr2.remove( binaryValue1 ) );
    assertEquals( 2, attr2.size() );

    assertTrue( attr2.remove( binaryValue2, binaryValue3 ) );
    assertEquals( 0, attr2.size() );

    assertFalse( attr2.remove( binaryValue4 ) );

    attr2.clear();
    attr2.add( BYTES1, BYTES2, BYTES3 );
    assertFalse( attr2.remove( binaryValue2, stringValue4 ) );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    attr2.add( BYTES1, ( byte[] ) null, BYTES3 );
    assertFalse( attr2.remove( nullStringValue, binaryValue1 ) );
    assertEquals( 2, attr2.size() );

    attr2.clear();
    attr2.add( BYTES1, ( byte[] ) null, BYTES2 );
    attr2.add( "c" );
    assertEquals( 4, attr2.size() );
    assertFalse( attr2.remove( nullStringValue, binaryValue1, stringValue3 ) );
    assertEquals( 3, attr2.size() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:66,代码来源:SchemaAwareAttributeTest.java


注:本文中的org.apache.directory.api.ldap.model.entry.Attribute.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。