Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Jackson JSON-processor.
   *
   * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi
   */
  
  package divconq.json3;

Object that encapsulates Location information used for reporting parsing (or potentially generation) errors, as well as current location within input streams.
 
 public class JsonLocation
     implements java.io.Serializable // as per [JACKSON-168]
 {
     private static final long serialVersionUID = 1L;

    
Shared immutable "N/A location" that can be returned to indicate that no location information is available
 
     public final static JsonLocation NA = new JsonLocation("N/A", -1L, -1L, -1, -1);
 
     final long _totalBytes;
     final long _totalChars;
 
     final int _lineNr;
     final int _columnNr;

    
Displayable description for input source: file path, URL.

NOTE: transient since 2.2 so that Location itself is Serializable.

 
     final transient Object _sourceRef;
 
     public JsonLocation(Object srcReflong totalCharsint lineNrint colNr)
     {
         /* Unfortunately, none of legal encodings are straight single-byte
          * encodings. Could determine offset for UTF-16/UTF-32, but the
          * most important one is UTF-8...
          * so for now, we'll just not report any real byte count
          */
         this(srcRef, -1L, totalCharslineNrcolNr);
     }
 
     public JsonLocation(Object sourceReflong totalByteslong totalChars,
             int lineNrint columnNr)
     {
          = sourceRef;
          = totalBytes;
          = totalChars;
          = lineNr;
          = columnNr;
     }
 
     /*
      * Reference to the original resource being read, if one available.
      * For example, when a parser has been constructed by passing
      * a {@link java.io.File} instance, this method would return
      * that File. Will return null if no such reference is available,
      * for example when {@link java.io.InputStream} was used to
      * construct the parser instance.
      */
     public Object getSourceRef() { return ; }
 
     /*
      * @return Line number of the location (1-based)
      */
     public int getLineNr() { return ; }
 
     /*
      * @return Column number of the location (1-based)
      */
     public int getColumnNr() { return ; }
 
     /*
      * @return Character offset within underlying stream, reader or writer,
      *   if available; -1 if not.
      */
     public long getCharOffset() { return ; }
 
     /*
      * @return Byte offset within underlying stream, reader or writer,
      *   if available; -1 if not.
      */
     public long getByteOffset()
     {
         return ;
     }
 
     @Override
     public String toString()
     {
         StringBuilder sb = new StringBuilder(80);
         sb.append("[Source: ");
         if ( == null) {
             sb.append("UNKNOWN");
         } else {
            sb.append(.toString());
        }
        sb.append("; line: ");
        sb.append();
        sb.append(", column: ");
        sb.append();
        sb.append(']');
        return sb.toString();
    }
    @Override
    public int hashCode()
    {
        int hash = ( == null) ? 1 : .hashCode();
        hash ^= ;
        hash += ;
        hash ^= (int;
        hash += (int;
        return hash;
    }
    @Override
    public boolean equals(Object other)
    {
        if (other == thisreturn true;
        if (other == nullreturn false;
        if (!(other instanceof JsonLocation)) return false;
        JsonLocation otherLoc = (JsonLocationother;
        if ( == null) {
            if (otherLoc._sourceRef != nullreturn false;
        } else if (!.equals(otherLoc._sourceRef)) return false;
        return ( == otherLoc._lineNr)
            && ( == otherLoc._columnNr)
            && ( == otherLoc._totalChars)
            && (getByteOffset() == otherLoc.getByteOffset())
            ;
    }
New to GrepCode? Check out our FAQ X