Java.src.org.antlr.v4.runtime.dfa.AbstractEdgeMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of antlr4-perf-testsuite Show documentation
Show all versions of antlr4-perf-testsuite Show documentation
The ANTLR 4 grammar compiler.
/*
* Copyright (c) 2012 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD-3-Clause license that
* can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.runtime.dfa;
import java.util.AbstractSet;
import java.util.Map;
/**
*
* @author Sam Harwell
*/
public abstract class AbstractEdgeMap implements EdgeMap {
protected final int minIndex;
protected final int maxIndex;
public AbstractEdgeMap(int minIndex, int maxIndex) {
// the allowed range (with minIndex and maxIndex inclusive) should be less than 2^32
assert maxIndex - minIndex + 1 >= 0;
this.minIndex = minIndex;
this.maxIndex = maxIndex;
}
@Override
public abstract AbstractEdgeMap put(int key, T value);
@Override
public AbstractEdgeMap putAll(EdgeMap extends T> m) {
AbstractEdgeMap result = this;
for (Map.Entry entry : m.entrySet()) {
result = result.put(entry.getKey(), entry.getValue());
}
return result;
}
@Override
public abstract AbstractEdgeMap clear();
@Override
public abstract AbstractEdgeMap remove(int key);
protected abstract class AbstractEntrySet extends AbstractSet> {
@Override
public boolean contains(Object o) {
if (!(o instanceof Map.Entry)) {
return false;
}
Map.Entry, ?> entry = (Map.Entry, ?>)o;
if (entry.getKey() instanceof Integer) {
int key = (Integer)entry.getKey();
Object value = entry.getValue();
T existing = get(key);
return value == existing || (existing != null && existing.equals(value));
}
return false;
}
@Override
public int size() {
return AbstractEdgeMap.this.size();
}
}
}