Example usage for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE

List of usage examples for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE.

Prototype

ToStringStyle MULTI_LINE_STYLE

To view the source code for org.apache.commons.lang.builder ToStringStyle MULTI_LINE_STYLE.

Click Source Link

Document

The multi line toString style.

Usage

From source file:com.haines.ml.rce.io.protostuff.ProtostuffEventMarshalBufferUnitTest.java

@Test
public void givenCandidate_whenCallingFullMarshalWithEdgeCase2BufferSize_thenExpectedMessageReturned()
        throws IOException {

    Iterable<ByteBuffer> buffers = loadByteBuffersFromFile("testBuffer2.txt");
    Iterator<ByteBuffer> buffersIt = buffers.iterator();

    int i = 0;// w ww. jav  a  2s . co m
    int totalBytesRead = 0;
    while (buffersIt.hasNext()) {
        ByteBuffer buffer = buffersIt.next();

        totalBytesRead += buffer.remaining();
        LOG.debug("trying buffer: " + (i++));

        boolean moreToRead = candidate.marshal(buffer);

        LOG.debug("inner message now: "
                + ReflectionToStringBuilder.toString(candidate.messageBuffer, ToStringStyle.MULTI_LINE_STYLE));
        assertThat(moreToRead, is(equalTo(!buffersIt.hasNext())));
    }

    System.out.println(totalBytesRead + " bytes read");

    TestMessage message = candidate.buildEventAndResetBuffer();

    assertFullySerialisedMessage(message, true);
}

From source file:com.likethecolor.alchemy.api.entity.NamedEntityAlchemyEntityTest.java

