Example usage for java.lang CharSequence CharSequence

List of usage examples for java.lang CharSequence CharSequence

Introduction

In this page you can find the example usage for java.lang CharSequence CharSequence.

Prototype

CharSequence

Source Link

Usage

From source file:com.basistech.rosette.dm.json.plain.JsonTest.java

@Test
public void dataPlainString() throws Exception {
    CharSequence fancyCharSequence = new CharSequence() {
        private final String data = "Hello Polly";

        public String getExtraneousInfo() {
            return "What is this doing here?";
        }//w ww  .  j  a v  a2  s  .c  om

        @Override
        public int length() {
            return data.length();
        }

        @Override
        public char charAt(int index) {
            return data.charAt(index);
        }

        @Override
        public CharSequence subSequence(int start, int end) {
            return data.substring(start, end);
        }

        @Override
        public String toString() {
            return data;
        }
    };

    AnnotatedText.Builder builder = new AnnotatedText.Builder();
    builder.data(fancyCharSequence);
    AnnotatedText text = builder.build();
    StringWriter writer = new StringWriter();
    ObjectMapper mapper = AnnotatedDataModelModule.setupObjectMapper(new ObjectMapper());
    ObjectWriter objectWriter = mapper.writer();
    objectWriter.writeValue(writer, text);
    assertFalse(writer.toString().contains("What is this doing here"));
    assertTrue(writer.toString().contains("Hello Polly"));
}