001/*******************************************************************************
002 * Copyright (c) 2016 EclipseSource.
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in all
012 * copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020 * SOFTWARE.
021 ******************************************************************************/
022package com.restfb.json;
023
024
025import java.io.Serializable;
026
027/**
028 * An immutable object that represents a location in the parsed text.
029 */
030public class Location implements Serializable {
031
032  private static final long serialVersionUID = -1249816104753838044L;
033
034  /**
035   * The absolute character index, starting at 0.
036   */
037  public final int offset;
038
039  /**
040   * The line number, starting at 1.
041   */
042  public final int line;
043
044  /**
045   * The column number, starting at 1.
046   */
047  public final int column;
048
049  Location(int offset, int line, int column) {
050    this.offset = offset;
051    this.column = column;
052    this.line = line;
053  }
054
055  @Override
056  public String toString() {
057    return line + ":" + column;
058  }
059
060  @Override
061  public int hashCode() {
062    return offset;
063  }
064
065  @Override
066  public boolean equals(Object obj) {
067    if (this == obj) {
068      return true;
069    }
070    if (obj == null) {
071      return false;
072    }
073    if (getClass() != obj.getClass()) {
074      return false;
075    }
076    Location other = (Location)obj;
077    return offset == other.offset && column == other.column && line == other.line;
078  }
079
080}