@Test
public void testToString_Formatted() {
    final ToStringStyle style = ToStringStyle.MULTI_LINE_STYLE;
    final String text = "Marcus Schrenker";
    final String type = "Person";
    final Double score = 0.843612D;
    final int count = 37;
    final boolean isMixed = true;
    final Double sentimentScore = 0.9734D;
    final SentimentAlchemyEntity.TYPE sentimentType = SentimentAlchemyEntity.TYPE.POSITIVE;
    final SentimentAlchemyEntity sentimentEntity = new SentimentAlchemyEntity(isMixed, sentimentScore,
            sentimentType.toString());//from   w  w w .j a v  a2 s . c om
    final String census = "http://census.org/resource/Israel";
    final String ciaFactbook = "http://www4.wiwiss.fu-berlin.de/factbook/resource/Israel";
    final String crunchbase = "http://crunchbase.com/resource/Israel";
    final String dbPedia = "http://dbpedia.org/resource/Israel";
    final String freebase = "http://rdf.freebase.com/ns/guid.9202a8c04000641f800000000001e2be";
    final Double latitude = 31.0D;
    final Double longitude = 35.0D;
    final String geo = latitude + " " + longitude;
    final String geonames = "http://geonames.com/Israel";
    final String musicBrainz = "http://musicbrainz.com/Israel";
    final String name = "Israel";
    final String opencyc = "http://sw.opencyc.org/concept/Mx4rvViP55wpEbGdrcN5Y29ycA";
    final String semanticCrunchbase = "http://semanticcrunchbase.com/concept/Mx4rvViP55wpEbGdrcN5Y29ycA";
    final String umbel = "http://umbel.org/umbel/ne/wikipedia/Israel";
    final String website = "http://www.knesset.gov.il/";
    final String yago = "http://mpii.de/yago/resource/Israel";
    final List<String> subtypes = new ArrayList<String>();
    subtypes.add("Location");
    subtypes.add("Country");
    subtypes.add("GovernmentalJurisdiction");

    final String quotation0 = "\"They should have run the complete, original version,\" Finley told ...";
    final String quotation1 = "Finley said the link was \"satisfactory,\" but he still wasn't happy with the Romney campaign edits. \"We're not as concerned,\" ...";
    final String quotation2 = "Finley said the link was \"satisfactory,\" but he still wasn't happy with the Romney campaign edits. \"We're not as concerned,\" he said. \"We still would have liked them to say it was excerpts. Thats what we do when we edit something down.\"";
    final Double sentimentScore0 = -0.233275D;
    final boolean sentimentIsMixed0 = true;
    final SentimentAlchemyEntity.TYPE sentimentType0 = SentimentAlchemyEntity.TYPE.NEGATIVE;
    final SentimentAlchemyEntity expectedSentiment0 = new SentimentAlchemyEntity(sentimentIsMixed0,
            sentimentScore0, sentimentType0.toString());

    final Double sentimentScore1 = -0.261198D;
    final SentimentAlchemyEntity.TYPE sentimentType1 = SentimentAlchemyEntity.TYPE.NEGATIVE;
    final SentimentAlchemyEntity expectedSentiment1 = new SentimentAlchemyEntity();
    expectedSentiment1.setScore(sentimentScore1);
    expectedSentiment1.setType(sentimentType1);

    final Double sentimentScore2 = 0.26119D;
    final SentimentAlchemyEntity.TYPE sentimentType2 = SentimentAlchemyEntity.TYPE.POSITIVE;
    final SentimentAlchemyEntity expectedSentiment2 = new SentimentAlchemyEntity();
    expectedSentiment2.setScore(sentimentScore2);
    expectedSentiment2.setType(sentimentType2);

    final QuotationAlchemyEntity quotationAlchemyEntity0 = new QuotationAlchemyEntity(quotation0,
            expectedSentiment0);
    final QuotationAlchemyEntity quotationAlchemyEntity1 = new QuotationAlchemyEntity(quotation1,
            expectedSentiment1);
    final QuotationAlchemyEntity quotationAlchemyEntity2 = new QuotationAlchemyEntity(quotation2,
            expectedSentiment2);

    final List<QuotationAlchemyEntity> quotations = new ArrayList<QuotationAlchemyEntity>();
    quotations.add(quotationAlchemyEntity0);
    quotations.add(quotationAlchemyEntity1);
    quotations.add(quotationAlchemyEntity2);

    final NamedEntityAlchemyEntity entity = new NamedEntityAlchemyEntity(text, type, count, score);
    entity.addQuotation(quotations.get(0));
    entity.addQuotation(quotations.get(1));
    entity.addQuotation(quotations.get(2));
    entity.setCensus(census);
    entity.setCIAFactbook(ciaFactbook);
    entity.setCrunchbase(crunchbase);
    entity.setDBPedia(dbPedia);
    entity.setFreebase(freebase);
    entity.setGeo(geo);
    entity.setGeonames(geonames);
    entity.setMusicBrainz(musicBrainz);
    entity.setName(name);
    entity.setOpencyc(opencyc);
    entity.setSemanticCrunchbase(semanticCrunchbase);
    entity.setSentiment(sentimentEntity);
    entity.setText(text);
    entity.setType(type);
    entity.setUmbel(umbel);
    entity.setWebsite(website);
    entity.setYago(yago);
    for (String subtype : subtypes) {
        entity.addSubtype(subtype);
    }
    for (QuotationAlchemyEntity quotation : quotations) {
        entity.addQuotation(quotation);
    }

    final DisambiguatedAlchemyEntity disambiguatedAlchemyEntity = entity.getDisambiguatedAlchemyEntity();

    final String expectedString = new ToStringBuilder(entity, style).append("count", count)
            .append("quotation count", quotations.size()).append("quotations", quotations)
            .append("score", score).append("sentiment", sentimentEntity).append("text", text)
            .append("type", type).append("disambiguated", disambiguatedAlchemyEntity.toString()).toString();

    final String actualString = entity.toString(style);

    assertEquals(expectedString, actualString);
}

From source file:nl.nn.adapterframework.align.ToXml.java

