Commit 5a5e67a2 authored by liujisi@google.com's avatar liujisi@google.com

Make protobuf java JDK 1.5 compatible.

parent 9cf65b7d
...@@ -421,7 +421,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -421,7 +421,7 @@ public abstract class GeneratedMessage extends AbstractMessage
return true; return true;
} }
@Override //@Override (Java
public final UnknownFieldSet getUnknownFields() { public final UnknownFieldSet getUnknownFields() {
return unknownFields; return unknownFields;
} }
...@@ -445,7 +445,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -445,7 +445,7 @@ public abstract class GeneratedMessage extends AbstractMessage
*/ */
private class BuilderParentImpl implements BuilderParent { private class BuilderParentImpl implements BuilderParent {
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() { public void markDirty() {
onChanged(); onChanged();
} }
...@@ -1130,7 +1130,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -1130,7 +1130,7 @@ public abstract class GeneratedMessage extends AbstractMessage
// obtained. // obtained.
return new GeneratedExtension<ContainingType, Type>( return new GeneratedExtension<ContainingType, Type>(
new ExtensionDescriptorRetriever() { new ExtensionDescriptorRetriever() {
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public FieldDescriptor getDescriptor() { public FieldDescriptor getDescriptor() {
return scope.getDescriptorForType().getExtensions() return scope.getDescriptorForType().getExtensions()
.get(descriptorIndex); .get(descriptorIndex);
...@@ -1225,7 +1225,7 @@ public abstract class GeneratedMessage extends AbstractMessage ...@@ -1225,7 +1225,7 @@ public abstract class GeneratedMessage extends AbstractMessage
throw new IllegalStateException("Already initialized."); throw new IllegalStateException("Already initialized.");
} }
descriptorRetriever = new ExtensionDescriptorRetriever() { descriptorRetriever = new ExtensionDescriptorRetriever() {
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public FieldDescriptor getDescriptor() { public FieldDescriptor getDescriptor() {
return descriptor; return descriptor;
} }
......
...@@ -573,7 +573,7 @@ public class RepeatedFieldBuilder ...@@ -573,7 +573,7 @@ public class RepeatedFieldBuilder
} }
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() { public void markDirty() {
onChanged(); onChanged();
} }
......
...@@ -234,7 +234,7 @@ public class SingleFieldBuilder ...@@ -234,7 +234,7 @@ public class SingleFieldBuilder
} }
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() { public void markDirty() {
onChanged(); onChanged();
} }
......
...@@ -411,22 +411,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { ...@@ -411,22 +411,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
this.value = value; this.value = value;
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public K getKey() { public K getKey() {
return key; return key;
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public V getValue() { public V getValue() {
return value; return value;
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public int compareTo(Entry other) { public int compareTo(Entry other) {
return getKey().compareTo(other.getKey()); return getKey().compareTo(other.getKey());
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public V setValue(V newValue) { public V setValue(V newValue) {
checkMutable(); checkMutable();
final V oldValue = this.value; final V oldValue = this.value;
...@@ -535,13 +535,13 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { ...@@ -535,13 +535,13 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
private boolean nextCalledBeforeRemove; private boolean nextCalledBeforeRemove;
private Iterator<Map.Entry<K, V>> lazyOverflowIterator; private Iterator<Map.Entry<K, V>> lazyOverflowIterator;
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() { public boolean hasNext() {
return (pos + 1) < entryList.size() || return (pos + 1) < entryList.size() ||
getOverflowIterator().hasNext(); getOverflowIterator().hasNext();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public Map.Entry<K, V> next() { public Map.Entry<K, V> next() {
nextCalledBeforeRemove = true; nextCalledBeforeRemove = true;
// Always increment pos so that we know whether the last returned value // 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> { ...@@ -552,7 +552,7 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
return getOverflowIterator().next(); return getOverflowIterator().next();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() { public void remove() {
if (!nextCalledBeforeRemove) { if (!nextCalledBeforeRemove) {
throw new IllegalStateException("remove() was called before next()"); throw new IllegalStateException("remove() was called before next()");
...@@ -589,22 +589,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> { ...@@ -589,22 +589,22 @@ class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
private static class EmptySet { private static class EmptySet {
private static final Iterator<Object> ITERATOR = new Iterator<Object>() { 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() { public boolean hasNext() {
return false; return false;
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public Object next() { public Object next() {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() { public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
}; };
private static final Iterable<Object> ITERABLE = new Iterable<Object>() { 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() { public Iterator<Object> iterator() {
return ITERATOR; return ITERATOR;
} }
......
...@@ -60,62 +60,62 @@ public class UnmodifiableLazyStringList extends AbstractList<String> ...@@ -60,62 +60,62 @@ public class UnmodifiableLazyStringList extends AbstractList<String>
return list.size(); return list.size();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public ByteString getByteString(int index) { public ByteString getByteString(int index) {
return list.getByteString(index); return list.getByteString(index);
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void add(ByteString element) { public void add(ByteString element) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public ListIterator<String> listIterator(final int index) { public ListIterator<String> listIterator(final int index) {
return new ListIterator<String>() { return new ListIterator<String>() {
ListIterator<String> iter = list.listIterator(index); ListIterator<String> iter = list.listIterator(index);
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() { public boolean hasNext() {
return iter.hasNext(); return iter.hasNext();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public String next() { public String next() {
return iter.next(); return iter.next();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasPrevious() { public boolean hasPrevious() {
return iter.hasPrevious(); return iter.hasPrevious();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public String previous() { public String previous() {
return iter.previous(); return iter.previous();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public int nextIndex() { public int nextIndex() {
return iter.nextIndex(); return iter.nextIndex();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public int previousIndex() { public int previousIndex() {
return iter.previousIndex(); return iter.previousIndex();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() { public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void set(String o) { public void set(String o) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void add(String o) { public void add(String o) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
...@@ -127,17 +127,17 @@ public class UnmodifiableLazyStringList extends AbstractList<String> ...@@ -127,17 +127,17 @@ public class UnmodifiableLazyStringList extends AbstractList<String>
return new Iterator<String>() { return new Iterator<String>() {
Iterator<String> iter = list.iterator(); Iterator<String> iter = list.iterator();
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public boolean hasNext() { public boolean hasNext() {
return iter.hasNext(); return iter.hasNext();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public String next() { public String next() {
return iter.next(); return iter.next();
} }
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void remove() { public void remove() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
...@@ -41,7 +41,7 @@ package com.google.protobuf; ...@@ -41,7 +41,7 @@ package com.google.protobuf;
*/ */
public class ForceFieldBuildersPreRun implements Runnable { public class ForceFieldBuildersPreRun implements Runnable {
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void run() { public void run() {
GeneratedMessage.enableAlwaysUseFieldBuildersForTesting(); GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
} }
......
...@@ -32,7 +32,6 @@ package com.google.protobuf; ...@@ -32,7 +32,6 @@ package com.google.protobuf;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
...@@ -46,6 +45,49 @@ import java.util.TreeSet; ...@@ -46,6 +45,49 @@ import java.util.TreeSet;
* @author darick@google.com Darick Tong * @author darick@google.com Darick Tong
*/ */
public class SmallSortedMapTest extends TestCase { 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() { public void testPutAndGetArrayEntriesOnly() {
runPutAndGetTest(3); runPutAndGetTest(3);
......
...@@ -3799,7 +3799,7 @@ public final class TestUtil { ...@@ -3799,7 +3799,7 @@ public final class TestUtil {
private int invalidations; private int invalidations;
@Override //@Override (Java 1.6 override semantics, but we must support 1.5)
public void markDirty() { public void markDirty() {
invalidations++; invalidations++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment