001/* 002 * Copyright (C) 2013 Chris Leishman 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.parboiled.support; 017 018import org.parboiled.matchers.Matcher; 019 020public class MatcherPosition { 021 private final Matcher matcher; 022 private final Integer index; 023 024 protected MatcherPosition(Matcher matcher, Integer index) { 025 this.matcher = matcher; 026 this.index = index; 027 } 028 029 public static MatcherPosition at(Matcher matcher, Integer index) { 030 return new MatcherPosition(matcher, index); 031 } 032 033 @Override 034 public int hashCode() { 035 return 31 * matcher.hashCode() * index; 036 } 037 038 @Override 039 public boolean equals(Object obj) { 040 if (!(obj instanceof MatcherPosition)) { 041 return false; 042 } 043 if (this == obj) { 044 return true; 045 } 046 MatcherPosition other = (MatcherPosition)obj; 047 return matcher == other.matcher && index == other.index; 048 } 049}