public List<XSParticle> getBestChildElementPath(XSElementDeclaration elementDeclaration, N node, boolean silent)
        throws SAXException {
    XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
    if (typeDefinition == null) {
        log.warn("getBestChildElementPath typeDefinition is null");
        return null;
    }//w w  w  . ja  va2 s  .c o m
    switch (typeDefinition.getTypeCategory()) {
    case XSTypeDefinition.SIMPLE_TYPE:
        if (DEBUG)
            log.debug("getBestChildElementPath typeDefinition.typeCategory is SimpleType, no child elements");
        return null;
    case XSTypeDefinition.COMPLEX_TYPE:
        XSComplexTypeDefinition complexTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
        switch (complexTypeDefinition.getContentType()) {
        case XSComplexTypeDefinition.CONTENTTYPE_EMPTY:
            if (DEBUG)
                log.debug(
                        "getBestChildElementPath complexTypeDefinition.contentType is Empty, no child elements");
            return null;
        case XSComplexTypeDefinition.CONTENTTYPE_SIMPLE:
            if (DEBUG)
                log.debug(
                        "getBestChildElementPath complexTypeDefinition.contentType is Simple, no child elements (only characters)");
            return null;
        case XSComplexTypeDefinition.CONTENTTYPE_ELEMENT:
        case XSComplexTypeDefinition.CONTENTTYPE_MIXED:
            XSParticle particle = complexTypeDefinition.getParticle();
            if (particle == null) {
                throw new IllegalStateException(
                        "getBestChildElementPath complexTypeDefinition.particle is null for Element or Mixed contentType");
                //               log.warn("typeDefinition particle is null, is this a problem?");
                //               return null;
            }
            if (DEBUG)
                log.debug("typeDefinition particle ["
                        + ToStringBuilder.reflectionToString(particle, ToStringStyle.MULTI_LINE_STYLE) + "]");
            List<XSParticle> result = new LinkedList<XSParticle>();
            List<String> failureReasons = new LinkedList<String>();
            if (getBestMatchingElementPath(elementDeclaration, node, particle, result, failureReasons)) {
                return result;
            }
            String msg = "Cannot find path:";
            for (String reason : failureReasons) {
                msg += '\n' + reason;
            }
            if (!silent) {
                handleError(msg);
            }
            return null;
        default:
            throw new IllegalStateException(
                    "getBestChildElementPath complexTypeDefinition.contentType is not Empty,Simple,Element or Mixed, but ["
                            + complexTypeDefinition.getContentType() + "]");
        }
    default:
        throw new IllegalStateException(
                "getBestChildElementPath typeDefinition.typeCategory is not SimpleType or ComplexType, but ["
                        + typeDefinition.getTypeCategory() + "] class [" + typeDefinition.getClass().getName()
                        + "]");
    }
}

From source file:nl.nn.adapterframework.align.ToXml.java

/**
 * //w w  w . ja v a  2s . c  o m
 * @param baseElementDeclaration TODO
 * @param particle
 * @param failureReasons returns the reasons why no match was found
 * @param path in this list the longest list of child elements, that matches the available, is maintained. Null if no matching.
 * @return true when a matching path is found. if false, failureReasons will contain reasons why.
 * @throws SAXException 
  */
