Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/TypedUtil.java

Issue 1162033004: Pull cacheinvalidations code directory into chromium repo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/TypedUtil.java
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/TypedUtil.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/TypedUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..bb70a80b8b6fe9b7e462abf5561fd7875e7ef099
--- /dev/null
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/util/TypedUtil.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.ipc.invalidation.util;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * Utilities for using various data structures such as {@link Map}s and {@link
+ * Set}s in a type-safe manner.
+ *
+ */
+public class TypedUtil {
+
+ private TypedUtil() { // prevent instantiation
+ }
+
+ /** A statically type-safe version of {@link Map#containsKey}. */
+ public static <Key> boolean containsKey(Map<Key, ?> map, Key key) {
+ return map.containsKey(key);
+ }
+
+ /** A statically type-safe version of {@link Map#get}. */
+ public static <Key, Value> Value mapGet(Map<Key, Value> map, Key key) {
+ return map.get(key);
+ }
+
+ /** A statically type-safe version of {@link Map#remove}. */
+ public static <Key, Value> Value remove(Map<Key, Value> map, Key key) {
+ return map.remove(key);
+ }
+
+ /** A statically type-safe version of {@link Set#contains}. */
+ public static <ElementType> boolean contains(Set<ElementType> set, ElementType element) {
+ return set.contains(element);
+ }
+
+ /** A statically type-safe version of {@link Set#contains}. */
+ public static <ElementType> boolean contains(
+ Collection<ElementType> collection, ElementType element) {
+ return collection.contains(element);
+ }
+
+ /** A statically type-safe version of {@link Set#remove}. */
+ public static <ElementType> boolean remove(Set<ElementType> set, ElementType element) {
+ return set.remove(element);
+ }
+
+ /**
+ * Typed equals operator (useful to ensure at compile time that the expected types are being
+ * compared). Returns {@code true} if both arguments are {@code null}, if they reference the same
+ * object, or if {@code o1.equals(o2)}.
+ */
+ public static <T> boolean equals(T o1, T o2) {
+ // Not using java.util.Objects, which is not supported by earlier version of Android, and not
+ // using com.google.common.base.Objects since we're avoiding a Guava dependency for client code.
+ return (o1 == o2) || ((o1 != null) && o1.equals(o2));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698