diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotation.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotation.java index d24cf43a..8ccaab1b 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotation.java @@ -31,11 +31,11 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.AnnotationElement; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -59,7 +59,7 @@ public class ImmutableAnnotation implements Annotation { @Nullable ImmutableList elements) { this.visibility = visibility; this.type = type; - this.elements = Objects.firstNonNull(elements, ImmutableList.of()); + this.elements = ImmutableListUtils.nullToEmptyList(elements); } public static ImmutableAnnotation of(Annotation annotation) { @@ -77,7 +77,7 @@ public class ImmutableAnnotation implements Annotation { @Nonnull @Override public ImmutableList getElements() { return elements; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java index cc760fab..d859f3ee 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableAnnotationElement.java @@ -38,6 +38,7 @@ import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.util.ImmutableListConverter; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; public class ImmutableAnnotationElement implements AnnotationElement { @@ -69,7 +70,8 @@ public class ImmutableAnnotationElement implements AnnotationElement { @Nonnull @Override public EncodedValue getValue() { return value; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf( + @Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableBaseAnnotation.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableBaseAnnotation.java index d9bd47ff..5af4e1df 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableBaseAnnotation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableBaseAnnotation.java @@ -31,10 +31,10 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.iface.BaseAnnotation; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -53,7 +53,7 @@ public class ImmutableBaseAnnotation implements BaseAnnotation { public ImmutableBaseAnnotation(@Nonnull String type, @Nullable ImmutableList elements) { this.type = type; - this.elements = Objects.firstNonNull(elements, ImmutableList.of()); + this.elements = ImmutableListUtils.nullToEmptyList(elements); } public static ImmutableBaseAnnotation of(BaseAnnotation baseAnnotation) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java index 55697ba8..f04df841 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableClassDef.java @@ -38,6 +38,7 @@ import org.jf.dexlib2.iface.ClassDef; import org.jf.dexlib2.iface.Field; import org.jf.dexlib2.iface.Method; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -82,11 +83,11 @@ public class ImmutableClassDef implements ClassDef { this.name = name; this.accessFlags = accessFlags; this.superclass = superclass; - this.interfaces = Objects.firstNonNull(interfaces, ImmutableList.of()); + this.interfaces = ImmutableListUtils.nullToEmptyList(interfaces); this.sourceFile = sourceFile; - this.annotations = Objects.firstNonNull(annotations, ImmutableList.of()); - this.fields = Objects.firstNonNull(fields, ImmutableList.of()); - this.methods = Objects.firstNonNull(methods, ImmutableList.of()); + this.annotations = ImmutableListUtils.nullToEmptyList(annotations); + this.fields = ImmutableListUtils.nullToEmptyList(fields); + this.methods = ImmutableListUtils.nullToEmptyList(methods); } public static ImmutableClassDef of(ClassDef classDef) { @@ -114,7 +115,7 @@ public class ImmutableClassDef implements ClassDef { @Nonnull @Override public ImmutableList getMethods() { return methods; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableDexFile.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableDexFile.java index 10914e95..d06db917 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableDexFile.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableDexFile.java @@ -31,9 +31,9 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.*; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -47,7 +47,7 @@ public class ImmutableDexFile implements DexFile { } public ImmutableDexFile(@Nullable ImmutableList classes) { - this.classes = Objects.firstNonNull(classes, ImmutableList.of()); + this.classes = ImmutableListUtils.nullToEmptyList(classes); } public static ImmutableDexFile of(DexFile dexFile) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java index 2a7f6f26..5c91cdb0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableExceptionHandler.java @@ -62,7 +62,8 @@ public class ImmutableExceptionHandler implements ExceptionHandler { @Override public int getHandlerCodeOffset() { return handlerCodeOffset; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf( + @Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java index ce1e1505..11ae6df2 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableField.java @@ -31,13 +31,13 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.immutable.value.ImmutableEncodedValue; import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.Field; import org.jf.dexlib2.iface.value.EncodedValue; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -76,7 +76,7 @@ public class ImmutableField implements Field { this.type = type; this.accessFlags = accessFlags; this.initialValue = initialValue; - this.annotations = Objects.firstNonNull(annotations, ImmutableList.of()); + this.annotations = ImmutableListUtils.nullToEmptyList(annotations); } public static ImmutableField of(Field field) { @@ -100,7 +100,7 @@ public class ImmutableField implements Field { @Nonnull @Override public ImmutableList getAnnotations() { return annotations; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethod.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethod.java index df36a24e..0bbcc708 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethod.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethod.java @@ -31,10 +31,10 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.*; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -74,10 +74,10 @@ public class ImmutableMethod implements Method { @Nullable ImmutableMethodImplementation methodImplementation) { this.containingClass = containingClass; this.name = name; - this.parameters = Objects.firstNonNull(parameters, ImmutableList.of()); + this.parameters = ImmutableListUtils.nullToEmptyList(parameters); this.returnType = returnType; this.accessFlags = accessFlags; - this.annotations = Objects.firstNonNull(annotations, ImmutableList.of()); + this.annotations = ImmutableListUtils.nullToEmptyList(annotations); this.methodImplementation = methodImplementation; } @@ -104,7 +104,7 @@ public class ImmutableMethod implements Method { @Nullable public ImmutableMethodImplementation getImplementation() { return methodImplementation; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java index db22f867..a1c6ca60 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodImplementation.java @@ -31,7 +31,6 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.MethodImplementation; import org.jf.dexlib2.iface.TryBlock; @@ -39,6 +38,7 @@ import org.jf.dexlib2.iface.debug.DebugItem; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.immutable.debug.ImmutableDebugItem; import org.jf.dexlib2.immutable.instruction.ImmutableInstruction; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -65,9 +65,9 @@ public class ImmutableMethodImplementation implements MethodImplementation { @Nullable ImmutableList tryBlocks, @Nullable ImmutableList debugItems) { this.registerCount = registerCount; - this.instructions = Objects.firstNonNull(instructions, ImmutableList.of()); - this.tryBlocks = Objects.firstNonNull(tryBlocks, ImmutableList.of()); - this.debugItems = Objects.firstNonNull(debugItems, ImmutableList.of()); + this.instructions = ImmutableListUtils.nullToEmptyList(instructions); + this.tryBlocks = ImmutableListUtils.nullToEmptyList(tryBlocks); + this.debugItems = ImmutableListUtils.nullToEmptyList(debugItems); } @Nullable diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodParameter.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodParameter.java index c670db95..13cf9c44 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodParameter.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableMethodParameter.java @@ -31,11 +31,11 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.Annotation; import org.jf.dexlib2.iface.MethodParameter; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -58,7 +58,7 @@ public class ImmutableMethodParameter implements MethodParameter { @Nullable ImmutableList annotations, @Nullable String name) { this.type = type; - this.annotations = Objects.firstNonNull(annotations, ImmutableList.of()); + this.annotations = ImmutableListUtils.nullToEmptyList(annotations); this.name = name; } @@ -80,7 +80,8 @@ public class ImmutableMethodParameter implements MethodParameter { @Nullable @Override public String getSignature() { return null; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf( + @Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java index 8b160396..85d0c70c 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/ImmutableTryBlock.java @@ -31,11 +31,11 @@ package org.jf.dexlib2.immutable; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.ExceptionHandler; import org.jf.dexlib2.iface.TryBlock; import org.jf.util.ImmutableListConverter; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -59,7 +59,7 @@ public class ImmutableTryBlock implements TryBlock { @Nullable ImmutableList exceptionHandlers) { this.startCodeOffset = startCodeOffset; this.codeUnitCount = codeUnitCount; - this.exceptionHandlers = Objects.firstNonNull(exceptionHandlers, ImmutableList.of()); + this.exceptionHandlers = ImmutableListUtils.nullToEmptyList(exceptionHandlers); } public static ImmutableTryBlock of(TryBlock tryBlock) { @@ -80,7 +80,7 @@ public class ImmutableTryBlock implements TryBlock { } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableArrayPayload.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableArrayPayload.java index ed1cd9b7..decf004d 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableArrayPayload.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableArrayPayload.java @@ -31,11 +31,11 @@ package org.jf.dexlib2.immutable.instruction; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.Format; import org.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -60,7 +60,7 @@ public class ImmutableArrayPayload extends ImmutableInstruction implements Array //TODO: need to ensure this is a valid width (1, 2, 4, 8) this.elementWidth = elementWidth; //TODO: need to validate the elements fit within the width - this.arrayElements = Objects.firstNonNull(arrayElements, ImmutableList.of()); + this.arrayElements = ImmutableListUtils.nullToEmptyList(arrayElements); } @Nonnull diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutablePackedSwitchPayload.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutablePackedSwitchPayload.java index abb020a4..47814139 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutablePackedSwitchPayload.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutablePackedSwitchPayload.java @@ -31,12 +31,12 @@ package org.jf.dexlib2.immutable.instruction; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.Format; import org.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -56,7 +56,7 @@ public class ImmutablePackedSwitchPayload extends ImmutableInstruction implement public ImmutablePackedSwitchPayload( @Nullable ImmutableList switchElements) { super(OPCODE); - this.switchElements = Objects.firstNonNull(switchElements, ImmutableList.of()); + this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements); } @Nonnull diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSparseSwitchPayload.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSparseSwitchPayload.java index 64e94483..710a3c55 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSparseSwitchPayload.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSparseSwitchPayload.java @@ -31,13 +31,12 @@ package org.jf.dexlib2.immutable.instruction; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.Format; import org.jf.dexlib2.Opcode; import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; -import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -56,7 +55,7 @@ public class ImmutableSparseSwitchPayload extends ImmutableInstruction implement public ImmutableSparseSwitchPayload( @Nullable ImmutableList switchElements) { super(OPCODE); - this.switchElements = Objects.firstNonNull(switchElements, ImmutableList.of()); + this.switchElements = ImmutableListUtils.nullToEmptyList(switchElements); } @Nonnull diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSwitchElement.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSwitchElement.java index 0373efac..b7830f25 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSwitchElement.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/instruction/ImmutableSwitchElement.java @@ -36,6 +36,7 @@ import org.jf.dexlib2.iface.instruction.SwitchElement; import org.jf.util.ImmutableListConverter; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.util.List; public class ImmutableSwitchElement implements SwitchElement { @@ -62,7 +63,7 @@ public class ImmutableSwitchElement implements SwitchElement { @Override public int getOffset() { return offset; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/reference/ImmutableMethodReference.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/reference/ImmutableMethodReference.java index cbb98971..a690f181 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/reference/ImmutableMethodReference.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/reference/ImmutableMethodReference.java @@ -31,10 +31,10 @@ package org.jf.dexlib2.immutable.reference; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.iface.reference.BasicMethodParameter; import org.jf.dexlib2.iface.reference.MethodReference; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -62,7 +62,7 @@ public class ImmutableMethodReference extends ImmutableReference implements Meth @Nonnull String returnType) { this.containingClass = containingClass; this.name = name; - this.parameters = Objects.firstNonNull(parameters, ImmutableList.of()); + this.parameters = ImmutableListUtils.nullToEmptyList(parameters); this.returnType = returnType; } diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java index f1ba0b8c..b20da552 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableAnnotationEncodedValue.java @@ -31,12 +31,12 @@ package org.jf.dexlib2.immutable.value; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import org.jf.dexlib2.ValueType; import org.jf.dexlib2.iface.AnnotationElement; import org.jf.dexlib2.immutable.ImmutableAnnotationElement; import org.jf.dexlib2.iface.value.AnnotationEncodedValue; +import org.jf.util.ImmutableListUtils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -57,7 +57,7 @@ public class ImmutableAnnotationEncodedValue extends ImmutableEncodedValue imple @Nullable ImmutableList elements) { super(ValueType.ANNOTATION); this.type = type; - this.elements = Objects.firstNonNull(elements, ImmutableList.of()); + this.elements = ImmutableListUtils.nullToEmptyList(elements); } public static ImmutableAnnotationEncodedValue of(AnnotationEncodedValue annotationEncodedValue) { diff --git a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java index c65fff91..442efe4b 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/immutable/value/ImmutableEncodedValue.java @@ -95,7 +95,7 @@ public class ImmutableEncodedValue implements EncodedValue { public int getValueType() { return type; } @Nonnull - public static ImmutableList immutableListOf(List list) { + public static ImmutableList immutableListOf(@Nullable List list) { return CONVERTER.convert(list); } diff --git a/util/src/main/java/org/jf/util/ImmutableListUtils.java b/util/src/main/java/org/jf/util/ImmutableListUtils.java new file mode 100644 index 00000000..35743dd3 --- /dev/null +++ b/util/src/main/java/org/jf/util/ImmutableListUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.jf.util; + +import com.google.common.collect.ImmutableList; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class ImmutableListUtils { + @Nonnull public static ImmutableList nullToEmptyList(@Nullable ImmutableList list) { + if (list == null) { + return ImmutableList.of(); + } + return list; + } +}