From 5a5e67a25dce780ee0050d2bc76fa58d8437619a Mon Sep 17 00:00:00 2001 From: "liujisi@google.com" Date: Thu, 28 Apr 2011 09:37:40 +0000 Subject: Make protobuf java JDK 1.5 compatible. --- .../google/protobuf/ForceFieldBuildersPreRun.java | 2 +- .../com/google/protobuf/SmallSortedMapTest.java | 44 +++++++++++++++++++++- .../test/java/com/google/protobuf/TestUtil.java | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'java/src/test') 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 implements Map.Entry { + 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++; } -- cgit v1.2.3