/*
 * Copyright 2016-2017 Talsma ICT
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.talsmasoftware.umldoclet.rendering;

import java.io.IOException;
import java.io.Serializable;

import static java.util.Objects.requireNonNull;

/**
 * Simple renderer for {@link CharSequence} content.
 *
 * @author Sjoerd Talsma
 */
public final class CharSequenceRenderer implements CharSequence, Renderer, Serializable {

    private final CharSequence content;

    private CharSequenceRenderer(CharSequence content) {
        this.content = requireNonNull("Content is <null>.");
    }

    public CharSequenceRenderer of(CharSequence content) {
        return new CharSequenceRenderer(content);
    }

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

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

    @Override
    public CharSequenceRenderer subSequence(int start, int end) {
        return start == 0 && end == length() ? this : new CharSequenceRenderer(content.subSequence(start, end));
    }

    @Override
    public <A extends Appendable> A writeTo(A output) {
        try {
            output.append(content, 0, content.length());
        } catch (IOException ioe) {
            throw new IllegalStateException("I/O exception writing character sequence: " + ioe.getMessage(), ioe);
        }
        return output;
    }

    @Override
    public int hashCode() {
        return content.hashCode();
    }

    @Override
    public boolean equals(Object other) {
        return this == other || (other instanceof CharSequence && content.toString().equals(other.toString()));
    }

    @Override
    public String toString() {
        return content.toString();
    }

}

@@ -21,9 +21,9 @@
 -201
-7
+8
  Tal
@@ -777,16 +777,38 @@
 rer for 
+fixed content of type 
 %7B@link C
@@ -819,24 +819,16 @@
 equence%7D
- content
 .%0A *%0A * 
@@ -942,16 +942,108 @@
 izable %7B
+%0A    public static final Renderer NEWLINE = CharSequenceRenderer.of(System.lineSeparator());
 %0A%0A    pr
@@ -1172,16 +1172,25 @@
 NonNull(
+content, 
 %22Content
@@ -1214,32 +1214,39 @@
   %7D%0A%0A    public 
+static 
 CharSequenceRend
@@ -1846,24 +1846,51 @@
 .length());%0A
+            return output;%0A
         %7D ca
@@ -1998,16 +1998,53 @@
 sequence
+ %5C%22%22%0A                    + this + %22%5C%22
 : %22 + io
@@ -2075,39 +2075,16 @@
       %7D%0A
-        return output;%0A
     %7D%0A%0A 

Fix CharSequenceRenderer input validation + static factory method.