10888a09821a98ac0680fad765217302858e70fa4Paul Duffin/* 20888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Copyright (C) 2008 The Guava Authors 30888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 40888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License"); 50888a09821a98ac0680fad765217302858e70fa4Paul Duffin * you may not use this file except in compliance with the License. 60888a09821a98ac0680fad765217302858e70fa4Paul Duffin * You may obtain a copy of the License at 70888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 80888a09821a98ac0680fad765217302858e70fa4Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0 90888a09821a98ac0680fad765217302858e70fa4Paul Duffin * 100888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Unless required by applicable law or agreed to in writing, software 110888a09821a98ac0680fad765217302858e70fa4Paul Duffin * distributed under the License is distributed on an "AS IS" BASIS, 120888a09821a98ac0680fad765217302858e70fa4Paul Duffin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130888a09821a98ac0680fad765217302858e70fa4Paul Duffin * See the License for the specific language governing permissions and 140888a09821a98ac0680fad765217302858e70fa4Paul Duffin * limitations under the License. 150888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 160888a09821a98ac0680fad765217302858e70fa4Paul Duffin 170888a09821a98ac0680fad765217302858e70fa4Paul Duffinpackage com.google.common.collect; 180888a09821a98ac0680fad765217302858e70fa4Paul Duffin 190888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport static com.google.common.base.Preconditions.checkState; 200888a09821a98ac0680fad765217302858e70fa4Paul Duffin 210888a09821a98ac0680fad765217302858e70fa4Paul Duffinimport com.google.common.annotations.GwtCompatible; 220888a09821a98ac0680fad765217302858e70fa4Paul Duffin 230888a09821a98ac0680fad765217302858e70fa4Paul Duffin/** 240888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Precondition checks useful in collection implementations. 250888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 260888a09821a98ac0680fad765217302858e70fa4Paul Duffin@GwtCompatible 270888a09821a98ac0680fad765217302858e70fa4Paul Duffinfinal class CollectPreconditions { 280888a09821a98ac0680fad765217302858e70fa4Paul Duffin 290888a09821a98ac0680fad765217302858e70fa4Paul Duffin static void checkEntryNotNull(Object key, Object value) { 300888a09821a98ac0680fad765217302858e70fa4Paul Duffin if (key == null) { 310888a09821a98ac0680fad765217302858e70fa4Paul Duffin throw new NullPointerException("null key in entry: null=" + value); 320888a09821a98ac0680fad765217302858e70fa4Paul Duffin } else if (value == null) { 330888a09821a98ac0680fad765217302858e70fa4Paul Duffin throw new NullPointerException("null value in entry: " + key + "=null"); 340888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 350888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 360888a09821a98ac0680fad765217302858e70fa4Paul Duffin 370888a09821a98ac0680fad765217302858e70fa4Paul Duffin static int checkNonnegative(int value, String name) { 380888a09821a98ac0680fad765217302858e70fa4Paul Duffin if (value < 0) { 390888a09821a98ac0680fad765217302858e70fa4Paul Duffin throw new IllegalArgumentException(name + " cannot be negative but was: " + value); 400888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 410888a09821a98ac0680fad765217302858e70fa4Paul Duffin return value; 420888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 430888a09821a98ac0680fad765217302858e70fa4Paul Duffin 440888a09821a98ac0680fad765217302858e70fa4Paul Duffin /** 450888a09821a98ac0680fad765217302858e70fa4Paul Duffin * Precondition tester for {@code Iterator.remove()} that throws an exception with a consistent 460888a09821a98ac0680fad765217302858e70fa4Paul Duffin * error message. 470888a09821a98ac0680fad765217302858e70fa4Paul Duffin */ 480888a09821a98ac0680fad765217302858e70fa4Paul Duffin static void checkRemove(boolean canRemove) { 490888a09821a98ac0680fad765217302858e70fa4Paul Duffin checkState(canRemove, "no calls to next() since the last call to remove()"); 500888a09821a98ac0680fad765217302858e70fa4Paul Duffin } 510888a09821a98ac0680fad765217302858e70fa4Paul Duffin} 52