Make protobuf java JDK 1.5 compatible.

This commit is contained in:
liujisi@google.com 2011-04-28 09:37:40 +00:00
parent 9cf65b7dd2
commit 5a5e67a25d
8 changed files with 77 additions and 35 deletions

View File

@ -421,7 +421,7 @@ public abstract class GeneratedMessage extends AbstractMessage
return true;
}
@Override
//@Override (Java
public final UnknownFieldSet getUnknownFields() {
return unknownFields;
}
@ -445,7 +445,7 @@ public abstract class GeneratedMessage extends AbstractMessage
*/
private class BuilderParentImpl implements BuilderParent {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() {
onChanged();
}
@ -1130,7 +1130,7 @@ public abstract class GeneratedMessage extends AbstractMessage
// obtained.
return new GeneratedExtension<ContainingType, Type>(
new ExtensionDescriptorRetriever() {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public FieldDescriptor getDescriptor() {
return scope.getDescriptorForType().getExtensions()
.get(descriptorIndex);
@ -1225,7 +1225,7 @@ public abstract class GeneratedMessage extends AbstractMessage
throw new IllegalStateException("Already initialized.");
}
descriptorRetriever = new ExtensionDescriptorRetriever() {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public FieldDescriptor getDescriptor() {
return descriptor;
}

View File

@ -573,7 +573,7 @@ public class RepeatedFieldBuilder
}
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() {
onChanged();
}

View File

@ -234,7 +234,7 @@ public class SingleFieldBuilder
}
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() {
onChanged();
}

View File

@ -411,22 +411,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
this.value = value;
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public K getKey() {
return key;
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public V getValue() {
return value;
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public int compareTo(Entry other) {
return getKey().compareTo(other.getKey());
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public V setValue(V newValue) {
checkMutable();
final V oldValue = this.value;
@ -535,13 +535,13 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
private boolean nextCalledBeforeRemove;
private Iterator<Map.Entry<K, V>> lazyOverflowIterator;
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() {
return (pos + 1) < entryList.size() ||
getOverflowIterator().hasNext();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public Map.Entry<K, V> next() {
nextCalledBeforeRemove = true;
// Always increment pos so that we know whether the last returned value
@ -552,7 +552,7 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
return getOverflowIterator().next();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() {
if (!nextCalledBeforeRemove) {
throw new IllegalStateException("remove() was called before next()");
@ -589,22 +589,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
private static class EmptySet {
private static final Iterator<Object> ITERATOR = new Iterator<Object>() {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() {
return false;
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public Object next() {
throw new NoSuchElementException();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() {
throw new UnsupportedOperationException();
}
};
private static final Iterable<Object> ITERABLE = new Iterable<Object>() {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public Iterator<Object> iterator() {
return ITERATOR;
}

View File

@ -60,62 +60,62 @@ public class UnmodifiableLazyStringList extends AbstractList<String>
return list.size();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public ByteString getByteString(int index) {
return list.getByteString(index);
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void add(ByteString element) {
throw new UnsupportedOperationException();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public ListIterator<String> listIterator(final int index) {
return new ListIterator<String>() {
ListIterator<String> iter = list.listIterator(index);
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() {
return iter.hasNext();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public String next() {
return iter.next();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasPrevious() {
return iter.hasPrevious();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public String previous() {
return iter.previous();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public int nextIndex() {
return iter.nextIndex();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public int previousIndex() {
return iter.previousIndex();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() {
throw new UnsupportedOperationException();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void set(String o) {
throw new UnsupportedOperationException();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void add(String o) {
throw new UnsupportedOperationException();
}
@ -127,17 +127,17 @@ public class UnmodifiableLazyStringList extends AbstractList<String>
return new Iterator<String>() {
Iterator<String> iter = list.iterator();
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() {
return iter.hasNext();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public String next() {
return iter.next();
}
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() {
throw new UnsupportedOperationException();
}

View File

@ -41,7 +41,7 @@ package com.google.protobuf;
*/
public class ForceFieldBuildersPreRun implements Runnable {
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void run() {
GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
}

View File

@ -32,7 +32,6 @@ package com.google.protobuf;
import junit.framework.TestCase;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -46,6 +45,49 @@ import java.util.TreeSet;
* @author darick@google.com Darick Tong
*/
public class SmallSortedMapTest extends TestCase {
// java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
// here for JDK 1.5 users.
private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
private final K key;
private V value;
SimpleEntry(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
public V setValue(V value) {
V oldValue = this.value;
this.value = value;
return oldValue;
}
private static boolean eq(Object o1, Object o2) {
return o1 == null ? o2 == null : o1.equals(o2);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry e = (Map.Entry) o;
return eq(key, e.getKey()) && eq(value, e.getValue());
}
@Override
public int hashCode() {
return ((key == null) ? 0 : key.hashCode()) ^
((value == null) ? 0 : value.hashCode());
}
}
public void testPutAndGetArrayEntriesOnly() {
runPutAndGetTest(3);

View File

@ -3799,7 +3799,7 @@ public final class TestUtil {
private int invalidations;
@Override
//@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() {
invalidations++;
}