Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.ioc.internal.util » [javadoc | source]
    1   // Copyright 2006, 2007 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.ioc.internal.util;
   16   
   17   import org.apache.tapestry5.ioc.Location;
   18   import org.apache.tapestry5.ioc.Resource;
   19   
   20   import java.util.Formatter;
   21   
   22   /**
   23    * Implementation class for {@link org.apache.tapestry5.ioc.Location}.
   24    */
   25   public final class LocationImpl implements Location
   26   {
   27       private final Resource resource;
   28   
   29       private final int line;
   30   
   31       private final int column;
   32   
   33       private static final int UNKNOWN = -1;
   34   
   35       public LocationImpl(Resource resource)
   36       {
   37           this(resource, UNKNOWN);
   38       }
   39   
   40       public LocationImpl(Resource resource, int line)
   41       {
   42           this(resource, line, UNKNOWN);
   43       }
   44   
   45       public LocationImpl(Resource resource, int line, int column)
   46       {
   47           this.resource = resource;
   48           this.line = line;
   49           this.column = column;
   50       }
   51   
   52       public Resource getResource()
   53       {
   54           return resource;
   55       }
   56   
   57       public int getLine()
   58       {
   59           return line;
   60       }
   61   
   62       public int getColumn()
   63       {
   64           return column;
   65       }
   66   
   67       @Override
   68       public String toString()
   69       {
   70           StringBuilder buffer = new StringBuilder(resource.toString());
   71           Formatter formatter = new Formatter(buffer);
   72   
   73           if (line != UNKNOWN) formatter.format(", line %d", line);
   74   
   75           if (column != UNKNOWN) formatter.format(", column %d", column);
   76   
   77           return buffer.toString();
   78       }
   79   
   80       @Override
   81       public int hashCode()
   82       {
   83           final int PRIME = 31;
   84           int result = 1;
   85           result = PRIME * result + column;
   86           result = PRIME * result + line;
   87           result = PRIME * result + ((resource == null) ? 0 : resource.hashCode());
   88           return result;
   89       }
   90   
   91       @Override
   92       public boolean equals(Object obj)
   93       {
   94           if (this == obj) return true;
   95           if (obj == null) return false;
   96           if (getClass() != obj.getClass()) return false;
   97           final LocationImpl other = (LocationImpl) obj;
   98           if (column != other.column) return false;
   99           if (line != other.line) return false;
  100           if (resource == null)
  101           {
  102               if (other.resource != null) return false;
  103           }
  104           else if (!resource.equals(other.resource)) return false;
  105           return true;
  106       }
  107   
  108   }

Save This Page
Home » tapestry-src-5.0.19 » org.apache.tapestry5.ioc.internal.util » [javadoc | source]