org.apache.commons.beanutils.converters.ArrayConverter Java Examples

The following examples show how to use org.apache.commons.beanutils.converters.ArrayConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Matrix3IntConverter.java    From ServerCore with Apache License 2.0 6 votes vote down vote up
@Override
public int[][][] convert(String str) {
    if (str == null || str.isEmpty()) {
        return new int[0][][];
    }
    // 格式 1,2;3,4|5,6  =>  [[[1, 2], [3, 4]], [[5,6]]]
    IntegerConverter integerConverter = new IntegerConverter(); // 基本类型
    ArrayConverter arrayConverter1 = new ArrayConverter(int[].class, integerConverter); // 一维数组 默认使用逗号分割

    ArrayConverter arrayConverter2 = new ArrayConverter(int[][].class, arrayConverter1); // 二维数组
    arrayConverter2.setDelimiter(';'); // 使用分号分割
    arrayConverter2.setAllowedChars(new char[]{','});


    ArrayConverter arrayConverter3 = new ArrayConverter(int[][].class, arrayConverter2); // 二维数组
    arrayConverter3.setDelimiter('|'); // 使用竖线分割
    arrayConverter3.setAllowedChars(new char[]{';', ','});

    return arrayConverter3.convert(int[][][].class, str);
}
 
Example #2
Source File: Matrix3IntConverter.java    From GameServer with Apache License 2.0 6 votes vote down vote up
@Override
public int[][][] convert(String str) {
    if (str == null || str.isEmpty()) {
        return new int[0][][];
    }
    // 格式 1,2;3,4|5,6  =>  [[[1, 2], [3, 4]], [[5,6]]]
    // 基本类型
    IntegerConverter integerConverter = new IntegerConverter();
    // 一维数组 默认使用逗号分割
    ArrayConverter arrayConverter1 = new ArrayConverter(int[].class, integerConverter);

    // 二维数组
    ArrayConverter arrayConverter2 = new ArrayConverter(int[][].class, arrayConverter1);
    // 使用分号分割
    arrayConverter2.setDelimiter(';');
    arrayConverter2.setAllowedChars(new char[]{','});

    // 二维数组
    ArrayConverter arrayConverter3 = new ArrayConverter(int[][].class, arrayConverter2);
    // 使用竖线分割
    arrayConverter3.setDelimiter('|');
    arrayConverter3.setAllowedChars(new char[]{';', ','});

    return arrayConverter3.convert(int[][][].class, str);
}
 
Example #3
Source File: ToAliasBeanTest.java    From feilong-core with Apache License 2.0 5 votes vote down vote up
/**
 * Test read properties to alias bean1.
 */
@Test
public void testToAliasBean1(){
    ArrayConverter arrayConverter = new ArrayConverter(String[].class, new StringConverter(), 2);
    char[] allowedChars = { ':' };
    arrayConverter.setAllowedChars(allowedChars);

    ConvertUtils.register(arrayConverter, String[].class);

    DangaMemCachedConfig dangaMemCachedConfig = toAliasBean(getResourceBundle("messages.memcached"), DangaMemCachedConfig.class);
    assertThat(
                    dangaMemCachedConfig,
                    allOf(//
                                    hasProperty("serverList", arrayContaining("172.20.3-1.23:11211", "172.20.31.22:11211")),
                                    hasProperty("poolName", is("sidsock2")),
                                    hasProperty("expireTime", is(180)),
                                    hasProperty("weight", arrayContaining(2)),
                                    hasProperty("initConnection", is(10)),
                                    hasProperty("minConnection", is(5)),
                                    hasProperty("maxConnection", is(250)),
                                    hasProperty("maintSleep", is(30)),
                                    hasProperty("nagle", is(false)),
                                    hasProperty("socketTo", is(3000)),
                                    hasProperty("aliveCheck", is(false))
                    //
                    ));
}
 
Example #4
Source File: FieldHolder.java    From bluetooth-gatt-parser with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array representation of the field or a default value in case if the field cannot
 * be converted to array.
 * @param def the default value to be returned if an error occurs converting the field
 * @return an array representation of the field
 */
public byte[] getBytes(byte[] def) {
    return new ArrayConverter(byte[].class, new ByteConverter()).convert(byte[].class, value);
}