001    package toolbus.parsercup;
002    
003    /**
004     * Like the name implies, this class contains position information (filename + begin and end line /
005     * column).
006     * 
007     * @author Arnold Lankamp
008     */
009    public class PositionInformation{
010            private final String fileName;
011            private final int offset;
012            private final int beginLine;
013            private final int beginColumn;
014            private final int endLine;
015            private final int endColumn;
016            
017            /**
018             * Constructor.
019             * 
020             * @param fileName
021             *            The name of the file the position is in.
022             * @param beginLine
023             *            The begin line.
024             * @param beginColumn
025             *            The begin column.
026             * @param endLine
027             *            The end line.
028             * @param endColumn
029             *            The end column.
030             */
031            public PositionInformation(String fileName, int offset, int beginLine, int beginColumn, int endLine, int endColumn){
032                    this.offset = offset;
033                    this.fileName = fileName;
034                    this.beginLine = beginLine;
035                    this.beginColumn = beginColumn;
036                    this.endLine = endLine;
037                    this.endColumn = endColumn;
038            }
039            
040            /**
041             * 
042             * @return the character offset of the file this position is in
043             */
044            public int getOffset() {
045                    return offset;
046            }
047            /**
048             * Returns the name of the file this position is in.
049             * 
050             * @return The name of the file this position is in.
051             */
052            public String getFileName(){
053                    return fileName;
054            }
055            
056            /**
057             * Returns the begin line of the position.
058             * 
059             * @return The begin line of the position.
060             */
061            public int getBeginLine(){
062                    return beginLine;
063            }
064            
065            /**
066             * Returns the begin column of the position.
067             * 
068             * @return The begin column of the position.
069             */
070            public int getBeginColumn(){
071                    return beginColumn;
072            }
073            
074            /**
075             * Retuns the end line of the position.
076             * 
077             * @return The end line of the position.
078             */
079            public int getEndLine(){
080                    return endLine;
081            }
082            
083            /**
084             * Retuns the end column of the position.
085             * 
086             * @return The end column of the position.
087             */
088            public int getEndColumn(){
089                    return endColumn;
090            }
091            
092            /**
093             * Returns the serial representation of this position in the following format: filename :
094             * beginline,begincolumn - endline,endcolumn
095             */
096            public String toString(){
097                    StringBuilder sb = new StringBuilder();
098                    sb.append(fileName);
099                    sb.append(" @ ");
100                    sb.append(beginLine);
101                    sb.append(",");
102                    sb.append(beginColumn);
103                    sb.append(" - ");
104                    sb.append(endLine);
105                    sb.append(",");
106                    sb.append(endColumn);
107                    return sb.toString();
108            }
109    }