public boolean getBestMatchingElementPath(XSElementDeclaration baseElementDeclaration, N baseNode,
        XSParticle particle, List<XSParticle> path, List<String> failureReasons) throws SAXException {
    if (particle == null) {
        throw new NullPointerException("getBestMatchingElementPath particle is null");
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new NullPointerException("getBestMatchingElementPath particle.term is null");
    }
    if (term instanceof XSModelGroup) {
        XSModelGroup modelGroup = (XSModelGroup) term;
        short compositor = modelGroup.getCompositor();
        XSObjectList particles = modelGroup.getParticles();
        if (DEBUG)
            log.debug("getBestMatchingElementPath() modelGroup particles ["
                    + ToStringBuilder.reflectionToString(particles, ToStringStyle.MULTI_LINE_STYLE) + "]");
        switch (compositor) {
        case XSModelGroup.COMPOSITOR_SEQUENCE:
        case XSModelGroup.COMPOSITOR_ALL:
            for (int i = 0; i < particles.getLength(); i++) {
                XSParticle childParticle = (XSParticle) particles.item(i);
                if (!getBestMatchingElementPath(baseElementDeclaration, baseNode, childParticle, path,
                        failureReasons)) {
                    return false;
                }
            }
            return true;
        case XSModelGroup.COMPOSITOR_CHOICE:
            List<XSParticle> bestPath = null;

            List<String> choiceFailureReasons = new LinkedList<String>();
            for (int i = 0; i < particles.getLength(); i++) {
                XSParticle childParticle = (XSParticle) particles.item(i);
                List<XSParticle> optionPath = new LinkedList<XSParticle>(path);

                if (getBestMatchingElementPath(baseElementDeclaration, baseNode, childParticle, optionPath,
                        choiceFailureReasons)) {
                    if (bestPath == null || bestPath.size() < optionPath.size()) {
                        bestPath = optionPath;
                    }
                }
            }
            if (bestPath == null) {
                failureReasons.addAll(choiceFailureReasons);
                return false;
            }
            if (DEBUG)
                log.debug("Replace path with best path of Choice Compositor, size [" + bestPath.size() + "]");
            path.clear();
            path.addAll(bestPath);
            return true;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath modelGroup.compositor is not COMPOSITOR_SEQUENCE, COMPOSITOR_ALL or COMPOSITOR_CHOICE, but ["
                            + compositor + "]");
        }
    }
    if (term instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
        String elementName = elementDeclaration.getName();
        if (DEBUG)
            log.debug("getBestMatchingElementPath().XSElementDeclaration name [" + elementName + "]");
        if (!hasChild(baseElementDeclaration, baseNode, elementName)) {
            if (isDeepSearch()) {
                if (DEBUG)
                    log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                            + "] not found, perform deep search");
                try {
                    List<XSParticle> subList = getBestChildElementPath(elementDeclaration, baseNode, true);
                    if (subList != null && !subList.isEmpty()) {
                        path.add(particle);
                        if (DEBUG)
                            log.debug("getBestMatchingElementPath().XSElementDeclaration element ["
                                    + elementName + "] not found, nested elements found in deep search");
                        return true;
                    }
                    if (DEBUG)
                        log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                                + "] not found, no nested elements found in deep search");
                } catch (Exception e) {
                    if (DEBUG)
                        log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                                + "] not found, no nested elements found in deep search: " + e.getMessage());
                    return false;
                }
            }
            if (particle.getMinOccurs() > 0) {
                //               if (DEBUG) log.debug("getBestMatchingElementPath().XSElementDeclaration mandatory element ["+elementName+"] not found, path fails, autoInsertMandatory ["+isAutoInsertMandatory()+"]");
                //               if (isAutoInsertMandatory()) {
                //                  path.add(particle);
                //                  if (DEBUG) log.debug("getBestMatchingElementPath().XSElementDeclaration element ["+elementName+"] not found, nested elements found in deep search");
                //                  return true;
                //               }
                failureReasons.add(MSG_EXPECTED_ELEMENT + " [" + elementName + "]");
                return false;
            }
            if (DEBUG)
                log.debug("getBestMatchingElementPath().XSElementDeclaration optional element [" + elementName
                        + "] not found, path continues");
            return true;
        }
        for (XSParticle resultParticle : path) {
            if (elementName.equals(resultParticle.getTerm().getName())) {
                if (DEBUG)
                    log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName
                            + "] found but required multiple times");
                failureReasons.add("element [" + elementName + "] required multiple times");
                return false;
            }
        }
        if (DEBUG)
            log.debug("getBestMatchingElementPath().XSElementDeclaration element [" + elementName + "] found");
        path.add(particle);
        return true;
    }
    if (term instanceof XSWildcard) {
        XSWildcard wildcard = (XSWildcard) term;
        String processContents;
        switch (wildcard.getProcessContents()) {
        case XSWildcard.PC_LAX:
            processContents = "LAX";
            break;
        case XSWildcard.PC_SKIP:
            processContents = "SKIP";
            break;
        case XSWildcard.PC_STRICT:
            processContents = "STRICT";
            break;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath wildcard.processContents is not PC_LAX, PC_SKIP or PC_STRICT, but ["
                            + wildcard.getProcessContents() + "]");
        }
        String namespaceConstraint;
        switch (wildcard.getConstraintType()) {
        case XSWildcard.NSCONSTRAINT_ANY:
            namespaceConstraint = "ANY";
            break;
        case XSWildcard.NSCONSTRAINT_LIST:
            namespaceConstraint = "SKIP " + wildcard.getNsConstraintList();
            break;
        case XSWildcard.NSCONSTRAINT_NOT:
            namespaceConstraint = "NOT " + wildcard.getNsConstraintList();
            break;
        default:
            throw new IllegalStateException(
                    "getBestMatchingElementPath wildcard.namespaceConstraint is not ANY, LIST or NOT, but ["
                            + wildcard.getConstraintType() + "]");
        }
        String msg = "term for element [" + baseElementDeclaration.getName()
                + "] is WILDCARD; namespaceConstraint [" + namespaceConstraint + "] processContents ["
                + processContents + "]. Please check if the element typed properly in the schema";
        if (isFailOnWildcards()) {
            throw new IllegalStateException(msg + ", or set failOnWildcards=\"false\"");
        }
        log.warn(msg);
        return true;
    }
    throw new IllegalStateException(
            "getBestMatchingElementPath unknown Term type [" + term.getClass().getName() + "]");
}

From source file:nl.nn.adapterframework.core.IbisException.java

