Search in sources :

Example 1 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project blue by kunstmusik.

the class PatternObjectTest method testClone.

public void testClone() {
    PatternObject p = new PatternObject();
    p.addPattern(0);
    p.addPattern(0);
    p.addPattern(0);
    for (int i = 0; i < p.size(); i++) {
        Pattern pat = p.getPattern(i);
        for (int j = 0; j < pat.values.length; j++) {
            pat.values[j] = (Math.random() > 0.5d);
        }
    }
    SoundObject clone = p.deepCopy();
    boolean isEqual = EqualsBuilder.reflectionEquals(p, clone);
    if (!isEqual) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("Problem with Pattern\n");
        buffer.append("Original Object\n");
        buffer.append(ToStringBuilder.reflectionToString(p)).append("\n");
        buffer.append("Cloned Object\n");
        buffer.append(ToStringBuilder.reflectionToString(clone)).append("\n");
        System.out.println(buffer.toString());
    }
    assertTrue(isEqual);
    assertEquals(p.saveAsXML(null).toString(), clone.saveAsXML(null).toString());
}
Also used : Pattern(blue.soundObject.pattern.Pattern) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder)

Example 2 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project jeesuite-libs by vakinge.

the class CacheKeyUtils method generate.

/**
 * 生成缓存key
 * @param prefix
 * @param args
 * @return
 */
public static String generate(String prefix, Object... args) {
    if (args == null || args.length == 0)
        return prefix;
    StringBuilder keyBuilder = new StringBuilder(prefix);
    String keyString = null;
    if (args != null && args.length > 0) {
        keyBuilder.append(":");
        StringBuilder argsBuilder = new StringBuilder();
        for (int i = 0; i < args.length; i++) {
            if (args[i] == null) {
                argsBuilder.append("_null");
            } else if (isSimpleDataType(args[i])) {
                argsBuilder.append(args[i].toString());
            } else if (args[i] instanceof Collection) {
                argsBuilder.append(args[i].toString().replaceAll("\\s{0,}", ""));
            } else {
                argsBuilder.append(ToStringBuilder.reflectionToString(args[i], ToStringStyle.SHORT_PREFIX_STYLE));
            }
            if (i < args.length - 1)
                argsBuilder.append("_");
        }
        keyString = argsBuilder.length() > 32 ? md5(argsBuilder) : argsBuilder.toString();
        keyBuilder.append(keyString);
    }
    return keyBuilder.toString();
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Collection(java.util.Collection)

Example 3 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project pinot by linkedin.

the class DPArray method toString.

public String toString() {
    if (slots != null) {
        StringBuilder sb = new StringBuilder();
        for (DPSlot slot : slots) {
            sb.append(ToStringBuilder.reflectionToString(slot, ToStringStyle.SHORT_PREFIX_STYLE));
            sb.append('\n');
        }
        return sb.toString();
    } else
        return "";
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder)

Example 4 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project blue by kunstmusik.

the class MixerTest method testSave.

public void testSave() {
    Mixer mixer = new Mixer();
    for (int i = 0; i < 3; i++) {
        Channel channel = new Channel();
        channel.setName(Integer.toString(i + 1));
        mixer.getChannels().add(channel);
    }
    for (int i = 0; i < 3; i++) {
        Channel channel = new Channel();
        channel.setName("SubChannel" + i);
        mixer.getSubChannels().add(channel);
    }
    Mixer clone = new Mixer(mixer);
    boolean isEqual = mixer.equals(clone);
    if (!isEqual) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("Problem with Mixer\n");
        buffer.append("Original Object\n");
        buffer.append(ToStringBuilder.reflectionToString(mixer)).append("\n");
        buffer.append("Cloned Object\n");
        buffer.append(ToStringBuilder.reflectionToString(clone)).append("\n");
        System.out.println(buffer.toString());
    }
    assertTrue(isEqual);
    Element elem1 = mixer.saveAsXML();
    Element elem2 = clone.saveAsXML();
    assertEquals(elem1.getTextString(), elem2.getTextString());
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Element(electric.xml.Element)

Example 5 with ToStringBuilder.reflectionToString

use of org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString in project blue by kunstmusik.

the class BSBCloneTest method testLoadSave.

public void testLoadSave() {
    BSBObjectEntry[] bsbObjects = BSBObjectRegistry.getBSBObjects();
    for (int i = 0; i < bsbObjects.length; i++) {
        BSBObjectEntry entry = bsbObjects[i];
        Class class1 = entry.bsbObjectClass;
        BSBObject bsbObj = null;
        try {
            bsbObj = (BSBObject) class1.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        assertNotNull(bsbObj);
        if (bsbObj == null) {
            continue;
        }
        Element elem1 = bsbObj.saveAsXML();
        Method m = null;
        try {
            m = class1.getMethod("loadFromXML", new Class[] { Element.class });
        } catch (SecurityException | NoSuchMethodException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        BSBObject bsbObj2 = null;
        assertNotNull(m);
        try {
            bsbObj2 = (BSBObject) m.invoke(bsbObj, new Object[] { elem1 });
        } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
        }
        assertNotNull(bsbObj2);
        boolean isEqual = elem1.toString().equals(bsbObj2.saveAsXML().toString());
        System.out.println(elem1.toString() + ":" + bsbObj2.saveAsXML().toString());
        if (!isEqual) {
            StringBuilder buffer = new StringBuilder();
            buffer.append("Problem with class: ").append(class1.getName()).append("\n");
            buffer.append("Original Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj)).append("\n");
            buffer.append("Cloned Object\n");
            buffer.append(ToStringBuilder.reflectionToString(bsbObj2)).append("\n");
            System.out.println(buffer.toString());
        }
        assertTrue(isEqual);
    }
}
Also used : ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) Element(electric.xml.Element) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ToStringBuilder (org.apache.commons.lang3.builder.ToStringBuilder)6 Element (electric.xml.Element)2 Pattern (blue.soundObject.pattern.Pattern)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1