// Copyright 2004-present Facebook. All Rights Reserved. package com.facebook.infer.annotation; import javax.annotation.Nullable; import java.util.List; import java.util.Map; public class Assertions { public static T assumeNotNull(@Nullable T object) { return object; } public static T assumeNotNull(@Nullable T object, String explanation) { return object; } public static T assertNotNull(@Nullable T object) { if (object == null) { throw new AssertionError(); } return object; } public static T assertNotNull(@Nullable T object, String explanation) { if (object == null) { throw new AssertionError(explanation); } return object; } public static T getAssumingNotNull(List list, int index) { return list.get(index); } public static T getAssertingNotNull(List list, int index) { assertCondition(0 <= index && index < list.size()); return assertNotNull(list.get(index)); } public static V getAssumingNotNull(Map map, K key) { return map.get(key); } public static V getAssertingNotNull(Map map, K key) { assertCondition(map.containsKey(key)); return assertNotNull(map.get(key)); } public static void assumeCondition(boolean condition) { } public static void assumeCondition(boolean condition, String explanation) { } public static void assertCondition(boolean condition) { if (!condition) { throw new AssertionError(); } } public static void assertCondition(boolean condition, String explanation) { if (!condition) { throw new AssertionError(explanation); } } public static AssertionError assertUnreachable() { throw new AssertionError(); } public static AssertionError assertUnreachable(String explanation) { throw new AssertionError(explanation); } public static AssertionError assertUnreachable(Exception exception) { throw new AssertionError(exception); } }