Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2006-2014 phloc systems http://www.phloc.com office[at]phloc[dot]com 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 com.phloc.json.impl;
This is the base class for all JSON implementation domain objects. It contains default implementation for shared methods.

Author(s):
Boris Gregorcic
public abstract class AbstractJSON implements IJSON
  private static final long serialVersionUID = 1580625257200342447L;
  protected static final String INDENT_STRING = "  "//$NON-NLS-1$
  public final String getJSONString ()
  {
    return getJSONString (false);
  }
  public final String getJSONString (final boolean bAlignAndIndent)
  {
    final StringBuilder aResult = new StringBuilder ();
    appendJSONString (aResultbAlignAndIndent, 0);
    return aResult.toString ();
  }

  
Emits the indentation characters for the current level

Parameters:
aResult The string builder to which to add
nLevel the current level in the hierarchy
bAlignAndIndent whether or not the output should be indented and aligned at all
  protected static final void indent (final StringBuilder aResultfinal int nLevelfinal boolean bAlignAndIndent)
  {
    if (bAlignAndIndent)
    {
      aResult.append (StringHelper.getRepeated (nLevel));
    }
  }

  
Appends a new line

Parameters:
aSB The string builder to which to add
bAlignAndIndent whether or not the output should be indented and aligned at all
  protected static final void appendNewLine (final StringBuilder aSBfinal boolean bAlignAndIndent)
  {
    // this is to avoid empty lines (is hard to grant otherwise!)
    if (bAlignAndIndent && !StringHelper.endsWith (aSB.))
    {
      aSB.append (.);
    }
  }
New to GrepCode? Check out our FAQ X