public String getMessage() {
    Throwable throwables[] = getThrowables();
    String result = null;//from   w  ww .j  a v  a2 s .c o  m
    String prev_message = null;

    for (int i = getThrowableCount() - 1; i >= 0; i--) {

        String cur_message = getMessage(i);

        //         if (log.isDebugEnabled()) {
        //            log.debug("t["+i+"], ["+ClassUtils.nameOf(throwables[i])+"], cur ["+cur_message+"], prev ["+prev_message+"]");
        //         }          

        String newPart = null;

        // prefix the result with the message of this exception.
        // if the new message ends with the previous, remove the part that is already known
        if (StringUtils.isNotEmpty(cur_message)) {
            newPart = addPart(cur_message, " ", newPart);
            if (StringUtils.isNotEmpty(newPart) && StringUtils.isNotEmpty(prev_message)
                    && newPart.endsWith(prev_message)) {
                newPart = newPart.substring(0, newPart.length() - prev_message.length());
            }
            if (StringUtils.isNotEmpty(newPart) && newPart.endsWith(": ")) {
                newPart = newPart.substring(0, newPart.length() - 2);
            }
            prev_message = cur_message;
        }
        String specificDetails = getExceptionSpecificDetails(throwables[i]);
        if (StringUtils.isNotEmpty(specificDetails)
                && (result == null || result.indexOf(specificDetails) < 0)) {
            newPart = addPart(specificDetails, ": ", newPart);
        }

        if (!(throwables[i] instanceof IbisException)) {
            String exceptionType = "(" + getExceptionType(throwables[i]) + ")";
            newPart = addPart(exceptionType, " ", newPart);
        }
        result = addPart(newPart, ": ", result);
    }

    if (result == null) {
        //          log.debug("no message found, returning fields by inspection");
        // do not replace the following with toString(), this causes an endless loop. GvB
        result = "no message, fields of this exception: "
                + ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
    return result;
}

From source file:nl.nn.adapterframework.ftp.FtpListener.java

public String toString() {
    String result = super.toString();
    ToStringBuilder ts = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
    ts.append("name", getName());
    ts.append("remoteDirectory", remoteDirectory);
    result += ts.toString();//  w  w  w .  j ava  2  s .  c  o m
    return result;

}

From source file:nl.nn.adapterframework.receivers.DirectoryListener.java

public String toString() {
    String result = super.toString();
    ToStringBuilder ts = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
    ts.append("name", getName());
    ts.append("inputDirectory", getInputDirectory());
    ts.append("wildcard", getWildcard());
    ts.append("excludeWildcard", getExcludeWildcard());
    result += ts.toString();/*from  w  w w  .ja v  a 2  s . c  om*/
    return result;

}

From source file:nl.nn.adapterframework.receivers.FileRecordListener.java

public String toString() {
    String result = super.toString();
    ToStringBuilder ts = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
    ts.append("name", getName());
    ts.append("inputDirectory", getInputDirectory());
    ts.append("wildcard", getWildcard());
    result += ts.toString();/*from w  w  w  .ja  v  a  2s .c om*/
    return result;

}

From source file:nl.nn.adapterframework.receivers.ReceiverBase.java

/**
 *  Returns a toString of this class by introspection and the toString() value of its listener.
 *
 * @return    Description of the Return Value
 *//*from w  w w .  j a  v a  2s .  c  o  m*/
public String toString() {
    String result = super.toString();
    ToStringBuilder ts = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
    ts.append("name", getName());
    result += ts.toString();
    result += " listener [" + (listener == null ? "-none-" : listener.toString()) + "]";
    return result;
}

From source file:no.java.ems.server.restlet.RoomResource.java

public Representation getRepresentation(Variant variant) {
    Serializable resource;/*w ww. j a v  a 2 s. com*/
    String eventId = (String) getRequest().getAttributes().get(EVENTID);
    if (StringUtils.isBlank(getId())) {
        resource = new ArrayList<Room>(roomDao.getRooms());
    } else {
        resource = roomDao.getRoom(getId());
    }
    if (!StringUtils.isBlank(eventId)) {
        Event event = eventDao.getEvent(eventId);
        if (event != null) {
            resource = new ArrayList<Room>(event.getRooms());
        }
    }
    if (variant.getMediaType().equals(MediaType.APPLICATION_JAVA_OBJECT)) {
        return new ObjectRepresentation(resource);
    } else if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {
        return new StringRepresentation(
                ToStringBuilder.reflectionToString(resource, ToStringStyle.MULTI_LINE_STYLE));
    }
    return super.getRepresentation(variant);
}