diff options
author | liujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2011-04-28 09:37:40 +0000 |
---|---|---|
committer | liujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d> | 2011-04-28 09:37:40 +0000 |
commit | 5a5e67a25dce780ee0050d2bc76fa58d8437619a (patch) | |
tree | ee835bbed608655d59f6334c756741dad054f090 /java/src/test | |
parent | 9cf65b7dd29adfb849b555eee3e3b93d7c45fc73 (diff) | |
download | protobuf-5a5e67a25dce780ee0050d2bc76fa58d8437619a.tar.gz protobuf-5a5e67a25dce780ee0050d2bc76fa58d8437619a.tar.bz2 protobuf-5a5e67a25dce780ee0050d2bc76fa58d8437619a.zip |
Make protobuf java JDK 1.5 compatible.
Diffstat (limited to 'java/src/test')
3 files changed, 45 insertions, 3 deletions
diff --git a/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java b/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java index 108a28e1..8b78893d 100644 --- a/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +++ b/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java @@ -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(); } diff --git a/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java b/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java index 922115fc..8f77a036 100644 --- a/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +++ b/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java @@ -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); diff --git a/java/src/test/java/com/google/protobuf/TestUtil.java b/java/src/test/java/com/google/protobuf/TestUtil.java index 7c458d75..9109f419 100644 --- a/java/src/test/java/com/google/protobuf/TestUtil.java +++ b/java/src/test/java/com/google/protobuf/TestUtil.java @@ -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++; } |