code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231
values | license stringclasses 13
values | size int64 1 2.01M |
|---|---|---|---|---|---|
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SingletonImmutableTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCellSet() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testCellSet();
}
public void testClear() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testColumn();
}
public void testColumnKeySet() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testColumnKeySet();
}
public void testColumnMap() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testColumnMap();
}
public void testConsistentHashCode() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testConsistentHashCode();
}
public void testConsistentToString() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testConsistentToString();
}
public void testContains() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testContainsValue();
}
public void testEqualsObject() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testEqualsObject();
}
public void testGet() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testGet();
}
public void testHashCode() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testPut();
}
public void testPutAll() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testPutAll();
}
public void testRemove() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testRow();
}
public void testRowKeySet() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testRowKeySet();
}
public void testRowMap() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testRowMap();
}
public void testSize() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testSize();
}
public void testToString() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testToString();
}
public void testValues() throws Exception {
com.google.common.collect.SingletonImmutableTableTest testCase = new com.google.common.collect.SingletonImmutableTableTest();
testCase.testValues();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SingletonImmutableTableTest_gwt.java | Java | asf20 | 5,741 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class GeneralRangeTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreateEmptyRangeClosedOpenSucceeds() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testCreateEmptyRangeClosedOpenSucceeds();
}
public void testCreateEmptyRangeFails() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testCreateEmptyRangeFails();
}
public void testCreateEmptyRangeOpenClosedSucceeds() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testCreateEmptyRangeOpenClosedSucceeds();
}
public void testCreateEmptyRangeOpenOpenFails() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testCreateEmptyRangeOpenOpenFails();
}
public void testCreateSingletonRangeSucceeds() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testCreateSingletonRangeSucceeds();
}
public void testDoublyBoundedAgainstRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testDoublyBoundedAgainstRange();
}
public void testFromRangeAll() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testFromRangeAll();
}
public void testFromRangeOneEnd() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testFromRangeOneEnd();
}
public void testFromRangeTwoEnds() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testFromRangeTwoEnds();
}
public void testIntersectAgainstBiggerRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testIntersectAgainstBiggerRange();
}
public void testIntersectAgainstMatchingEndpointsRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testIntersectAgainstMatchingEndpointsRange();
}
public void testIntersectAgainstSmallerRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testIntersectAgainstSmallerRange();
}
public void testIntersectNonOverlappingRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testIntersectNonOverlappingRange();
}
public void testIntersectOverlappingRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testIntersectOverlappingRange();
}
public void testLowerRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testLowerRange();
}
public void testReverse() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testReverse();
}
public void testSingletonRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testSingletonRange();
}
public void testUpperRange() throws Exception {
com.google.common.collect.GeneralRangeTest testCase = new com.google.common.collect.GeneralRangeTest();
testCase.testUpperRange();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/GeneralRangeTest_gwt.java | Java | asf20 | 4,604 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class TransposedTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testColumn();
}
public void testColumnNull() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testColumnNull();
}
public void testColumnSetPartialOverlap() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testColumnSetPartialOverlap();
}
public void testContains() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testContainsValue();
}
public void testEquals() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testEquals();
}
public void testGet() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testGet();
}
public void testHashCode() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPut();
}
public void testPutAllTable() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPutAllTable();
}
public void testPutNull() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPutNull();
}
public void testPutNullReplace() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPutNullReplace();
}
public void testPutOriginalModifiesTranspose() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPutOriginalModifiesTranspose();
}
public void testPutTransposeModifiesOriginal() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testPutTransposeModifiesOriginal();
}
public void testRemove() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testRow();
}
public void testRowClearAndPut() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testRowClearAndPut();
}
public void testRowNull() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testRowNull();
}
public void testSize() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testSize();
}
public void testToStringSize1() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testToStringSize1();
}
public void testTransposeTransposed() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testTransposeTransposed();
}
public void testTransposedViews() throws Exception {
com.google.common.collect.TransposedTableTest testCase = new com.google.common.collect.TransposedTableTest();
testCase.setUp();
testCase.testTransposedViews();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/TransposedTableTest_gwt.java | Java | asf20 | 6,381 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class PeekingIteratorTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCantRemoveAfterPeek() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testCantRemoveAfterPeek();
}
public void testPeekDoesntChangeIteration() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testPeekDoesntChangeIteration();
}
public void testPeekOnEmptyList() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testPeekOnEmptyList();
}
public void testPeekingIteratorBehavesLikeIteratorOnEmptyIterable() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testPeekingIteratorBehavesLikeIteratorOnEmptyIterable();
}
public void testPeekingIteratorBehavesLikeIteratorOnSingletonIterable() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testPeekingIteratorBehavesLikeIteratorOnSingletonIterable();
}
public void testPeekingIteratorDoesntAdvancePrematurely() throws Exception {
com.google.common.collect.PeekingIteratorTest testCase = new com.google.common.collect.PeekingIteratorTest();
testCase.testPeekingIteratorDoesntAdvancePrematurely();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/PeekingIteratorTest_gwt.java | Java | asf20 | 2,249 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableMultisetTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAsList() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testAsList();
}
public void testBuilderAdd() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAdd();
}
public void testBuilderAddAll() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddAll();
}
public void testBuilderAddAllHandlesNullsCorrectly() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddAllHandlesNullsCorrectly();
}
public void testBuilderAddAllIterator() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddAllIterator();
}
public void testBuilderAddAllMultiset() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddAllMultiset();
}
public void testBuilderAddCopies() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddCopies();
}
public void testBuilderAddCopiesHandlesNullsCorrectly() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddCopiesHandlesNullsCorrectly();
}
public void testBuilderAddCopiesIllegal() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddCopiesIllegal();
}
public void testBuilderAddHandlesNullsCorrectly() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderAddHandlesNullsCorrectly();
}
public void testBuilderSetCount() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderSetCount();
}
public void testBuilderSetCountHandlesNullsCorrectly() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderSetCountHandlesNullsCorrectly();
}
public void testBuilderSetCountIllegal() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testBuilderSetCountIllegal();
}
public void testCopyOf_collectionContainingNull() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_collectionContainingNull();
}
public void testCopyOf_collection_empty() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_collection_empty();
}
public void testCopyOf_collection_general() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_collection_general();
}
public void testCopyOf_collection_oneElement() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_collection_oneElement();
}
public void testCopyOf_iteratorContainingNull() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_iteratorContainingNull();
}
public void testCopyOf_iterator_empty() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_iterator_empty();
}
public void testCopyOf_iterator_general() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_iterator_general();
}
public void testCopyOf_iterator_oneElement() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_iterator_oneElement();
}
public void testCopyOf_multisetContainingNull() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_multisetContainingNull();
}
public void testCopyOf_multiset_empty() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_multiset_empty();
}
public void testCopyOf_multiset_general() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_multiset_general();
}
public void testCopyOf_multiset_oneElement() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_multiset_oneElement();
}
public void testCopyOf_plainIterable() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_plainIterable();
}
public void testCopyOf_shortcut_empty() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_shortcut_empty();
}
public void testCopyOf_shortcut_immutableMultiset() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_shortcut_immutableMultiset();
}
public void testCopyOf_shortcut_singleton() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCopyOf_shortcut_singleton();
}
public void testCreation_arrayContainingOnlyNull() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_arrayContainingOnlyNull();
}
public void testCreation_arrayOfArray() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_arrayOfArray();
}
public void testCreation_arrayOfOneElement() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_arrayOfOneElement();
}
public void testCreation_emptyArray() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_emptyArray();
}
public void testCreation_fiveElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_fiveElements();
}
public void testCreation_fourElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_fourElements();
}
public void testCreation_noArgs() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_noArgs();
}
public void testCreation_oneElement() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_oneElement();
}
public void testCreation_sevenElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_sevenElements();
}
public void testCreation_sixElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_sixElements();
}
public void testCreation_threeElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_threeElements();
}
public void testCreation_twoElements() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testCreation_twoElements();
}
public void testEquals() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testEquals();
}
public void testEquals_immutableMultiset() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testEquals_immutableMultiset();
}
public void testIterationOrder() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testIterationOrder();
}
public void testMultisetWrites() throws Exception {
com.google.common.collect.ImmutableMultisetTest testCase = new com.google.common.collect.ImmutableMultisetTest();
testCase.testMultisetWrites();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableMultisetTest_gwt.java | Java | asf20 | 10,749 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class IteratorsTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAddAllToList() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAddAllToList();
}
public void testAddAllToSet() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAddAllToSet();
}
public void testAddAllWithEmptyIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAddAllWithEmptyIterator();
}
public void testAdvance_basic() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAdvance_basic();
}
public void testAdvance_illegalArgument() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAdvance_illegalArgument();
}
public void testAdvance_pastEnd() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAdvance_pastEnd();
}
public void testAll() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAll();
}
public void testAny() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAny();
}
public void testAsEnumerationEmpty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAsEnumerationEmpty();
}
public void testAsEnumerationSingleton() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAsEnumerationSingleton();
}
public void testAsEnumerationTypical() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testAsEnumerationTypical();
}
public void testConcatContainingNull() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testConcatContainingNull();
}
public void testConcatVarArgsContainingNull() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testConcatVarArgsContainingNull();
}
public void testConsumingIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testConsumingIterator();
}
public void testCycleNoSuchElementException() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleNoSuchElementException();
}
public void testCycleOfEmpty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleOfEmpty();
}
public void testCycleOfOne() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleOfOne();
}
public void testCycleOfOneWithRemove() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleOfOneWithRemove();
}
public void testCycleOfTwo() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleOfTwo();
}
public void testCycleOfTwoWithRemove() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleOfTwoWithRemove();
}
public void testCycleRemoveAfterHasNext() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleRemoveAfterHasNext();
}
public void testCycleRemoveSameElementTwice() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleRemoveSameElementTwice();
}
public void testCycleRemoveWithoutNext() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleRemoveWithoutNext();
}
public void testCycleWhenRemoveIsNotSupported() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testCycleWhenRemoveIsNotSupported();
}
public void testElementsEqual() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testElementsEqual();
}
public void testEmptyIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testEmptyIterator();
}
public void testEmptyListIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testEmptyListIterator();
}
public void testEmptyModifiableIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testEmptyModifiableIterator();
}
public void testFilterMatchAll() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFilterMatchAll();
}
public void testFilterNoMatch() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFilterNoMatch();
}
public void testFilterNothing() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFilterNothing();
}
public void testFilterSimple() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFilterSimple();
}
public void testFind_firstElement() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_firstElement();
}
public void testFind_lastElement() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_lastElement();
}
public void testFind_matchAlways() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_matchAlways();
}
public void testFind_notPresent() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_notPresent();
}
public void testFind_withDefault_first() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_withDefault_first();
}
public void testFind_withDefault_last() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_withDefault_last();
}
public void testFind_withDefault_matchAlways() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_withDefault_matchAlways();
}
public void testFind_withDefault_notPresent() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_withDefault_notPresent();
}
public void testFind_withDefault_notPresent_nullReturn() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFind_withDefault_notPresent_nullReturn();
}
public void testForArrayEmpty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForArrayEmpty();
}
public void testForArrayLength0() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForArrayLength0();
}
public void testForArrayOffset() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForArrayOffset();
}
public void testForArrayTypical() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForArrayTypical();
}
public void testForEnumerationEmpty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForEnumerationEmpty();
}
public void testForEnumerationSingleton() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForEnumerationSingleton();
}
public void testForEnumerationTypical() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testForEnumerationTypical();
}
public void testFrequency() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testFrequency();
}
public void testGetLast_basic() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_basic();
}
public void testGetLast_exception() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_exception();
}
public void testGetLast_withDefault_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_withDefault_empty();
}
public void testGetLast_withDefault_empty_null() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_withDefault_empty_null();
}
public void testGetLast_withDefault_singleton() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_withDefault_singleton();
}
public void testGetLast_withDefault_two() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetLast_withDefault_two();
}
public void testGetNext_withDefault_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetNext_withDefault_empty();
}
public void testGetNext_withDefault_empty_null() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetNext_withDefault_empty_null();
}
public void testGetNext_withDefault_singleton() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetNext_withDefault_singleton();
}
public void testGetNext_withDefault_two() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetNext_withDefault_two();
}
public void testGetOnlyElement_noDefault_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_noDefault_empty();
}
public void testGetOnlyElement_noDefault_fiveElements() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_noDefault_fiveElements();
}
public void testGetOnlyElement_noDefault_moreThanFiveElements() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_noDefault_moreThanFiveElements();
}
public void testGetOnlyElement_noDefault_moreThanOneLessThanFiveElements() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_noDefault_moreThanOneLessThanFiveElements();
}
public void testGetOnlyElement_noDefault_valid() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_noDefault_valid();
}
public void testGetOnlyElement_withDefault_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_withDefault_empty();
}
public void testGetOnlyElement_withDefault_empty_null() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_withDefault_empty_null();
}
public void testGetOnlyElement_withDefault_singleton() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_withDefault_singleton();
}
public void testGetOnlyElement_withDefault_two() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGetOnlyElement_withDefault_two();
}
public void testGet_atSize() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_atSize();
}
public void testGet_basic() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_basic();
}
public void testGet_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_empty();
}
public void testGet_negativeIndex() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_negativeIndex();
}
public void testGet_pastEnd() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_pastEnd();
}
public void testGet_withDefault_atSize() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_withDefault_atSize();
}
public void testGet_withDefault_basic() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_withDefault_basic();
}
public void testGet_withDefault_negativeIndex() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_withDefault_negativeIndex();
}
public void testGet_withDefault_pastEnd() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testGet_withDefault_pastEnd();
}
public void testIndexOf_consumedData() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testIndexOf_consumedData();
}
public void testIndexOf_consumedDataNoMatch() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testIndexOf_consumedDataNoMatch();
}
public void testIndexOf_consumedDataWithDuplicates() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testIndexOf_consumedDataWithDuplicates();
}
public void testLimit() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testLimit();
}
public void testLimitRemove() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testLimitRemove();
}
public void testNullFriendlyTransform() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testNullFriendlyTransform();
}
public void testPaddedPartitionRandomAccess() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartitionRandomAccess();
}
public void testPaddedPartition_badSize() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartition_badSize();
}
public void testPaddedPartition_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartition_empty();
}
public void testPaddedPartition_singleton1() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartition_singleton1();
}
public void testPaddedPartition_singleton2() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartition_singleton2();
}
public void testPaddedPartition_view() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPaddedPartition_view();
}
public void testPartition_badSize() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPartition_badSize();
}
public void testPartition_empty() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPartition_empty();
}
public void testPartition_singleton1() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPartition_singleton1();
}
public void testPartition_singleton2() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPartition_singleton2();
}
public void testPartition_view() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPartition_view();
}
public void testPeekingIteratorShortCircuit() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPeekingIteratorShortCircuit();
}
public void testPoorlyBehavedTransform() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testPoorlyBehavedTransform();
}
public void testRemoveAll() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testRemoveAll();
}
public void testRemoveIf() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testRemoveIf();
}
public void testRetainAll() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testRetainAll();
}
public void testSize0() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testSize0();
}
public void testSize1() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testSize1();
}
public void testSize_partiallyConsumed() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testSize_partiallyConsumed();
}
public void testToString() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testToString();
}
public void testToStringEmptyIterator() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testToStringEmptyIterator();
}
public void testToStringWithNull() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testToStringWithNull();
}
public void testTransform() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTransform();
}
public void testTransformRemove() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTransformRemove();
}
public void testTryFind_alwaysFalse_isPresent() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTryFind_alwaysFalse_isPresent();
}
public void testTryFind_alwaysFalse_orDefault() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTryFind_alwaysFalse_orDefault();
}
public void testTryFind_alwaysTrue() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTryFind_alwaysTrue();
}
public void testTryFind_firstElement() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTryFind_firstElement();
}
public void testTryFind_lastElement() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testTryFind_lastElement();
}
public void testUnmodifiableIteratorShortCircuit() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.testUnmodifiableIteratorShortCircuit();
}
public void test_contains_nonnull_no() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.test_contains_nonnull_no();
}
public void test_contains_nonnull_yes() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.test_contains_nonnull_yes();
}
public void test_contains_null_no() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.test_contains_null_no();
}
public void test_contains_null_yes() throws Exception {
com.google.common.collect.IteratorsTest testCase = new com.google.common.collect.IteratorsTest();
testCase.test_contains_null_yes();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/IteratorsTest_gwt.java | Java | asf20 | 24,227 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class RegularImmutableAsListTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testDoesntCheckForNull() throws Exception {
com.google.common.collect.RegularImmutableAsListTest testCase = new com.google.common.collect.RegularImmutableAsListTest();
testCase.testDoesntCheckForNull();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/RegularImmutableAsListTest_gwt.java | Java | asf20 | 1,046 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SortedIterablesTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testComparator() throws Exception {
com.google.common.collect.SortedIterablesTest testCase = new com.google.common.collect.SortedIterablesTest();
testCase.testComparator();
}
public void testSameComparator() throws Exception {
com.google.common.collect.SortedIterablesTest testCase = new com.google.common.collect.SortedIterablesTest();
testCase.testSameComparator();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SortedIterablesTest_gwt.java | Java | asf20 | 1,209 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testBuilder() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder();
}
public void testBuilder_noDuplicates() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_noDuplicates();
}
public void testBuilder_noNulls() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_noNulls();
}
public void testBuilder_orderColumnsBy_dense() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderColumnsBy_dense();
}
public void testBuilder_orderColumnsBy_sparse() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderColumnsBy_sparse();
}
public void testBuilder_orderRowsAndColumnsBy_dense() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderRowsAndColumnsBy_dense();
}
public void testBuilder_orderRowsAndColumnsBy_putAll() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderRowsAndColumnsBy_putAll();
}
public void testBuilder_orderRowsAndColumnsBy_sparse() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderRowsAndColumnsBy_sparse();
}
public void testBuilder_orderRowsBy_dense() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderRowsBy_dense();
}
public void testBuilder_orderRowsBy_sparse() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_orderRowsBy_sparse();
}
public void testBuilder_withImmutableCell() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_withImmutableCell();
}
public void testBuilder_withImmutableCellAndNullContents() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_withImmutableCellAndNullContents();
}
public void testBuilder_withMutableCell() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testBuilder_withMutableCell();
}
public void testColumn() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testColumn();
}
public void testColumnNull() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testColumnNull();
}
public void testColumnSetPartialOverlap() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testColumnSetPartialOverlap();
}
public void testContains() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testContainsValue();
}
public void testCopyOf() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testCopyOf();
}
public void testCopyOfDense() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testCopyOfDense();
}
public void testCopyOfSparse() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testCopyOfSparse();
}
public void testEquals() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testEquals();
}
public void testGet() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testGet();
}
public void testHashCode() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testIsEmpty();
}
public void testRow() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testRow();
}
public void testRowNull() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testRowNull();
}
public void testSize() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testSize();
}
public void testToStringSize1() throws Exception {
com.google.common.collect.ImmutableTableTest testCase = new com.google.common.collect.ImmutableTableTest();
testCase.setUp();
testCase.testToStringSize1();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableTableTest_gwt.java | Java | asf20 | 7,726 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class IterablesTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAddAllToList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testAddAllToList();
}
public void testAll() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testAll();
}
public void testAny() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testAny();
}
public void testConcatIterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConcatIterable();
}
public void testConcatNullPointerException() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConcatNullPointerException();
}
public void testConcatPeformingFiniteCycle() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConcatPeformingFiniteCycle();
}
public void testConcatVarargs() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConcatVarargs();
}
public void testConsumingIterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConsumingIterable();
}
public void testConsumingIterable_noIteratorCall() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConsumingIterable_noIteratorCall();
}
public void testConsumingIterable_queue_iterator() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConsumingIterable_queue_iterator();
}
public void testConsumingIterable_queue_removesFromQueue() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testConsumingIterable_queue_removesFromQueue();
}
public void testCycle() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testCycle();
}
public void testElementsEqual() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testElementsEqual();
}
public void testFind() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testFind();
}
public void testFind_withDefault() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testFind_withDefault();
}
public void testFrequency_list() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testFrequency_list();
}
public void testFrequency_multiset() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testFrequency_multiset();
}
public void testFrequency_set() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testFrequency_set();
}
public void testGetFirst_withDefault_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetFirst_withDefault_empty();
}
public void testGetFirst_withDefault_empty_null() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetFirst_withDefault_empty_null();
}
public void testGetFirst_withDefault_multiple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetFirst_withDefault_multiple();
}
public void testGetFirst_withDefault_singleton() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetFirst_withDefault_singleton();
}
public void testGetLast_emptyIterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_emptyIterable();
}
public void testGetLast_emptyList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_emptyList();
}
public void testGetLast_emptySortedSet() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_emptySortedSet();
}
public void testGetLast_iterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_iterable();
}
public void testGetLast_list() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_list();
}
public void testGetLast_sortedSet() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_sortedSet();
}
public void testGetLast_withDefault_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_withDefault_empty();
}
public void testGetLast_withDefault_empty_null() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_withDefault_empty_null();
}
public void testGetLast_withDefault_multiple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_withDefault_multiple();
}
public void testGetLast_withDefault_not_empty_list() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_withDefault_not_empty_list();
}
public void testGetLast_withDefault_singleton() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetLast_withDefault_singleton();
}
public void testGetOnlyElement_noDefault_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_noDefault_empty();
}
public void testGetOnlyElement_noDefault_multiple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_noDefault_multiple();
}
public void testGetOnlyElement_noDefault_valid() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_noDefault_valid();
}
public void testGetOnlyElement_withDefault_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_withDefault_empty();
}
public void testGetOnlyElement_withDefault_empty_null() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_withDefault_empty_null();
}
public void testGetOnlyElement_withDefault_multiple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_withDefault_multiple();
}
public void testGetOnlyElement_withDefault_singleton() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGetOnlyElement_withDefault_singleton();
}
public void testGet_emptyIterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_emptyIterable();
}
public void testGet_emptyList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_emptyList();
}
public void testGet_emptySortedSet() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_emptySortedSet();
}
public void testGet_iterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_iterable();
}
public void testGet_list() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_list();
}
public void testGet_sortedSet() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_sortedSet();
}
public void testGet_withDefault_doesntIterate() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_doesntIterate();
}
public void testGet_withDefault_iterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_iterable();
}
public void testGet_withDefault_last() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_last();
}
public void testGet_withDefault_lastPlusOne() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_lastPlusOne();
}
public void testGet_withDefault_negativePosition() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_negativePosition();
}
public void testGet_withDefault_simple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testGet_withDefault_simple();
}
public void testIndexOf_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_empty();
}
public void testIndexOf_genericPredicate() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_genericPredicate();
}
public void testIndexOf_genericPredicate2() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_genericPredicate2();
}
public void testIndexOf_oneElement() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_oneElement();
}
public void testIndexOf_twoElements() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_twoElements();
}
public void testIndexOf_withDuplicates() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIndexOf_withDuplicates();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIsEmpty();
}
public void testIterableWithToString() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIterableWithToString();
}
public void testIterableWithToStringNull() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testIterableWithToStringNull();
}
public void testLimit() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testLimit();
}
public void testLimit_illegalArgument() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testLimit_illegalArgument();
}
public void testMergeSorted_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testMergeSorted_empty();
}
public void testMergeSorted_pyramid() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testMergeSorted_pyramid();
}
public void testMergeSorted_single() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testMergeSorted_single();
}
public void testMergeSorted_single_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testMergeSorted_single_empty();
}
public void testMergeSorted_skipping_pyramid() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testMergeSorted_skipping_pyramid();
}
public void testNullFriendlyTransform() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testNullFriendlyTransform();
}
public void testPaddedPartitionNonRandomAccessInput() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPaddedPartitionNonRandomAccessInput();
}
public void testPaddedPartitionRandomAccessInput() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPaddedPartitionRandomAccessInput();
}
public void testPaddedPartition_basic() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPaddedPartition_basic();
}
public void testPartition_badSize() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPartition_badSize();
}
public void testPartition_empty() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPartition_empty();
}
public void testPartition_singleton1() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPartition_singleton1();
}
public void testPartition_view() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPartition_view();
}
public void testPoorlyBehavedTransform() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testPoorlyBehavedTransform();
}
public void testRemoveAll_collection() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRemoveAll_collection();
}
public void testRemoveAll_iterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRemoveAll_iterable();
}
public void testRemoveIf_noRandomAccess() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRemoveIf_noRandomAccess();
}
public void testRemoveIf_randomAccess() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRemoveIf_randomAccess();
}
public void testRemoveIf_transformedList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRemoveIf_transformedList();
}
public void testRetainAll_collection() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRetainAll_collection();
}
public void testRetainAll_iterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testRetainAll_iterable();
}
public void testSize0() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSize0();
}
public void testSize1Collection() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSize1Collection();
}
public void testSize2NonCollection() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSize2NonCollection();
}
public void testSize_collection_doesntIterate() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSize_collection_doesntIterate();
}
public void testSkip_allOfImmutableList_modifiable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_allOfImmutableList_modifiable();
}
public void testSkip_allOfMutableList_modifiable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_allOfMutableList_modifiable();
}
public void testSkip_illegalArgument() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_illegalArgument();
}
public void testSkip_nonStructurallyModifiedList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_nonStructurallyModifiedList();
}
public void testSkip_pastEnd() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_pastEnd();
}
public void testSkip_pastEndList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_pastEndList();
}
public void testSkip_removal() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_removal();
}
public void testSkip_simple() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_simple();
}
public void testSkip_simpleList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_simpleList();
}
public void testSkip_skipNone() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_skipNone();
}
public void testSkip_skipNoneList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_skipNoneList();
}
public void testSkip_structurallyModifiedSkipAll() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_structurallyModifiedSkipAll();
}
public void testSkip_structurallyModifiedSkipAllList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_structurallyModifiedSkipAllList();
}
public void testSkip_structurallyModifiedSkipSome() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_structurallyModifiedSkipSome();
}
public void testSkip_structurallyModifiedSkipSomeList() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testSkip_structurallyModifiedSkipSomeList();
}
public void testToString() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testToString();
}
public void testTransform() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testTransform();
}
public void testTryFind() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testTryFind();
}
public void testUnmodifiableIterable() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testUnmodifiableIterable();
}
public void testUnmodifiableIterableShortCircuit() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.testUnmodifiableIterableShortCircuit();
}
public void test_contains_nonnull_iterable_no() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_nonnull_iterable_no();
}
public void test_contains_nonnull_iterable_yes() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_nonnull_iterable_yes();
}
public void test_contains_nonnull_set_no() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_nonnull_set_no();
}
public void test_contains_nonnull_set_yes() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_nonnull_set_yes();
}
public void test_contains_null_iterable_no() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_null_iterable_no();
}
public void test_contains_null_iterable_yes() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_null_iterable_yes();
}
public void test_contains_null_set_no() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_null_set_no();
}
public void test_contains_null_set_yes() throws Exception {
com.google.common.collect.IterablesTest testCase = new com.google.common.collect.IterablesTest();
testCase.test_contains_null_set_yes();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/IterablesTest_gwt.java | Java | asf20 | 24,331 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SortedListsTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testWithDups() throws Exception {
com.google.common.collect.SortedListsTest testCase = new com.google.common.collect.SortedListsTest();
testCase.testWithDups();
}
public void testWithoutDups() throws Exception {
com.google.common.collect.SortedListsTest testCase = new com.google.common.collect.SortedListsTest();
testCase.testWithoutDups();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SortedListsTest_gwt.java | Java | asf20 | 1,179 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableEnumMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testEmptyImmutableEnumMap() throws Exception {
com.google.common.collect.ImmutableEnumMapTest testCase = new com.google.common.collect.ImmutableEnumMapTest();
testCase.testEmptyImmutableEnumMap();
}
public void testImmutableEnumMapOrdering() throws Exception {
com.google.common.collect.ImmutableEnumMapTest testCase = new com.google.common.collect.ImmutableEnumMapTest();
testCase.testImmutableEnumMapOrdering();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableEnumMapTest_gwt.java | Java | asf20 | 1,256 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class MapsTransformValuesUnmodifiableIteratorTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testClear();
}
public void testContainsKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testContainsKey();
}
public void testContainsValue() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testContainsValue();
}
public void testEntrySet() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testEqualsForSmallerMap();
}
public void testGet() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testGet();
}
public void testGetForEmptyMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testGetForEmptyMap();
}
public void testGetNull() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testGetNull();
}
public void testHashCode() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetClear();
}
public void testKeySetRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutAllNewKey();
}
public void testPutExistingKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutExistingKey();
}
public void testPutNewKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutNewKey();
}
public void testPutNullKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutNullKey();
}
public void testPutNullValue() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testPutNullValueForExistingKey();
}
public void testRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testRemove();
}
public void testRemoveMissingKey() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testRemoveMissingKey();
}
public void testSize() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testSize();
}
public void testTransformChangesAreReflectedInUnderlyingMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformChangesAreReflectedInUnderlyingMap();
}
public void testTransformEmptyMapEquality() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformEmptyMapEquality();
}
public void testTransformEntrySetContains() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformEntrySetContains();
}
public void testTransformEqualityOfMapsWithNullValues() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformEqualityOfMapsWithNullValues();
}
public void testTransformEquals() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformEquals();
}
public void testTransformIdentityFunctionEquality() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformIdentityFunctionEquality();
}
public void testTransformPutEntryIsUnsupported() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformPutEntryIsUnsupported();
}
public void testTransformReflectsUnderlyingMap() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformReflectsUnderlyingMap();
}
public void testTransformRemoveEntry() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformRemoveEntry();
}
public void testTransformSingletonMapEquality() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testTransformSingletonMapEquality();
}
public void testValues() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValues();
}
public void testValuesClear() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesClear();
}
public void testValuesIteratorRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRemove();
}
public void testValuesRemoveAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest testCase = new com.google.common.collect.MapsTransformValuesUnmodifiableIteratorTest();
testCase.testValuesRetainAllNullFromEmpty();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest_gwt.java | Java | asf20 | 17,905 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SetOperationsTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testDifference__MoreTests() throws Exception {
com.google.common.collect.SetOperationsTest.MoreTests testCase = new com.google.common.collect.SetOperationsTest.MoreTests();
testCase.setUp();
testCase.testDifference();
}
public void testIntersection__MoreTests() throws Exception {
com.google.common.collect.SetOperationsTest.MoreTests testCase = new com.google.common.collect.SetOperationsTest.MoreTests();
testCase.setUp();
testCase.testIntersection();
}
public void testSymmetricDifference__MoreTests() throws Exception {
com.google.common.collect.SetOperationsTest.MoreTests testCase = new com.google.common.collect.SetOperationsTest.MoreTests();
testCase.setUp();
testCase.testSymmetricDifference();
}
public void testUnion__MoreTests() throws Exception {
com.google.common.collect.SetOperationsTest.MoreTests testCase = new com.google.common.collect.SetOperationsTest.MoreTests();
testCase.setUp();
testCase.testUnion();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SetOperationsTest_gwt.java | Java | asf20 | 1,783 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ArrayTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAt() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testAt();
}
public void testCellReflectsChanges() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCellReflectsChanges();
}
public void testCellSetToString_ordered() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCellSetToString_ordered();
}
public void testClear() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumn();
}
public void testColumnKeyList() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnKeyList();
}
public void testColumnKeySetToString_ordered() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnKeySetToString_ordered();
}
public void testColumnMissing() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnMissing();
}
public void testColumnNull() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnNull();
}
public void testColumnPutIllegal() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnPutIllegal();
}
public void testColumnSetPartialOverlap() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testColumnSetPartialOverlap();
}
public void testContains() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testContainsValue();
}
public void testCreateCopyArrayTable() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateCopyArrayTable();
}
public void testCreateCopyEmptyTable() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateCopyEmptyTable();
}
public void testCreateCopyHashBasedTable() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateCopyHashBasedTable();
}
public void testCreateDuplicateColumns() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateDuplicateColumns();
}
public void testCreateDuplicateRows() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateDuplicateRows();
}
public void testCreateEmptyColumns() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateEmptyColumns();
}
public void testCreateEmptyRows() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testCreateEmptyRows();
}
public void testEquals() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testEquals();
}
public void testErase() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testErase();
}
public void testEraseAll() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testEraseAll();
}
public void testGet() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testGet();
}
public void testGetMissingKeys() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testGetMissingKeys();
}
public void testHashCode() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testPut();
}
public void testPutAllTable() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testPutAllTable();
}
public void testPutIllegal() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testPutIllegal();
}
public void testPutNull() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testPutNull();
}
public void testPutNullReplace() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testPutNullReplace();
}
public void testRemove() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRow();
}
public void testRowClearAndPut() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowClearAndPut();
}
public void testRowKeyList() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowKeyList();
}
public void testRowKeySetToString_ordered() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowKeySetToString_ordered();
}
public void testRowMissing() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowMissing();
}
public void testRowNull() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowNull();
}
public void testRowPutIllegal() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testRowPutIllegal();
}
public void testSerialization() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testSerialization();
}
public void testSet() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testSet();
}
public void testSize() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testSize();
}
public void testToStringSize1() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testToStringSize1();
}
public void testToString_ordered() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testToString_ordered();
}
public void testValuesToString_ordered() throws Exception {
com.google.common.collect.ArrayTableTest testCase = new com.google.common.collect.ArrayTableTest();
testCase.setUp();
testCase.testValuesToString_ordered();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ArrayTableTest_gwt.java | Java | asf20 | 10,742 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableListMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testBuilderOrderKeysAndValuesBy() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderOrderKeysAndValuesBy();
}
public void testBuilderOrderKeysBy() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderOrderKeysBy();
}
public void testBuilderOrderKeysByDuplicates() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderOrderKeysByDuplicates();
}
public void testBuilderOrderValuesBy() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderOrderValuesBy();
}
public void testBuilderPutAllIterable() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutAllIterable();
}
public void testBuilderPutAllMultimap() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutAllMultimap();
}
public void testBuilderPutAllMultimapWithDuplicates() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutAllMultimapWithDuplicates();
}
public void testBuilderPutAllVarargs() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutAllVarargs();
}
public void testBuilderPutAllWithDuplicates() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutAllWithDuplicates();
}
public void testBuilderPutNullKey() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutNullKey();
}
public void testBuilderPutNullValue() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutNullValue();
}
public void testBuilderPutWithDuplicates() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilderPutWithDuplicates();
}
public void testBuilder_withImmutableEntry() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilder_withImmutableEntry();
}
public void testBuilder_withImmutableEntryAndNullContents() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilder_withImmutableEntryAndNullContents();
}
public void testBuilder_withMutableEntry() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testBuilder_withMutableEntry();
}
public void testCopyOf() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOf();
}
public void testCopyOfEmpty() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOfEmpty();
}
public void testCopyOfImmutableListMultimap() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOfImmutableListMultimap();
}
public void testCopyOfNullKey() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOfNullKey();
}
public void testCopyOfNullValue() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOfNullValue();
}
public void testCopyOfWithDuplicates() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testCopyOfWithDuplicates();
}
public void testEmptyMultimapReads() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testEmptyMultimapReads();
}
public void testEmptyMultimapWrites() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testEmptyMultimapWrites();
}
public void testInverse() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testInverse();
}
public void testInverseMinimizesWork() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testInverseMinimizesWork();
}
public void testMultimapEquals() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testMultimapEquals();
}
public void testMultimapReads() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testMultimapReads();
}
public void testMultimapWrites() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testMultimapWrites();
}
public void testOf() throws Exception {
com.google.common.collect.ImmutableListMultimapTest testCase = new com.google.common.collect.ImmutableListMultimapTest();
testCase.testOf();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableListMultimapTest_gwt.java | Java | asf20 | 7,293 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ContiguousSetTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testContains() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testContains();
}
public void testContainsAll() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testContainsAll();
}
public void testCreate_empty() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testCreate_empty();
}
public void testCreate_noMax() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testCreate_noMax();
}
public void testCreate_noMin() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testCreate_noMin();
}
public void testEquals() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testEquals();
}
public void testFirst() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testFirst();
}
public void testHeadSet() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testHeadSet();
}
public void testHeadSet_tooSmall() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testHeadSet_tooSmall();
}
public void testIntersection() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testIntersection();
}
public void testIntersection_empty() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testIntersection_empty();
}
public void testLast() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testLast();
}
public void testRange() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testRange();
}
public void testRange_unboundedRange() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testRange_unboundedRange();
}
public void testSubSet() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testSubSet();
}
public void testSubSet_outOfOrder() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testSubSet_outOfOrder();
}
public void testSubSet_tooLarge() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testSubSet_tooLarge();
}
public void testSubSet_tooSmall() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testSubSet_tooSmall();
}
public void testTailSet() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testTailSet();
}
public void testTailSet_tooLarge() throws Exception {
com.google.common.collect.ContiguousSetTest testCase = new com.google.common.collect.ContiguousSetTest();
testCase.testTailSet_tooLarge();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ContiguousSetTest_gwt.java | Java | asf20 | 4,623 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class LinkedHashMultisetTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreate() throws Exception {
com.google.common.collect.LinkedHashMultisetTest testCase = new com.google.common.collect.LinkedHashMultisetTest();
testCase.testCreate();
}
public void testCreateFromIterable() throws Exception {
com.google.common.collect.LinkedHashMultisetTest testCase = new com.google.common.collect.LinkedHashMultisetTest();
testCase.testCreateFromIterable();
}
public void testCreateWithSize() throws Exception {
com.google.common.collect.LinkedHashMultisetTest testCase = new com.google.common.collect.LinkedHashMultisetTest();
testCase.testCreateWithSize();
}
public void testLosesPlaceInLine() throws Exception {
com.google.common.collect.LinkedHashMultisetTest testCase = new com.google.common.collect.LinkedHashMultisetTest();
testCase.testLosesPlaceInLine();
}
public void testToString() throws Exception {
com.google.common.collect.LinkedHashMultisetTest testCase = new com.google.common.collect.LinkedHashMultisetTest();
testCase.testToString();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/LinkedHashMultisetTest_gwt.java | Java | asf20 | 1,834 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAsMultimap() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testAsMultimap();
}
public void testAsMultimapCaches() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testAsMultimapCaches();
}
public void testAsMultimapWhenEmpty() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testAsMultimapWhenEmpty();
}
public void testCopyOfEnumMap() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testCopyOfEnumMap();
}
public void testEquals() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testEquals();
}
public void testMutableValues() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testMutableValues();
}
public void testNullGet() throws Exception {
com.google.common.collect.ImmutableMapTest testCase = new com.google.common.collect.ImmutableMapTest();
testCase.testNullGet();
}
public void testBuilder__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilder();
}
public void testBuilderPutAll__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutAll();
}
public void testBuilderPutAllWithEmptyMap__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutAllWithEmptyMap();
}
public void testBuilderPutImmutableEntryWithNullKeyFailsAtomically__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutImmutableEntryWithNullKeyFailsAtomically();
}
public void testBuilderPutMutableEntryWithNullKeyFailsAtomically__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutMutableEntryWithNullKeyFailsAtomically();
}
public void testBuilderPutNullKey__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutNullKey();
}
public void testBuilderPutNullKeyFailsAtomically__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutNullKeyFailsAtomically();
}
public void testBuilderPutNullKeyViaPutAll__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutNullKeyViaPutAll();
}
public void testBuilderPutNullValue__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutNullValue();
}
public void testBuilderPutNullValueViaPutAll__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderPutNullValueViaPutAll();
}
public void testBuilderReuse__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilderReuse();
}
public void testBuilder_withImmutableEntry__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilder_withImmutableEntry();
}
public void testBuilder_withImmutableEntryAndNullContents__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilder_withImmutableEntryAndNullContents();
}
public void testBuilder_withMutableEntry__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testBuilder_withMutableEntry();
}
public void testCopyOf__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testCopyOf();
}
public void testCopyOfEmptyMap__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testCopyOfEmptyMap();
}
public void testCopyOfSingletonMap__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testCopyOfSingletonMap();
}
public void testEmptyBuilder__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testEmptyBuilder();
}
public void testOf__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testOf();
}
public void testOfNullKey__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testOfNullKey();
}
public void testOfNullValue__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testOfNullValue();
}
public void testOfWithDuplicateKey__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testOfWithDuplicateKey();
}
public void testPuttingTheSameKeyTwiceThrowsOnBuild__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testPuttingTheSameKeyTwiceThrowsOnBuild();
}
public void testSingletonBuilder__CreationTests() throws Exception {
com.google.common.collect.ImmutableMapTest.CreationTests testCase = new com.google.common.collect.ImmutableMapTest.CreationTests();
testCase.testSingletonBuilder();
}
public void testClear__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testClear();
}
public void testContainsKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testContainsKey();
}
public void testContainsValue__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testContainsValue();
}
public void testEntrySet__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testEqualsForSmallerMap();
}
public void testGet__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testGet();
}
public void testGetForEmptyMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testGetForEmptyMap();
}
public void testGetNull__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testGetNull();
}
public void testHashCode__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetClear();
}
public void testKeySetRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutAllNewKey();
}
public void testPutExistingKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutExistingKey();
}
public void testPutNewKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutNewKey();
}
public void testPutNullKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutNullKey();
}
public void testPutNullValue__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testPutNullValueForExistingKey();
}
public void testRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testRemove();
}
public void testRemoveMissingKey__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testRemoveMissingKey();
}
public void testSize__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testSize();
}
public void testValues__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValues();
}
public void testValuesClear__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesClear();
}
public void testValuesIteratorRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRemove();
}
public void testValuesRemoveAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty__MapTestsWithBadHashes() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes testCase = new com.google.common.collect.ImmutableMapTest.MapTestsWithBadHashes();
testCase.testValuesRetainAllNullFromEmpty();
}
public void testClear__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testClear();
}
public void testContainsKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testContainsKey();
}
public void testContainsValue__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testContainsValue();
}
public void testEntrySet__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testEqualsForSmallerMap();
}
public void testGet__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testGet();
}
public void testGetForEmptyMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testGetForEmptyMap();
}
public void testGetNull__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testGetNull();
}
public void testHashCode__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetClear();
}
public void testKeySetRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutAllNewKey();
}
public void testPutExistingKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutExistingKey();
}
public void testPutNewKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutNewKey();
}
public void testPutNullKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutNullKey();
}
public void testPutNullValue__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testPutNullValueForExistingKey();
}
public void testRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testRemove();
}
public void testRemoveMissingKey__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testRemoveMissingKey();
}
public void testSize__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testSize();
}
public void testValues__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValues();
}
public void testValuesClear__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesClear();
}
public void testValuesIteratorRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRemove();
}
public void testValuesRemoveAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty__SingletonMapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.SingletonMapTests testCase = new com.google.common.collect.ImmutableMapTest.SingletonMapTests();
testCase.testValuesRetainAllNullFromEmpty();
}
public void testClear__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testClear();
}
public void testContainsKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testContainsKey();
}
public void testContainsValue__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testContainsValue();
}
public void testEntrySet__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testEqualsForSmallerMap();
}
public void testGet__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testGet();
}
public void testGetForEmptyMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testGetForEmptyMap();
}
public void testGetNull__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testGetNull();
}
public void testHashCode__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetClear();
}
public void testKeySetRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutAllNewKey();
}
public void testPutExistingKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutExistingKey();
}
public void testPutNewKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutNewKey();
}
public void testPutNullKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutNullKey();
}
public void testPutNullValue__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testPutNullValueForExistingKey();
}
public void testRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testRemove();
}
public void testRemoveMissingKey__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testRemoveMissingKey();
}
public void testSize__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testSize();
}
public void testValues__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValues();
}
public void testValuesClear__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesClear();
}
public void testValuesIteratorRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRemove();
}
public void testValuesRemoveAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty__MapTests() throws Exception {
com.google.common.collect.ImmutableMapTest.MapTests testCase = new com.google.common.collect.ImmutableMapTest.MapTests();
testCase.testValuesRetainAllNullFromEmpty();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableMapTest_gwt.java | Java | asf20 | 50,376 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class EnumHashBiMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreate() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testCreate();
}
public void testCreateFromMap() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testCreateFromMap();
}
public void testEntrySet() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testEntrySet();
}
public void testEnumBiMapConstructor() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testEnumBiMapConstructor();
}
public void testEnumHashBiMapConstructor() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testEnumHashBiMapConstructor();
}
public void testKeyType() throws Exception {
com.google.common.collect.EnumHashBiMapTest testCase = new com.google.common.collect.EnumHashBiMapTest();
testCase.testKeyType();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/EnumHashBiMapTest_gwt.java | Java | asf20 | 1,979 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class HashBasedTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testColumn();
}
public void testColumnNull() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testColumnNull();
}
public void testColumnSetPartialOverlap() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testColumnSetPartialOverlap();
}
public void testContains() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testContainsValue();
}
public void testCreateCopy() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testCreateCopy();
}
public void testCreateWithInvalidSizes() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testCreateWithInvalidSizes();
}
public void testCreateWithValidSizes() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testCreateWithValidSizes();
}
public void testEquals() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testEquals();
}
public void testGet() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testGet();
}
public void testHashCode() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testPut();
}
public void testPutAllTable() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testPutAllTable();
}
public void testPutNull() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testPutNull();
}
public void testPutNullReplace() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testPutNullReplace();
}
public void testRemove() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testRow();
}
public void testRowClearAndPut() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testRowClearAndPut();
}
public void testRowNull() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testRowNull();
}
public void testSize() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testSize();
}
public void testToStringSize1() throws Exception {
com.google.common.collect.HashBasedTableTest testCase = new com.google.common.collect.HashBasedTableTest();
testCase.setUp();
testCase.testToStringSize1();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/HashBasedTableTest_gwt.java | Java | asf20 | 6,062 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ObjectArraysTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAppendOneElement() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testAppendOneElement();
}
public void testAppendTwoElements() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testAppendTwoElements();
}
public void testAppendZeroElements() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testAppendZeroElements();
}
public void testEmptyArrayToEmpty() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testEmptyArrayToEmpty();
}
public void testEmptyArrayToNonEmpty() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testEmptyArrayToNonEmpty();
}
public void testNewArray_fromArray_Empty() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNewArray_fromArray_Empty();
}
public void testNewArray_fromArray_Nonempty() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNewArray_fromArray_Nonempty();
}
public void testNewArray_fromArray_OfArray() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNewArray_fromArray_OfArray();
}
public void testNonEmptyToLonger() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNonEmptyToLonger();
}
public void testNonEmptyToSameLength() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNonEmptyToSameLength();
}
public void testNonEmptyToShorter() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testNonEmptyToShorter();
}
public void testPrependOneElement() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testPrependOneElement();
}
public void testPrependTwoElements() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testPrependTwoElements();
}
public void testPrependZeroElements() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testPrependZeroElements();
}
public void testToArrayImpl1() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testToArrayImpl1();
}
public void testToArrayImpl2() throws Exception {
com.google.common.collect.ObjectArraysTest testCase = new com.google.common.collect.ObjectArraysTest();
testCase.testToArrayImpl2();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ObjectArraysTest_gwt.java | Java | asf20 | 4,062 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect.testing;
import com.google.common.annotations.GwtCompatible;
/**
* Version of {@link GwtPlatform} used in hosted-mode. It includes methods in
* {@link Platform} that requires different implementions in web mode and
* hosted mode. It is factored out from {@link Platform} because <code>
* {@literal @}GwtScriptOnly</code> (which is applied to the emul version)
* supports only public classes and methods.
*
* @author Hayward Chan
*/
@GwtCompatible
public final class GwtPlatform {
private GwtPlatform() {}
/** See {@link Platform#clone(Object[])} */
public static <T> T[] clone(T[] array) {
return array.clone();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/testing/GwtPlatform.java | Java | asf20 | 1,278 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect.testing;
public class MinimalIterableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testing.testModule";
}
public void testFrom_empty() throws Exception {
com.google.common.collect.testing.MinimalIterableTest testCase = new com.google.common.collect.testing.MinimalIterableTest();
testCase.testFrom_empty();
}
public void testFrom_one() throws Exception {
com.google.common.collect.testing.MinimalIterableTest testCase = new com.google.common.collect.testing.MinimalIterableTest();
testCase.testFrom_one();
}
public void testOf_empty() throws Exception {
com.google.common.collect.testing.MinimalIterableTest testCase = new com.google.common.collect.testing.MinimalIterableTest();
testCase.testOf_empty();
}
public void testOf_one() throws Exception {
com.google.common.collect.testing.MinimalIterableTest testCase = new com.google.common.collect.testing.MinimalIterableTest();
testCase.testOf_one();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/testing/MinimalIterableTest_gwt.java | Java | asf20 | 1,649 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect.testing;
public class IteratorTesterTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testing.testModule";
}
public void testCanCatchDifferentContents() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testCanCatchDifferentContents();
}
public void testCanCatchDifferentLengthOfIteration() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testCanCatchDifferentLengthOfIteration();
}
public void testCanCatchDifferentRemoveBehaviour() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testCanCatchDifferentRemoveBehaviour();
}
public void testCanCatchSunJavaBug6529795InTargetIterator() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testCanCatchSunJavaBug6529795InTargetIterator();
}
public void testCanWorkAroundSunJavaBug6529795InTargetIterator() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testCanWorkAroundSunJavaBug6529795InTargetIterator();
}
public void testMismatchedException() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testMismatchedException();
}
public void testMissingException() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testMissingException();
}
public void testSimilarException() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testSimilarException();
}
public void testUnexpectedException() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testUnexpectedException();
}
public void testUnknownOrder() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testUnknownOrder();
}
public void testUnknownOrderUnrecognizedElement() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testUnknownOrderUnrecognizedElement();
}
public void testVerifyCanThrowAssertionThatFailsTest() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testVerifyCanThrowAssertionThatFailsTest();
}
public void testVerifyGetsCalled() throws Exception {
com.google.common.collect.testing.IteratorTesterTest testCase = new com.google.common.collect.testing.IteratorTesterTest();
testCase.testVerifyGetsCalled();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/testing/IteratorTesterTest_gwt.java | Java | asf20 | 3,936 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect.testing;
public class HelpersTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testing.testModule";
}
public void testNullsBeforeB() throws Exception {
com.google.common.collect.testing.HelpersTest testCase = new com.google.common.collect.testing.HelpersTest();
testCase.testNullsBeforeB();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/testing/HelpersTest_gwt.java | Java | asf20 | 1,021 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class HashMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreate() throws Exception {
com.google.common.collect.HashMultimapTest testCase = new com.google.common.collect.HashMultimapTest();
testCase.testCreate();
}
public void testCreateFromIllegalSizes() throws Exception {
com.google.common.collect.HashMultimapTest testCase = new com.google.common.collect.HashMultimapTest();
testCase.testCreateFromIllegalSizes();
}
public void testCreateFromMultimap() throws Exception {
com.google.common.collect.HashMultimapTest testCase = new com.google.common.collect.HashMultimapTest();
testCase.testCreateFromMultimap();
}
public void testCreateFromSizes() throws Exception {
com.google.common.collect.HashMultimapTest testCase = new com.google.common.collect.HashMultimapTest();
testCase.testCreateFromSizes();
}
public void testEmptyMultimapsEqual() throws Exception {
com.google.common.collect.HashMultimapTest testCase = new com.google.common.collect.HashMultimapTest();
testCase.testEmptyMultimapsEqual();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/HashMultimapTest_gwt.java | Java | asf20 | 1,804 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class CountTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAddAndGet() throws Exception {
com.google.common.collect.CountTest testCase = new com.google.common.collect.CountTest();
testCase.testAddAndGet();
}
public void testGet() throws Exception {
com.google.common.collect.CountTest testCase = new com.google.common.collect.CountTest();
testCase.testGet();
}
public void testGetAndAdd() throws Exception {
com.google.common.collect.CountTest testCase = new com.google.common.collect.CountTest();
testCase.testGetAndAdd();
}
public void testGetAndSet() throws Exception {
com.google.common.collect.CountTest testCase = new com.google.common.collect.CountTest();
testCase.testGetAndSet();
}
public void testSet() throws Exception {
com.google.common.collect.CountTest testCase = new com.google.common.collect.CountTest();
testCase.testSet();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/CountTest_gwt.java | Java | asf20 | 1,633 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class EnumMultisetTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClassCreate() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testClassCreate();
}
public void testCollectionCreate() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testCollectionCreate();
}
public void testCreateEmptyWithClass() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testCreateEmptyWithClass();
}
public void testCreateEmptyWithoutClassFails() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testCreateEmptyWithoutClassFails();
}
public void testEntrySet() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testEntrySet();
}
public void testIllegalCreate() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testIllegalCreate();
}
public void testToString() throws Exception {
com.google.common.collect.EnumMultisetTest testCase = new com.google.common.collect.EnumMultisetTest();
testCase.testToString();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/EnumMultisetTest_gwt.java | Java | asf20 | 2,184 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SimpleAbstractMultisetTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testFastAddAllMultiset() throws Exception {
com.google.common.collect.SimpleAbstractMultisetTest testCase = new com.google.common.collect.SimpleAbstractMultisetTest();
testCase.testFastAddAllMultiset();
}
public void testRemoveUnsupported() throws Exception {
com.google.common.collect.SimpleAbstractMultisetTest testCase = new com.google.common.collect.SimpleAbstractMultisetTest();
testCase.testRemoveUnsupported();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SimpleAbstractMultisetTest_gwt.java | Java | asf20 | 1,266 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class TreeMultimapNaturalTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testComparators() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testComparators();
}
public void testCreateFromHashMultimap() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testCreateFromHashMultimap();
}
public void testCreateFromSortedSetMultimap() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testCreateFromSortedSetMultimap();
}
public void testCreateFromTreeMultimap() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testCreateFromTreeMultimap();
}
public void testMultimapConstructor() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testMultimapConstructor();
}
public void testOrderedAsMapEntries() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testOrderedAsMapEntries();
}
public void testOrderedEntries() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testOrderedEntries();
}
public void testOrderedGet() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testOrderedGet();
}
public void testOrderedKeySet() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testOrderedKeySet();
}
public void testOrderedValues() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testOrderedValues();
}
public void testTailSetClear() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testTailSetClear();
}
public void testToString() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testToString();
}
public void testTreeMultimapAsMapSorted() throws Exception {
com.google.common.collect.TreeMultimapNaturalTest testCase = new com.google.common.collect.TreeMultimapNaturalTest();
testCase.testTreeMultimapAsMapSorted();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/TreeMultimapNaturalTest_gwt.java | Java | asf20 | 3,587 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class LinkedListMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreateFromIllegalSize() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testCreateFromIllegalSize();
}
public void testCreateFromMultimap() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testCreateFromMultimap();
}
public void testCreateFromSize() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testCreateFromSize();
}
public void testEntriesAfterMultimapUpdate() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testEntriesAfterMultimapUpdate();
}
public void testEquals() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testEquals();
}
public void testGetRandomAccess() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testGetRandomAccess();
}
public void testLinkedAsMapEntries() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedAsMapEntries();
}
public void testLinkedClear() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedClear();
}
public void testLinkedEntries() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedEntries();
}
public void testLinkedGetAdd() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedGetAdd();
}
public void testLinkedGetInsert() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedGetInsert();
}
public void testLinkedKeySet() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedKeySet();
}
public void testLinkedKeys() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedKeys();
}
public void testLinkedPutAllMultimap() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedPutAllMultimap();
}
public void testLinkedPutInOrder() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedPutInOrder();
}
public void testLinkedPutOutOfOrder() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedPutOutOfOrder();
}
public void testLinkedReplaceValues() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedReplaceValues();
}
public void testLinkedValues() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testLinkedValues();
}
public void testRemoveAllRandomAccess() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testRemoveAllRandomAccess();
}
public void testReplaceValuesRandomAccess() throws Exception {
com.google.common.collect.LinkedListMultimapTest testCase = new com.google.common.collect.LinkedListMultimapTest();
testCase.testReplaceValuesRandomAccess();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/LinkedListMultimapTest_gwt.java | Java | asf20 | 5,026 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class WellBehavedMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testEntriesAreMutableAndConsistent() throws Exception {
com.google.common.collect.WellBehavedMapTest testCase = new com.google.common.collect.WellBehavedMapTest();
testCase.testEntriesAreMutableAndConsistent();
}
public void testEntrySet_contain() throws Exception {
com.google.common.collect.WellBehavedMapTest testCase = new com.google.common.collect.WellBehavedMapTest();
testCase.testEntrySet_contain();
}
public void testEntrySet_remove() throws Exception {
com.google.common.collect.WellBehavedMapTest testCase = new com.google.common.collect.WellBehavedMapTest();
testCase.testEntrySet_remove();
}
public void testEntry_setValue() throws Exception {
com.google.common.collect.WellBehavedMapTest testCase = new com.google.common.collect.WellBehavedMapTest();
testCase.testEntry_setValue();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/WellBehavedMapTest_gwt.java | Java | asf20 | 1,646 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class Collections2Test_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testOrderedPermutationSetContains() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetContains();
}
public void testOrderedPermutationSetEmpty() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetEmpty();
}
public void testOrderedPermutationSetOneElement() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetOneElement();
}
public void testOrderedPermutationSetRepeatedElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetRepeatedElements();
}
public void testOrderedPermutationSetRepeatedElementsSize() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetRepeatedElementsSize();
}
public void testOrderedPermutationSetSizeOverflow() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetSizeOverflow();
}
public void testOrderedPermutationSetThreeElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testOrderedPermutationSetThreeElements();
}
public void testPermutationSetContains() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetContains();
}
public void testPermutationSetEmpty() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetEmpty();
}
public void testPermutationSetFourElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetFourElements();
}
public void testPermutationSetOneElement() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetOneElement();
}
public void testPermutationSetSize() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetSize();
}
public void testPermutationSetSizeOverflow() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetSizeOverflow();
}
public void testPermutationSetThreeElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetThreeElements();
}
public void testPermutationSetThreeElementsOutOfOrder() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetThreeElementsOutOfOrder();
}
public void testPermutationSetThreeRepeatedElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetThreeRepeatedElements();
}
public void testPermutationSetTwoElements() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testPermutationSetTwoElements();
}
public void testToStringImplWithNullEntries() throws Exception {
com.google.common.collect.Collections2Test testCase = new com.google.common.collect.Collections2Test();
testCase.testToStringImplWithNullEntries();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/Collections2Test_gwt.java | Java | asf20 | 4,836 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class MapsTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAsConverter_inverse() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_inverse();
}
public void testAsConverter_isAView() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_isAView();
}
public void testAsConverter_noMapping() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_noMapping();
}
public void testAsConverter_nominal() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_nominal();
}
public void testAsConverter_nullConversions() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_nullConversions();
}
public void testAsConverter_serialization() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_serialization();
}
public void testAsConverter_toString() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_toString();
}
public void testAsConverter_withNullMapping() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsConverter_withNullMapping();
}
public void testAsMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMap();
}
public void testAsMapEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapEmpty();
}
public void testAsMapReadsThrough() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapReadsThrough();
}
public void testAsMapReturnsSortedMapForSortedSetInput() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapReturnsSortedMapForSortedSetInput();
}
public void testAsMapSorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSorted();
}
public void testAsMapSortedEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSortedEmpty();
}
public void testAsMapSortedReadsThrough() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSortedReadsThrough();
}
public void testAsMapSortedSubViewKeySetsDoNotSupportAdd() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSortedSubViewKeySetsDoNotSupportAdd();
}
public void testAsMapSortedWritesThrough() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSortedWritesThrough();
}
public void testAsMapWritesThrough() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapWritesThrough();
}
public void testCapacityForLargeSizes() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testCapacityForLargeSizes();
}
public void testCapacityForNegativeSizeFails() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testCapacityForNegativeSizeFails();
}
public void testConcurrentMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testConcurrentMap();
}
public void testEnumMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMap();
}
public void testEnumMapNullClass() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMapNullClass();
}
public void testEnumMapWithInitialEmptyEnumMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMapWithInitialEmptyEnumMap();
}
public void testEnumMapWithInitialEmptyMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMapWithInitialEmptyMap();
}
public void testEnumMapWithInitialEnumMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMapWithInitialEnumMap();
}
public void testEnumMapWithInitialMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testEnumMapWithInitialMap();
}
public void testHashMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testHashMap();
}
public void testHashMapGeneralizesTypes() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testHashMapGeneralizesTypes();
}
public void testHashMapWithInitialMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testHashMapWithInitialMap();
}
public void testIdentityHashMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testIdentityHashMap();
}
public void testImmutableEntry() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testImmutableEntry();
}
public void testImmutableEntryNull() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testImmutableEntryNull();
}
public void testLinkedHashMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testLinkedHashMap();
}
public void testLinkedHashMapGeneralizesTypes() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testLinkedHashMapGeneralizesTypes();
}
public void testLinkedHashMapWithInitialMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testLinkedHashMapWithInitialMap();
}
public void testMapDifferenceEmptyEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceEmptyEmpty();
}
public void testMapDifferenceEmptySingleton() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceEmptySingleton();
}
public void testMapDifferenceEquals() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceEquals();
}
public void testMapDifferenceOfSortedMapIsSorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceOfSortedMapIsSorted();
}
public void testMapDifferencePredicateTypical() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferencePredicateTypical();
}
public void testMapDifferenceSingletonEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceSingletonEmpty();
}
public void testMapDifferenceTypical() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testMapDifferenceTypical();
}
public void testSortedMapDifferenceEmptyEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceEmptyEmpty();
}
public void testSortedMapDifferenceEmptySingleton() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceEmptySingleton();
}
public void testSortedMapDifferenceEquals() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceEquals();
}
public void testSortedMapDifferenceImmutable() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceImmutable();
}
public void testSortedMapDifferenceSingletonEmpty() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceSingletonEmpty();
}
public void testSortedMapDifferenceTypical() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapDifferenceTypical();
}
public void testSortedMapTransformEntries() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapTransformEntries();
}
public void testSortedMapTransformValues() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSortedMapTransformValues();
}
public void testSynchronizedBiMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testSynchronizedBiMap();
}
public void testToMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToMap();
}
public void testToMapIterator() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToMapIterator();
}
public void testToMapWithDuplicateKeys() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToMapWithDuplicateKeys();
}
public void testToMapWithNullKeys() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToMapWithNullKeys();
}
public void testToMapWithNullValues() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToMapWithNullValues();
}
public void testToStringImplWithNullKeys() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToStringImplWithNullKeys();
}
public void testToStringImplWithNullValues() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testToStringImplWithNullValues();
}
public void testTransformEntries() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformEntries();
}
public void testTransformEntriesExample() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformEntriesExample();
}
public void testTransformEntriesGenerics() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformEntriesGenerics();
}
public void testTransformEntriesSecretlySorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformEntriesSecretlySorted();
}
public void testTransformValues() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformValues();
}
public void testTransformValuesSecretlySorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformValuesSecretlySorted();
}
public void testTreeMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMap();
}
public void testTreeMapDerived() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMapDerived();
}
public void testTreeMapNonGeneric() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMapNonGeneric();
}
public void testTreeMapWithComparator() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMapWithComparator();
}
public void testTreeMapWithInitialMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMapWithInitialMap();
}
public void testUniqueIndexCollection() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexCollection();
}
public void testUniqueIndexDuplicates() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexDuplicates();
}
public void testUniqueIndexIterable() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexIterable();
}
public void testUniqueIndexIterator() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexIterator();
}
public void testUniqueIndexNullKey() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexNullKey();
}
public void testUniqueIndexNullValue() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUniqueIndexNullValue();
}
public void testUnmodifiableBiMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testUnmodifiableBiMap();
}
public void testFilterEntriesIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterEntriesIdentifiesBiMap();
}
public void testFilterKeysIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterKeysIdentifiesBiMap();
}
public void testFilterValuesIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterValuesIdentifiesBiMap();
}
public void testFilteredEntriesIllegalPut__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredEntriesIllegalPut();
}
public void testFilteredEntriesIllegalPutAll__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredEntriesIllegalPutAll();
}
public void testFilteredEntriesObjectPredicate__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredEntriesObjectPredicate();
}
public void testFilteredEntriesWildCardEntryPredicate__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredEntriesWildCardEntryPredicate();
}
public void testFilteredKeysFilteredReflectsBackingChanges__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredKeysFilteredReflectsBackingChanges();
}
public void testFilteredKeysIllegalPut__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredKeysIllegalPut();
}
public void testFilteredKeysIllegalPutAll__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredKeysIllegalPutAll();
}
public void testFilteredValuesClear__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredValuesClear();
}
public void testFilteredValuesIllegalPut__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredValuesIllegalPut();
}
public void testFilteredValuesIllegalPutAll__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredValuesIllegalPutAll();
}
public void testFilteredValuesIllegalSetValue__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredValuesIllegalSetValue();
}
public void testFilterEntriesIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterEntriesIdentifiesSortedMap();
}
public void testFilterKeysIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterKeysIdentifiesSortedMap();
}
public void testFilterValuesIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterValuesIdentifiesSortedMap();
}
public void testFilteredEntriesIllegalPut__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredEntriesIllegalPut();
}
public void testFilteredEntriesIllegalPutAll__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredEntriesIllegalPutAll();
}
public void testFilteredEntriesObjectPredicate__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredEntriesObjectPredicate();
}
public void testFilteredEntriesWildCardEntryPredicate__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredEntriesWildCardEntryPredicate();
}
public void testFilteredKeysFilteredReflectsBackingChanges__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredKeysFilteredReflectsBackingChanges();
}
public void testFilteredKeysIllegalPut__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredKeysIllegalPut();
}
public void testFilteredKeysIllegalPutAll__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredKeysIllegalPutAll();
}
public void testFilteredValuesClear__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredValuesClear();
}
public void testFilteredValuesIllegalPut__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredValuesIllegalPut();
}
public void testFilteredValuesIllegalPutAll__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredValuesIllegalPutAll();
}
public void testFilteredValuesIllegalSetValue__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredValuesIllegalSetValue();
}
public void testFirstAndLastKeyFilteredMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFirstAndLastKeyFilteredMap();
}
public void testHeadSubTailMap_FilteredMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testHeadSubTailMap_FilteredMap();
}
public void testFilteredEntriesIllegalPut__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredEntriesIllegalPut();
}
public void testFilteredEntriesIllegalPutAll__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredEntriesIllegalPutAll();
}
public void testFilteredEntriesObjectPredicate__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredEntriesObjectPredicate();
}
public void testFilteredEntriesWildCardEntryPredicate__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredEntriesWildCardEntryPredicate();
}
public void testFilteredKeysFilteredReflectsBackingChanges__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredKeysFilteredReflectsBackingChanges();
}
public void testFilteredKeysIllegalPut__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredKeysIllegalPut();
}
public void testFilteredKeysIllegalPutAll__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredKeysIllegalPutAll();
}
public void testFilteredValuesClear__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredValuesClear();
}
public void testFilteredValuesIllegalPut__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredValuesIllegalPut();
}
public void testFilteredValuesIllegalPutAll__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredValuesIllegalPutAll();
}
public void testFilteredValuesIllegalSetValue__FilteredMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredMapTest testCase = new com.google.common.collect.MapsTest.FilteredMapTest();
testCase.testFilteredValuesIllegalSetValue();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/MapsTest_gwt.java | Java | asf20 | 26,439 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class MultisetsImmutableEntryTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testEquals() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testEquals();
}
public void testEqualsNull() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testEqualsNull();
}
public void testHashCode() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testHashCode();
}
public void testHashCodeNull() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testHashCodeNull();
}
public void testNegativeCount() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testNegativeCount();
}
public void testToString() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testToString();
}
public void testToStringNull() throws Exception {
com.google.common.collect.MultisetsImmutableEntryTest testCase = new com.google.common.collect.MultisetsImmutableEntryTest();
testCase.testToStringNull();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/MultisetsImmutableEntryTest_gwt.java | Java | asf20 | 2,279 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class TreeTraverserTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testBreadthOrder() throws Exception {
com.google.common.collect.TreeTraverserTest testCase = new com.google.common.collect.TreeTraverserTest();
testCase.testBreadthOrder();
}
public void testInOrder() throws Exception {
com.google.common.collect.TreeTraverserTest testCase = new com.google.common.collect.TreeTraverserTest();
testCase.testInOrder();
}
public void testPostOrder() throws Exception {
com.google.common.collect.TreeTraverserTest testCase = new com.google.common.collect.TreeTraverserTest();
testCase.testPostOrder();
}
public void testPreOrder() throws Exception {
com.google.common.collect.TreeTraverserTest testCase = new com.google.common.collect.TreeTraverserTest();
testCase.testPreOrder();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/TreeTraverserTest_gwt.java | Java | asf20 | 1,559 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class RangeTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testAll() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testAll();
}
public void testApply() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testApply();
}
public void testAtLeast() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testAtLeast();
}
public void testAtMost() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testAtMost();
}
public void testCanonical() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testCanonical();
}
public void testCanonical_unboundedDomain() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testCanonical_unboundedDomain();
}
public void testClosed() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testClosed();
}
public void testClosedOpen() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testClosedOpen();
}
public void testClosed_invalid() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testClosed_invalid();
}
public void testContainsAll() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testContainsAll();
}
public void testEmpty1() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEmpty1();
}
public void testEmpty2() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEmpty2();
}
public void testEncloseAll() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEncloseAll();
}
public void testEncloseAll_empty() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEncloseAll_empty();
}
public void testEncloseAll_nullValue() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEncloseAll_nullValue();
}
public void testEncloses_closed() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEncloses_closed();
}
public void testEncloses_open() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEncloses_open();
}
public void testEquals() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEquals();
}
public void testEquivalentFactories() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testEquivalentFactories();
}
public void testGreaterThan() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testGreaterThan();
}
public void testIntersection_deFactoEmpty() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testIntersection_deFactoEmpty();
}
public void testIntersection_empty() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testIntersection_empty();
}
public void testIntersection_general() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testIntersection_general();
}
public void testIntersection_singleton() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testIntersection_singleton();
}
public void testIsConnected() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testIsConnected();
}
public void testLegacyComparable() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testLegacyComparable();
}
public void testLessThan() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testLessThan();
}
public void testOpen() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testOpen();
}
public void testOpenClosed() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testOpenClosed();
}
public void testOpen_invalid() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testOpen_invalid();
}
public void testOrderingCuts() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testOrderingCuts();
}
public void testSingleton() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testSingleton();
}
public void testSpan_general() throws Exception {
com.google.common.collect.RangeTest testCase = new com.google.common.collect.RangeTest();
testCase.testSpan_general();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/RangeTest_gwt.java | Java | asf20 | 6,617 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class MapConstraintsTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testConstrainedBiMapIllegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedBiMapIllegal();
}
public void testConstrainedBiMapLegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedBiMapLegal();
}
public void testConstrainedMapIllegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedMapIllegal();
}
public void testConstrainedMapLegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedMapLegal();
}
public void testConstrainedMultimapIllegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedMultimapIllegal();
}
public void testConstrainedMultimapLegal() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedMultimapLegal();
}
public void testConstrainedMultimapQueue() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedMultimapQueue();
}
public void testConstrainedTypePreservingList() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedTypePreservingList();
}
public void testConstrainedTypePreservingRandomAccessList() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedTypePreservingRandomAccessList();
}
public void testConstrainedTypePreservingSet() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedTypePreservingSet();
}
public void testConstrainedTypePreservingSortedSet() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testConstrainedTypePreservingSortedSet();
}
public void testMapEntrySetContainsNefariousEntry() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMapEntrySetContainsNefariousEntry();
}
public void testMapEntrySetToArray() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMapEntrySetToArray();
}
public void testMultimapAsMapEntriesContainsNefariousEntry() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapAsMapEntriesContainsNefariousEntry();
}
public void testMultimapAsMapEntriesRemoveNefariousEntry() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapAsMapEntriesRemoveNefariousEntry();
}
public void testMultimapAsMapEntriesToArray() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapAsMapEntriesToArray();
}
public void testMultimapAsMapValuesToArray() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapAsMapValuesToArray();
}
public void testMultimapEntriesContainsNefariousEntry() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapEntriesContainsNefariousEntry();
}
public void testMultimapEntriesRemoveNefariousEntry() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testMultimapEntriesRemoveNefariousEntry();
}
public void testNefariousMapPutAll() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testNefariousMapPutAll();
}
public void testNefariousMultimapGetAddAll() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testNefariousMultimapGetAddAll();
}
public void testNefariousMultimapPutAllIterable() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testNefariousMultimapPutAllIterable();
}
public void testNefariousMultimapPutAllMultimap() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testNefariousMultimapPutAllMultimap();
}
public void testNotNull() throws Exception {
com.google.common.collect.MapConstraintsTest testCase = new com.google.common.collect.MapConstraintsTest();
testCase.testNotNull();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/MapConstraintsTest_gwt.java | Java | asf20 | 6,218 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ConstrainedMapImplementsMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testClear();
}
public void testContainsKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testContainsKey();
}
public void testContainsValue() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testContainsValue();
}
public void testEntrySet() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testEqualsForSmallerMap();
}
public void testGet() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testGet();
}
public void testGetForEmptyMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testGetForEmptyMap();
}
public void testGetNull() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testGetNull();
}
public void testHashCode() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetClear();
}
public void testKeySetRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutAllNewKey();
}
public void testPutExistingKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutExistingKey();
}
public void testPutNewKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutNewKey();
}
public void testPutNullKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutNullKey();
}
public void testPutNullValue() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testPutNullValueForExistingKey();
}
public void testRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testRemove();
}
public void testRemoveMissingKey() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testRemoveMissingKey();
}
public void testSize() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testSize();
}
public void testValues() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValues();
}
public void testValuesClear() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesClear();
}
public void testValuesIteratorRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRemove();
}
public void testValuesRemoveAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ConstrainedMapImplementsMapTest testCase = new com.google.common.collect.ConstrainedMapImplementsMapTest();
testCase.testValuesRetainAllNullFromEmpty();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ConstrainedMapImplementsMapTest_gwt.java | Java | asf20 | 13,775 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableSetMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testBuilderOrderKeysAndValuesBy() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderOrderKeysAndValuesBy();
}
public void testBuilderOrderKeysBy() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderOrderKeysBy();
}
public void testBuilderOrderKeysByDuplicates() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderOrderKeysByDuplicates();
}
public void testBuilderOrderValuesBy() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderOrderValuesBy();
}
public void testBuilderPutAllIterable() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutAllIterable();
}
public void testBuilderPutAllMultimap() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutAllMultimap();
}
public void testBuilderPutAllMultimapWithDuplicates() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutAllMultimapWithDuplicates();
}
public void testBuilderPutAllVarargs() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutAllVarargs();
}
public void testBuilderPutAllWithDuplicates() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutAllWithDuplicates();
}
public void testBuilderPutNullKey() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutNullKey();
}
public void testBuilderPutNullValue() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutNullValue();
}
public void testBuilderPutWithDuplicates() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilderPutWithDuplicates();
}
public void testBuilder_withImmutableEntry() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilder_withImmutableEntry();
}
public void testBuilder_withImmutableEntryAndNullContents() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilder_withImmutableEntryAndNullContents();
}
public void testBuilder_withMutableEntry() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testBuilder_withMutableEntry();
}
public void testCopyOf() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOf();
}
public void testCopyOfEmpty() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOfEmpty();
}
public void testCopyOfImmutableSetMultimap() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOfImmutableSetMultimap();
}
public void testCopyOfNullKey() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOfNullKey();
}
public void testCopyOfNullValue() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOfNullValue();
}
public void testCopyOfWithDuplicates() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testCopyOfWithDuplicates();
}
public void testEmptyMultimapReads() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testEmptyMultimapReads();
}
public void testEmptyMultimapWrites() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testEmptyMultimapWrites();
}
public void testInverse() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testInverse();
}
public void testInverseMinimizesWork() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testInverseMinimizesWork();
}
public void testMultimapEquals() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testMultimapEquals();
}
public void testMultimapReads() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testMultimapReads();
}
public void testMultimapWrites() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testMultimapWrites();
}
public void testOf() throws Exception {
com.google.common.collect.ImmutableSetMultimapTest testCase = new com.google.common.collect.ImmutableSetMultimapTest();
testCase.testOf();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableSetMultimapTest_gwt.java | Java | asf20 | 7,232 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class NewCustomTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testColumn();
}
public void testColumnNull() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testColumnNull();
}
public void testColumnSetPartialOverlap() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testColumnSetPartialOverlap();
}
public void testContains() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testContainsValue();
}
public void testEquals() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testEquals();
}
public void testGet() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testGet();
}
public void testHashCode() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testHashCode();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testPut();
}
public void testPutAllTable() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testPutAllTable();
}
public void testPutNull() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testPutNull();
}
public void testPutNullReplace() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testPutNullReplace();
}
public void testRemove() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRow();
}
public void testRowClearAndPut() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRowClearAndPut();
}
public void testRowKeySetOrdering() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRowKeySetOrdering();
}
public void testRowNull() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRowNull();
}
public void testRowOrdering() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testRowOrdering();
}
public void testSize() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testSize();
}
public void testToStringSize1() throws Exception {
com.google.common.collect.NewCustomTableTest testCase = new com.google.common.collect.NewCustomTableTest();
testCase.setUp();
testCase.testToStringSize1();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/NewCustomTableTest_gwt.java | Java | asf20 | 5,824 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ForwardingSortedMapImplementsMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testClear();
}
public void testContainsKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testContainsKey();
}
public void testContainsValue() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testContainsValue();
}
public void testEntrySet() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testEqualsForSmallerMap();
}
public void testGet() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testGet();
}
public void testGetForEmptyMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testGetForEmptyMap();
}
public void testGetNull() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testGetNull();
}
public void testHashCode() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetClear();
}
public void testKeySetRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutAllNewKey();
}
public void testPutExistingKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutExistingKey();
}
public void testPutNewKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutNewKey();
}
public void testPutNullKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutNullKey();
}
public void testPutNullValue() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testPutNullValueForExistingKey();
}
public void testRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testRemove();
}
public void testRemoveMissingKey() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testRemoveMissingKey();
}
public void testSize() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testSize();
}
public void testTailMapClearThrough() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testTailMapClearThrough();
}
public void testTailMapRemoveThrough() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testTailMapRemoveThrough();
}
public void testTailMapWriteThrough() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testTailMapWriteThrough();
}
public void testValues() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValues();
}
public void testValuesClear() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesClear();
}
public void testValuesIteratorRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRemove();
}
public void testValuesRemoveAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.ForwardingSortedMapImplementsMapTest testCase = new com.google.common.collect.ForwardingSortedMapImplementsMapTest();
testCase.testValuesRetainAllNullFromEmpty();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest_gwt.java | Java | asf20 | 15,074 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class RegularImmutableTableTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCellSet() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testCellSet();
}
public void testClear() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testClear();
}
public void testColumn() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testColumn();
}
public void testColumnKeySet() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testColumnKeySet();
}
public void testColumnMap() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testColumnMap();
}
public void testConsistentHashCode() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testConsistentHashCode();
}
public void testConsistentToString() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testConsistentToString();
}
public void testContains() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testContains();
}
public void testContainsColumn() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testContainsColumn();
}
public void testContainsRow() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testContainsRow();
}
public void testContainsValue() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testContainsValue();
}
public void testForCells() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testForCells();
}
public void testGet() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testGet();
}
public void testIsEmpty() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testIsEmpty();
}
public void testPut() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testPut();
}
public void testPutAll() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testPutAll();
}
public void testRemove() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testRemove();
}
public void testRow() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testRow();
}
public void testRowKeySet() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testRowKeySet();
}
public void testRowMap() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testRowMap();
}
public void testSize() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testSize();
}
public void testValues() throws Exception {
com.google.common.collect.RegularImmutableTableTest testCase = new com.google.common.collect.RegularImmutableTableTest();
testCase.testValues();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/RegularImmutableTableTest_gwt.java | Java | asf20 | 5,235 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class LinkedHashMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreate() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testCreate();
}
public void testCreateFromIllegalSizes() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testCreateFromIllegalSizes();
}
public void testCreateFromMultimap() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testCreateFromMultimap();
}
public void testCreateFromSizes() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testCreateFromSizes();
}
public void testKeysToString_ordering() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testKeysToString_ordering();
}
public void testOrderingReadOnly() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testOrderingReadOnly();
}
public void testOrderingSynchronized() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testOrderingSynchronized();
}
public void testOrderingUnmodifiable() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testOrderingUnmodifiable();
}
public void testOrderingUpdates() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testOrderingUpdates();
}
public void testPutMultimapOrdered() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testPutMultimapOrdered();
}
public void testToString() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testToString();
}
public void testToStringNullExact() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testToStringNullExact();
}
public void testValueSetHashTableExpansion() throws Exception {
com.google.common.collect.LinkedHashMultimapTest testCase = new com.google.common.collect.LinkedHashMultimapTest();
testCase.testValueSetHashTableExpansion();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/LinkedHashMultimapTest_gwt.java | Java | asf20 | 3,578 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class ImmutableMultimapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testBuilder_withImmutableEntry() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testBuilder_withImmutableEntry();
}
public void testBuilder_withImmutableEntryAndNullContents() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testBuilder_withImmutableEntryAndNullContents();
}
public void testBuilder_withMutableEntry() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testBuilder_withMutableEntry();
}
public void testCopyOf() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testCopyOf();
}
public void testEquals() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testEquals();
}
public void testUnhashableMixedValues() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testUnhashableMixedValues();
}
public void testUnhashableSingletonValue() throws Exception {
com.google.common.collect.ImmutableMultimapTest testCase = new com.google.common.collect.ImmutableMultimapTest();
testCase.testUnhashableSingletonValue();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/ImmutableMultimapTest_gwt.java | Java | asf20 | 2,347 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class EnumBiMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testCreate() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testCreate();
}
public void testCreateFromMap() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testCreateFromMap();
}
public void testEntrySet() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testEntrySet();
}
public void testEnumBiMapConstructor() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testEnumBiMapConstructor();
}
public void testEquals() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testEquals();
}
public void testIterationOrder() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testIterationOrder();
}
public void testKeySetIteratorRemove() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testKeySetIteratorRemove();
}
public void testKeyType() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testKeyType();
}
public void testValueType() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testValueType();
}
public void testValuesIteratorRemove() throws Exception {
com.google.common.collect.EnumBiMapTest testCase = new com.google.common.collect.EnumBiMapTest();
testCase.testValuesIteratorRemove();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/EnumBiMapTest_gwt.java | Java | asf20 | 2,657 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class MultimapBuilderTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testGenerics_gwtCompatible() throws Exception {
com.google.common.collect.MultimapBuilderTest testCase = new com.google.common.collect.MultimapBuilderTest();
testCase.testGenerics_gwtCompatible();
}
public void testSerialization() throws Exception {
com.google.common.collect.MultimapBuilderTest testCase = new com.google.common.collect.MultimapBuilderTest();
testCase.testSerialization();
}
public void testTreeKeys_gwtCompatible() throws Exception {
com.google.common.collect.MultimapBuilderTest testCase = new com.google.common.collect.MultimapBuilderTest();
testCase.testTreeKeys_gwtCompatible();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/MultimapBuilderTest_gwt.java | Java | asf20 | 1,447 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
public class SubMapMultimapAsMapImplementsMapTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.collect.testModule";
}
public void testClear() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testClear();
}
public void testContainsKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testContainsKey();
}
public void testContainsValue() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testContainsValue();
}
public void testEntrySet() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySet();
}
public void testEntrySetAddAndAddAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetAddAndAddAll();
}
public void testEntrySetClear() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetClear();
}
public void testEntrySetContainsEntryIncompatibleKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetContainsEntryIncompatibleKey();
}
public void testEntrySetContainsEntryNullKeyMissing() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyMissing();
}
public void testEntrySetContainsEntryNullKeyPresent() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetContainsEntryNullKeyPresent();
}
public void testEntrySetForEmptyMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetForEmptyMap();
}
public void testEntrySetIteratorRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetIteratorRemove();
}
public void testEntrySetRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemove();
}
public void testEntrySetRemoveAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveAll();
}
public void testEntrySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveAllNullFromEmpty();
}
public void testEntrySetRemoveDifferentValue() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveDifferentValue();
}
public void testEntrySetRemoveMissingKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveMissingKey();
}
public void testEntrySetRemoveNullKeyMissing() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyMissing();
}
public void testEntrySetRemoveNullKeyPresent() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRemoveNullKeyPresent();
}
public void testEntrySetRetainAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRetainAll();
}
public void testEntrySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetRetainAllNullFromEmpty();
}
public void testEntrySetSetValue() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetSetValue();
}
public void testEntrySetSetValueSameValue() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEntrySetSetValueSameValue();
}
public void testEqualsForEmptyMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEqualsForEmptyMap();
}
public void testEqualsForEqualMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEqualsForEqualMap();
}
public void testEqualsForLargerMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEqualsForLargerMap();
}
public void testEqualsForSmallerMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testEqualsForSmallerMap();
}
public void testGet() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testGet();
}
public void testGetForEmptyMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testGetForEmptyMap();
}
public void testGetNull() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testGetNull();
}
public void testHashCode() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testHashCode();
}
public void testHashCodeForEmptyMap() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testHashCodeForEmptyMap();
}
public void testKeySetClear() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetClear();
}
public void testKeySetRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetRemove();
}
public void testKeySetRemoveAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetRemoveAll();
}
public void testKeySetRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetRemoveAllNullFromEmpty();
}
public void testKeySetRetainAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetRetainAll();
}
public void testKeySetRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testKeySetRetainAllNullFromEmpty();
}
public void testPutAllExistingKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutAllExistingKey();
}
public void testPutAllNewKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutAllNewKey();
}
public void testPutExistingKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutExistingKey();
}
public void testPutNewKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutNewKey();
}
public void testPutNullKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutNullKey();
}
public void testPutNullValue() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutNullValue();
}
public void testPutNullValueForExistingKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testPutNullValueForExistingKey();
}
public void testRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testRemove();
}
public void testRemoveMissingKey() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testRemoveMissingKey();
}
public void testSize() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testSize();
}
public void testValues() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValues();
}
public void testValuesClear() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesClear();
}
public void testValuesIteratorRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesIteratorRemove();
}
public void testValuesRemove() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRemove();
}
public void testValuesRemoveAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRemoveAll();
}
public void testValuesRemoveAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRemoveAllNullFromEmpty();
}
public void testValuesRemoveMissing() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRemoveMissing();
}
public void testValuesRetainAll() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRetainAll();
}
public void testValuesRetainAllNullFromEmpty() throws Exception {
com.google.common.collect.SubMapMultimapAsMapImplementsMapTest testCase = new com.google.common.collect.SubMapMultimapAsMapImplementsMapTest();
testCase.testValuesRetainAllNullFromEmpty();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/collect/SubMapMultimapAsMapImplementsMapTest_gwt.java | Java | asf20 | 14,340 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.net;
public class HostAndPortTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.net.testModule";
}
public void testFromHost() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromHost();
}
public void testFromParts() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromParts();
}
public void testFromStringBadDefaultPort() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringBadDefaultPort();
}
public void testFromStringBadPort() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringBadPort();
}
public void testFromStringParseableNonsense() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringParseableNonsense();
}
public void testFromStringUnparseableNonsense() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringUnparseableNonsense();
}
public void testFromStringUnusedDefaultPort() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringUnusedDefaultPort();
}
public void testFromStringWellFormed() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testFromStringWellFormed();
}
public void testGetPortOrDefault() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testGetPortOrDefault();
}
public void testHashCodeAndEquals() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testHashCodeAndEquals();
}
public void testRequireBracketsForIPv6() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testRequireBracketsForIPv6();
}
public void testSerialization() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testSerialization();
}
public void testToString() throws Exception {
com.google.common.net.HostAndPortTest testCase = new com.google.common.net.HostAndPortTest();
testCase.testToString();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/net/HostAndPortTest_gwt.java | Java | asf20 | 3,307 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.net;
public class MediaTypeTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.net.testModule";
}
public void testCreateApplicationType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateApplicationType();
}
public void testCreateAudioType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateAudioType();
}
public void testCreateImageType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateImageType();
}
public void testCreateTextType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateTextType();
}
public void testCreateVideoType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreateVideoType();
}
public void testCreate_invalidSubtype() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreate_invalidSubtype();
}
public void testCreate_invalidType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreate_invalidType();
}
public void testCreate_wildcardTypeDeclaredSubtype() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testCreate_wildcardTypeDeclaredSubtype();
}
public void testEquals() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testEquals();
}
public void testGetCharset() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetCharset();
}
public void testGetCharset_illegalCharset() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetCharset_illegalCharset();
}
public void testGetCharset_tooMany() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetCharset_tooMany();
}
public void testGetCharset_unsupportedCharset() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetCharset_unsupportedCharset();
}
public void testGetParameters() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetParameters();
}
public void testGetSubtype() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetSubtype();
}
public void testGetType() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testGetType();
}
public void testHasWildcard() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testHasWildcard();
}
public void testIs() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testIs();
}
public void testParse_badInput() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testParse_badInput();
}
public void testParse_empty() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testParse_empty();
}
public void testToString() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testToString();
}
public void testWithCharset() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithCharset();
}
public void testWithParameter() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithParameter();
}
public void testWithParameter_invalidAttribute() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithParameter_invalidAttribute();
}
public void testWithParameters() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithParameters();
}
public void testWithParameters_invalidAttribute() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithParameters_invalidAttribute();
}
public void testWithoutParameters() throws Exception {
com.google.common.net.MediaTypeTest testCase = new com.google.common.net.MediaTypeTest();
testCase.testWithoutParameters();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/net/MediaTypeTest_gwt.java | Java | asf20 | 5,773 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.net;
public class UrlEscapersTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.net.testModule";
}
public void testUrlFormParameterEscaper() throws Exception {
com.google.common.net.UrlEscapersTest testCase = new com.google.common.net.UrlEscapersTest();
testCase.testUrlFormParameterEscaper();
}
public void testUrlFragmentEscaper() throws Exception {
com.google.common.net.UrlEscapersTest testCase = new com.google.common.net.UrlEscapersTest();
testCase.testUrlFragmentEscaper();
}
public void testUrlPathSegmentEscaper() throws Exception {
com.google.common.net.UrlEscapersTest testCase = new com.google.common.net.UrlEscapersTest();
testCase.testUrlPathSegmentEscaper();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/net/UrlEscapersTest_gwt.java | Java | asf20 | 1,397 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.net;
public class PercentEscaperTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.net.testModule";
}
public void testBadArguments_badchars() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testBadArguments_badchars();
}
public void testBadArguments_null() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testBadArguments_null();
}
public void testBadArguments_plusforspace() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testBadArguments_plusforspace();
}
public void testCustomEscaper() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testCustomEscaper();
}
public void testCustomEscaper_withpercent() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testCustomEscaper_withpercent();
}
public void testPlusForSpace() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testPlusForSpace();
}
public void testSimpleEscaper() throws Exception {
com.google.common.net.PercentEscaperTest testCase = new com.google.common.net.PercentEscaperTest();
testCase.testSimpleEscaper();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/net/PercentEscaperTest_gwt.java | Java | asf20 | 2,194 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.net;
public class InternetDomainNameTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.net.testModule";
}
public void testChild() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testChild();
}
public void testEquality() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testEquality();
}
public void testExclusion() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testExclusion();
}
public void testInvalid() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testInvalid();
}
public void testInvalidTopPrivateDomain() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testInvalidTopPrivateDomain();
}
public void testIsValid() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testIsValid();
}
public void testMultipleUnders() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testMultipleUnders();
}
public void testParent() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testParent();
}
public void testParentChild() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testParentChild();
}
public void testPublicSuffix() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testPublicSuffix();
}
public void testToString() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testToString();
}
public void testTopPrivateDomain() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testTopPrivateDomain();
}
public void testUnderPrivateDomain() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testUnderPrivateDomain();
}
public void testUnderPublicSuffix() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testUnderPublicSuffix();
}
public void testValid() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testValid();
}
public void testValidTopPrivateDomain() throws Exception {
com.google.common.net.InternetDomainNameTest testCase = new com.google.common.net.InternetDomainNameTest();
testCase.testValidTopPrivateDomain();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/net/InternetDomainNameTest_gwt.java | Java | asf20 | 3,906 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.html;
public class HtmlEscapersTest_gwt extends com.google.gwt.junit.client.GWTTestCase {
@Override public String getModuleName() {
return "com.google.common.html.testModule";
}
public void testHtmlEscaper() throws Exception {
com.google.common.html.HtmlEscapersTest testCase = new com.google.common.html.HtmlEscapersTest();
testCase.testHtmlEscaper();
}
}
| zzhhhhh-aw4rwer | guava-gwt/test/com/google/common/html/HtmlEscapersTest_gwt.java | Java | asf20 | 991 |
/*
* Copyright (C) 2012 The Guava Authors
*
* 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.common.io;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.io.GwtWorkarounds.asCharInput;
import static com.google.common.io.GwtWorkarounds.stringBuilderOutput;
import static com.google.common.math.IntMath.divide;
import static com.google.common.math.IntMath.log2;
import static java.math.RoundingMode.CEILING;
import static java.math.RoundingMode.FLOOR;
import static java.math.RoundingMode.UNNECESSARY;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Ascii;
import com.google.common.base.CharMatcher;
import com.google.common.io.GwtWorkarounds.ByteInput;
import com.google.common.io.GwtWorkarounds.ByteOutput;
import com.google.common.io.GwtWorkarounds.CharInput;
import com.google.common.io.GwtWorkarounds.CharOutput;
import java.io.IOException;
import java.util.Arrays;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
/**
* A binary encoding scheme for reversibly translating between byte sequences and printable ASCII
* strings. This class includes several constants for encoding schemes specified by <a
* href="http://tools.ietf.org/html/rfc4648">RFC 4648</a>. For example, the expression:
*
* <pre> {@code
* BaseEncoding.base32().encode("foo".getBytes(Charsets.US_ASCII))}</pre>
*
* <p>returns the string {@code "MZXW6==="}, and <pre> {@code
* byte[] decoded = BaseEncoding.base32().decode("MZXW6===");}</pre>
*
* <p>...returns the ASCII bytes of the string {@code "foo"}.
*
* <p>By default, {@code BaseEncoding}'s behavior is relatively strict and in accordance with
* RFC 4648. Decoding rejects characters in the wrong case, though padding is optional.
* To modify encoding and decoding behavior, use configuration methods to obtain a new encoding
* with modified behavior:
*
* <pre> {@code
* BaseEncoding.base16().lowerCase().decode("deadbeef");}</pre>
*
* <p>Warning: BaseEncoding instances are immutable. Invoking a configuration method has no effect
* on the receiving instance; you must store and use the new encoding instance it returns, instead.
*
* <pre> {@code
* // Do NOT do this
* BaseEncoding hex = BaseEncoding.base16();
* hex.lowerCase(); // does nothing!
* return hex.decode("deadbeef"); // throws an IllegalArgumentException}</pre>
*
* <p>It is guaranteed that {@code encoding.decode(encoding.encode(x))} is always equal to
* {@code x}, but the reverse does not necessarily hold.
*
* <p>
* <table>
* <tr>
* <th>Encoding
* <th>Alphabet
* <th>{@code char:byte} ratio
* <th>Default padding
* <th>Comments
* <tr>
* <td>{@link #base16()}
* <td>0-9 A-F
* <td>2.00
* <td>N/A
* <td>Traditional hexadecimal. Defaults to upper case.
* <tr>
* <td>{@link #base32()}
* <td>A-Z 2-7
* <td>1.60
* <td>=
* <td>Human-readable; no possibility of mixing up 0/O or 1/I. Defaults to upper case.
* <tr>
* <td>{@link #base32Hex()}
* <td>0-9 A-V
* <td>1.60
* <td>=
* <td>"Numerical" base 32; extended from the traditional hex alphabet. Defaults to upper case.
* <tr>
* <td>{@link #base64()}
* <td>A-Z a-z 0-9 + /
* <td>1.33
* <td>=
* <td>
* <tr>
* <td>{@link #base64Url()}
* <td>A-Z a-z 0-9 - _
* <td>1.33
* <td>=
* <td>Safe to use as filenames, or to pass in URLs without escaping
* </table>
*
* <p>
* All instances of this class are immutable, so they may be stored safely as static constants.
*
* @author Louis Wasserman
* @since 14.0
*/
@Beta
@GwtCompatible(emulated = true)
public abstract class BaseEncoding {
// TODO(user): consider adding encodeTo(Appendable, byte[], [int, int])
BaseEncoding() {}
/**
* Exception indicating invalid base-encoded input encountered while decoding.
*
* @author Louis Wasserman
* @since 15.0
*/
public static final class DecodingException extends IOException {
DecodingException(String message) {
super(message);
}
DecodingException(Throwable cause) {
super(cause);
}
}
/**
* Encodes the specified byte array, and returns the encoded {@code String}.
*/
public String encode(byte[] bytes) {
return encode(checkNotNull(bytes), 0, bytes.length);
}
/**
* Encodes the specified range of the specified byte array, and returns the encoded
* {@code String}.
*/
public final String encode(byte[] bytes, int off, int len) {
checkNotNull(bytes);
checkPositionIndexes(off, off + len, bytes.length);
CharOutput result = stringBuilderOutput(maxEncodedSize(len));
ByteOutput byteOutput = encodingStream(result);
try {
for (int i = 0; i < len; i++) {
byteOutput.write(bytes[off + i]);
}
byteOutput.close();
} catch (IOException impossible) {
throw new AssertionError("impossible");
}
return result.toString();
}
// TODO(user): document the extent of leniency, probably after adding ignore(CharMatcher)
private static byte[] extract(byte[] result, int length) {
if (length == result.length) {
return result;
} else {
byte[] trunc = new byte[length];
System.arraycopy(result, 0, trunc, 0, length);
return trunc;
}
}
/**
* Decodes the specified character sequence, and returns the resulting {@code byte[]}.
* This is the inverse operation to {@link #encode(byte[])}.
*
* @throws IllegalArgumentException if the input is not a valid encoded string according to this
* encoding.
*/
public final byte[] decode(CharSequence chars) {
try {
return decodeChecked(chars);
} catch (DecodingException badInput) {
throw new IllegalArgumentException(badInput);
}
}
/**
* Decodes the specified character sequence, and returns the resulting {@code byte[]}.
* This is the inverse operation to {@link #encode(byte[])}.
*
* @throws DecodingException if the input is not a valid encoded string according to this
* encoding.
*/
final byte[] decodeChecked(CharSequence chars) throws DecodingException {
chars = padding().trimTrailingFrom(chars);
ByteInput decodedInput = decodingStream(asCharInput(chars));
byte[] tmp = new byte[maxDecodedSize(chars.length())];
int index = 0;
try {
for (int i = decodedInput.read(); i != -1; i = decodedInput.read()) {
tmp[index++] = (byte) i;
}
} catch (DecodingException badInput) {
throw badInput;
} catch (IOException impossible) {
throw new AssertionError(impossible);
}
return extract(tmp, index);
}
// Implementations for encoding/decoding
abstract int maxEncodedSize(int bytes);
abstract ByteOutput encodingStream(CharOutput charOutput);
abstract int maxDecodedSize(int chars);
abstract ByteInput decodingStream(CharInput charInput);
abstract CharMatcher padding();
// Modified encoding generators
/**
* Returns an encoding that behaves equivalently to this encoding, but omits any padding
* characters as specified by <a href="http://tools.ietf.org/html/rfc4648#section-3.2">RFC 4648
* section 3.2</a>, Padding of Encoded Data.
*/
@CheckReturnValue
public abstract BaseEncoding omitPadding();
/**
* Returns an encoding that behaves equivalently to this encoding, but uses an alternate character
* for padding.
*
* @throws IllegalArgumentException if this padding character is already used in the alphabet or a
* separator
*/
@CheckReturnValue
public abstract BaseEncoding withPadChar(char padChar);
/**
* Returns an encoding that behaves equivalently to this encoding, but adds a separator string
* after every {@code n} characters. Any occurrences of any characters that occur in the separator
* are skipped over in decoding.
*
* @throws IllegalArgumentException if any alphabet or padding characters appear in the separator
* string, or if {@code n <= 0}
* @throws UnsupportedOperationException if this encoding already uses a separator
*/
@CheckReturnValue
public abstract BaseEncoding withSeparator(String separator, int n);
/**
* Returns an encoding that behaves equivalently to this encoding, but encodes and decodes with
* uppercase letters. Padding and separator characters remain in their original case.
*
* @throws IllegalStateException if the alphabet used by this encoding contains mixed upper- and
* lower-case characters
*/
@CheckReturnValue
public abstract BaseEncoding upperCase();
/**
* Returns an encoding that behaves equivalently to this encoding, but encodes and decodes with
* lowercase letters. Padding and separator characters remain in their original case.
*
* @throws IllegalStateException if the alphabet used by this encoding contains mixed upper- and
* lower-case characters
*/
@CheckReturnValue
public abstract BaseEncoding lowerCase();
private static final BaseEncoding BASE64 = new StandardBaseEncoding(
"base64()", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", '=');
/**
* The "base64" base encoding specified by <a
* href="http://tools.ietf.org/html/rfc4648#section-4">RFC 4648 section 4</a>, Base 64 Encoding.
* (This is the same as the base 64 encoding from <a
* href="http://tools.ietf.org/html/rfc3548#section-3">RFC 3548</a>.)
*
* <p>The character {@code '='} is used for padding, but can be {@linkplain #omitPadding()
* omitted} or {@linkplain #withPadChar(char) replaced}.
*
* <p>No line feeds are added by default, as per <a
* href="http://tools.ietf.org/html/rfc4648#section-3.1"> RFC 4648 section 3.1</a>, Line Feeds in
* Encoded Data. Line feeds may be added using {@link #withSeparator(String, int)}.
*/
public static BaseEncoding base64() {
return BASE64;
}
private static final BaseEncoding BASE64_URL = new StandardBaseEncoding(
"base64Url()", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", '=');
/**
* The "base64url" encoding specified by <a
* href="http://tools.ietf.org/html/rfc4648#section-5">RFC 4648 section 5</a>, Base 64 Encoding
* with URL and Filename Safe Alphabet, also sometimes referred to as the "web safe Base64."
* (This is the same as the base 64 encoding with URL and filename safe alphabet from <a
* href="http://tools.ietf.org/html/rfc3548#section-4">RFC 3548</a>.)
*
* <p>The character {@code '='} is used for padding, but can be {@linkplain #omitPadding()
* omitted} or {@linkplain #withPadChar(char) replaced}.
*
* <p>No line feeds are added by default, as per <a
* href="http://tools.ietf.org/html/rfc4648#section-3.1"> RFC 4648 section 3.1</a>, Line Feeds in
* Encoded Data. Line feeds may be added using {@link #withSeparator(String, int)}.
*/
public static BaseEncoding base64Url() {
return BASE64_URL;
}
private static final BaseEncoding BASE32 =
new StandardBaseEncoding("base32()", "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", '=');
/**
* The "base32" encoding specified by <a
* href="http://tools.ietf.org/html/rfc4648#section-6">RFC 4648 section 6</a>, Base 32 Encoding.
* (This is the same as the base 32 encoding from <a
* href="http://tools.ietf.org/html/rfc3548#section-5">RFC 3548</a>.)
*
* <p>The character {@code '='} is used for padding, but can be {@linkplain #omitPadding()
* omitted} or {@linkplain #withPadChar(char) replaced}.
*
* <p>No line feeds are added by default, as per <a
* href="http://tools.ietf.org/html/rfc4648#section-3.1"> RFC 4648 section 3.1</a>, Line Feeds in
* Encoded Data. Line feeds may be added using {@link #withSeparator(String, int)}.
*/
public static BaseEncoding base32() {
return BASE32;
}
private static final BaseEncoding BASE32_HEX =
new StandardBaseEncoding("base32Hex()", "0123456789ABCDEFGHIJKLMNOPQRSTUV", '=');
/**
* The "base32hex" encoding specified by <a
* href="http://tools.ietf.org/html/rfc4648#section-7">RFC 4648 section 7</a>, Base 32 Encoding
* with Extended Hex Alphabet. There is no corresponding encoding in RFC 3548.
*
* <p>The character {@code '='} is used for padding, but can be {@linkplain #omitPadding()
* omitted} or {@linkplain #withPadChar(char) replaced}.
*
* <p>No line feeds are added by default, as per <a
* href="http://tools.ietf.org/html/rfc4648#section-3.1"> RFC 4648 section 3.1</a>, Line Feeds in
* Encoded Data. Line feeds may be added using {@link #withSeparator(String, int)}.
*/
public static BaseEncoding base32Hex() {
return BASE32_HEX;
}
private static final BaseEncoding BASE16 =
new StandardBaseEncoding("base16()", "0123456789ABCDEF", null);
/**
* The "base16" encoding specified by <a
* href="http://tools.ietf.org/html/rfc4648#section-8">RFC 4648 section 8</a>, Base 16 Encoding.
* (This is the same as the base 16 encoding from <a
* href="http://tools.ietf.org/html/rfc3548#section-6">RFC 3548</a>.) This is commonly known as
* "hexadecimal" format.
*
* <p>No padding is necessary in base 16, so {@link #withPadChar(char)} and
* {@link #omitPadding()} have no effect.
*
* <p>No line feeds are added by default, as per <a
* href="http://tools.ietf.org/html/rfc4648#section-3.1"> RFC 4648 section 3.1</a>, Line Feeds in
* Encoded Data. Line feeds may be added using {@link #withSeparator(String, int)}.
*/
public static BaseEncoding base16() {
return BASE16;
}
private static final class Alphabet extends CharMatcher {
private final String name;
// this is meant to be immutable -- don't modify it!
private final char[] chars;
final int mask;
final int bitsPerChar;
final int charsPerChunk;
final int bytesPerChunk;
private final byte[] decodabet;
private final boolean[] validPadding;
Alphabet(String name, char[] chars) {
this.name = checkNotNull(name);
this.chars = checkNotNull(chars);
try {
this.bitsPerChar = log2(chars.length, UNNECESSARY);
} catch (ArithmeticException e) {
throw new IllegalArgumentException("Illegal alphabet length " + chars.length, e);
}
/*
* e.g. for base64, bitsPerChar == 6, charsPerChunk == 4, and bytesPerChunk == 3. This makes
* for the smallest chunk size that still has charsPerChunk * bitsPerChar be a multiple of 8.
*/
int gcd = Math.min(8, Integer.lowestOneBit(bitsPerChar));
this.charsPerChunk = 8 / gcd;
this.bytesPerChunk = bitsPerChar / gcd;
this.mask = chars.length - 1;
byte[] decodabet = new byte[Ascii.MAX + 1];
Arrays.fill(decodabet, (byte) -1);
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
checkArgument(CharMatcher.ASCII.matches(c), "Non-ASCII character: %s", c);
checkArgument(decodabet[c] == -1, "Duplicate character: %s", c);
decodabet[c] = (byte) i;
}
this.decodabet = decodabet;
boolean[] validPadding = new boolean[charsPerChunk];
for (int i = 0; i < bytesPerChunk; i++) {
validPadding[divide(i * 8, bitsPerChar, CEILING)] = true;
}
this.validPadding = validPadding;
}
char encode(int bits) {
return chars[bits];
}
boolean isValidPaddingStartPosition(int index) {
return validPadding[index % charsPerChunk];
}
int decode(char ch) throws IOException {
if (ch > Ascii.MAX || decodabet[ch] == -1) {
throw new DecodingException("Unrecognized character: " + ch);
}
return decodabet[ch];
}
private boolean hasLowerCase() {
for (char c : chars) {
if (Ascii.isLowerCase(c)) {
return true;
}
}
return false;
}
private boolean hasUpperCase() {
for (char c : chars) {
if (Ascii.isUpperCase(c)) {
return true;
}
}
return false;
}
Alphabet upperCase() {
if (!hasLowerCase()) {
return this;
} else {
checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet");
char[] upperCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
upperCased[i] = Ascii.toUpperCase(chars[i]);
}
return new Alphabet(name + ".upperCase()", upperCased);
}
}
Alphabet lowerCase() {
if (!hasUpperCase()) {
return this;
} else {
checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet");
char[] lowerCased = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
lowerCased[i] = Ascii.toLowerCase(chars[i]);
}
return new Alphabet(name + ".lowerCase()", lowerCased);
}
}
@Override
public boolean matches(char c) {
return CharMatcher.ASCII.matches(c) && decodabet[c] != -1;
}
@Override
public String toString() {
return name;
}
}
static final class StandardBaseEncoding extends BaseEncoding {
// TODO(user): provide a useful toString
private final Alphabet alphabet;
@Nullable
private final Character paddingChar;
StandardBaseEncoding(String name, String alphabetChars, @Nullable Character paddingChar) {
this(new Alphabet(name, alphabetChars.toCharArray()), paddingChar);
}
StandardBaseEncoding(Alphabet alphabet, @Nullable Character paddingChar) {
this.alphabet = checkNotNull(alphabet);
checkArgument(paddingChar == null || !alphabet.matches(paddingChar),
"Padding character %s was already in alphabet", paddingChar);
this.paddingChar = paddingChar;
}
@Override
CharMatcher padding() {
return (paddingChar == null) ? CharMatcher.NONE : CharMatcher.is(paddingChar.charValue());
}
@Override
int maxEncodedSize(int bytes) {
return alphabet.charsPerChunk * divide(bytes, alphabet.bytesPerChunk, CEILING);
}
@Override
ByteOutput encodingStream(final CharOutput out) {
checkNotNull(out);
return new ByteOutput() {
int bitBuffer = 0;
int bitBufferLength = 0;
int writtenChars = 0;
@Override
public void write(byte b) throws IOException {
bitBuffer <<= 8;
bitBuffer |= b & 0xFF;
bitBufferLength += 8;
while (bitBufferLength >= alphabet.bitsPerChar) {
int charIndex = (bitBuffer >> (bitBufferLength - alphabet.bitsPerChar))
& alphabet.mask;
out.write(alphabet.encode(charIndex));
writtenChars++;
bitBufferLength -= alphabet.bitsPerChar;
}
}
@Override
public void flush() throws IOException {
out.flush();
}
@Override
public void close() throws IOException {
if (bitBufferLength > 0) {
int charIndex = (bitBuffer << (alphabet.bitsPerChar - bitBufferLength))
& alphabet.mask;
out.write(alphabet.encode(charIndex));
writtenChars++;
if (paddingChar != null) {
while (writtenChars % alphabet.charsPerChunk != 0) {
out.write(paddingChar.charValue());
writtenChars++;
}
}
}
out.close();
}
};
}
@Override
int maxDecodedSize(int chars) {
return (int) ((alphabet.bitsPerChar * (long) chars + 7L) / 8L);
}
@Override
ByteInput decodingStream(final CharInput reader) {
checkNotNull(reader);
return new ByteInput() {
int bitBuffer = 0;
int bitBufferLength = 0;
int readChars = 0;
boolean hitPadding = false;
final CharMatcher paddingMatcher = padding();
@Override
public int read() throws IOException {
while (true) {
int readChar = reader.read();
if (readChar == -1) {
if (!hitPadding && !alphabet.isValidPaddingStartPosition(readChars)) {
throw new DecodingException("Invalid input length " + readChars);
}
return -1;
}
readChars++;
char ch = (char) readChar;
if (paddingMatcher.matches(ch)) {
if (!hitPadding
&& (readChars == 1 || !alphabet.isValidPaddingStartPosition(readChars - 1))) {
throw new DecodingException("Padding cannot start at index " + readChars);
}
hitPadding = true;
} else if (hitPadding) {
throw new DecodingException(
"Expected padding character but found '" + ch + "' at index " + readChars);
} else {
bitBuffer <<= alphabet.bitsPerChar;
bitBuffer |= alphabet.decode(ch);
bitBufferLength += alphabet.bitsPerChar;
if (bitBufferLength >= 8) {
bitBufferLength -= 8;
return (bitBuffer >> bitBufferLength) & 0xFF;
}
}
}
}
@Override
public void close() throws IOException {
reader.close();
}
};
}
@Override
public BaseEncoding omitPadding() {
return (paddingChar == null) ? this : new StandardBaseEncoding(alphabet, null);
}
@Override
public BaseEncoding withPadChar(char padChar) {
if (8 % alphabet.bitsPerChar == 0 ||
(paddingChar != null && paddingChar.charValue() == padChar)) {
return this;
} else {
return new StandardBaseEncoding(alphabet, padChar);
}
}
@Override
public BaseEncoding withSeparator(String separator, int afterEveryChars) {
checkNotNull(separator);
checkArgument(padding().or(alphabet).matchesNoneOf(separator),
"Separator cannot contain alphabet or padding characters");
return new SeparatedBaseEncoding(this, separator, afterEveryChars);
}
private transient BaseEncoding upperCase;
private transient BaseEncoding lowerCase;
@Override
public BaseEncoding upperCase() {
BaseEncoding result = upperCase;
if (result == null) {
Alphabet upper = alphabet.upperCase();
result = upperCase =
(upper == alphabet) ? this : new StandardBaseEncoding(upper, paddingChar);
}
return result;
}
@Override
public BaseEncoding lowerCase() {
BaseEncoding result = lowerCase;
if (result == null) {
Alphabet lower = alphabet.lowerCase();
result = lowerCase =
(lower == alphabet) ? this : new StandardBaseEncoding(lower, paddingChar);
}
return result;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder("BaseEncoding.");
builder.append(alphabet.toString());
if (8 % alphabet.bitsPerChar != 0) {
if (paddingChar == null) {
builder.append(".omitPadding()");
} else {
builder.append(".withPadChar(").append(paddingChar).append(')');
}
}
return builder.toString();
}
}
static CharInput ignoringInput(final CharInput delegate, final CharMatcher toIgnore) {
checkNotNull(delegate);
checkNotNull(toIgnore);
return new CharInput() {
@Override
public int read() throws IOException {
int readChar;
do {
readChar = delegate.read();
} while (readChar != -1 && toIgnore.matches((char) readChar));
return readChar;
}
@Override
public void close() throws IOException {
delegate.close();
}
};
}
static CharOutput separatingOutput(
final CharOutput delegate, final String separator, final int afterEveryChars) {
checkNotNull(delegate);
checkNotNull(separator);
checkArgument(afterEveryChars > 0);
return new CharOutput() {
int charsUntilSeparator = afterEveryChars;
@Override
public void write(char c) throws IOException {
if (charsUntilSeparator == 0) {
for (int i = 0; i < separator.length(); i++) {
delegate.write(separator.charAt(i));
}
charsUntilSeparator = afterEveryChars;
}
delegate.write(c);
charsUntilSeparator--;
}
@Override
public void flush() throws IOException {
delegate.flush();
}
@Override
public void close() throws IOException {
delegate.close();
}
};
}
static final class SeparatedBaseEncoding extends BaseEncoding {
private final BaseEncoding delegate;
private final String separator;
private final int afterEveryChars;
private final CharMatcher separatorChars;
SeparatedBaseEncoding(BaseEncoding delegate, String separator, int afterEveryChars) {
this.delegate = checkNotNull(delegate);
this.separator = checkNotNull(separator);
this.afterEveryChars = afterEveryChars;
checkArgument(
afterEveryChars > 0, "Cannot add a separator after every %s chars", afterEveryChars);
this.separatorChars = CharMatcher.anyOf(separator).precomputed();
}
@Override
CharMatcher padding() {
return delegate.padding();
}
@Override
int maxEncodedSize(int bytes) {
int unseparatedSize = delegate.maxEncodedSize(bytes);
return unseparatedSize + separator.length()
* divide(Math.max(0, unseparatedSize - 1), afterEveryChars, FLOOR);
}
@Override
ByteOutput encodingStream(final CharOutput output) {
return delegate.encodingStream(separatingOutput(output, separator, afterEveryChars));
}
@Override
int maxDecodedSize(int chars) {
return delegate.maxDecodedSize(chars);
}
@Override
ByteInput decodingStream(final CharInput input) {
return delegate.decodingStream(ignoringInput(input, separatorChars));
}
@Override
public BaseEncoding omitPadding() {
return delegate.omitPadding().withSeparator(separator, afterEveryChars);
}
@Override
public BaseEncoding withPadChar(char padChar) {
return delegate.withPadChar(padChar).withSeparator(separator, afterEveryChars);
}
@Override
public BaseEncoding withSeparator(String separator, int afterEveryChars) {
throw new UnsupportedOperationException("Already have a separator");
}
@Override
public BaseEncoding upperCase() {
return delegate.upperCase().withSeparator(separator, afterEveryChars);
}
@Override
public BaseEncoding lowerCase() {
return delegate.lowerCase().withSeparator(separator, afterEveryChars);
}
@Override
public String toString() {
return delegate.toString() +
".withSeparator(\"" + separator + "\", " + afterEveryChars + ")";
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/io/super/com/google/common/io/BaseEncoding.java | Java | asf20 | 27,688 |
/*
* Copyright (C) 2012 The Guava Authors
*
* 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.common.io;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.io.IOException;
/**
* Provides simple GWT-compatible substitutes for {@code InputStream}, {@code OutputStream},
* {@code Reader}, and {@code Writer} so that {@code BaseEncoding} can use streaming implementations
* while remaining GWT-compatible.
*
* @author Louis Wasserman
*/
@GwtCompatible(emulated = true)
final class GwtWorkarounds {
private GwtWorkarounds() {}
/**
* A GWT-compatible substitute for a {@code Reader}.
*/
interface CharInput {
int read() throws IOException;
void close() throws IOException;
}
/**
* Views a {@code CharSequence} as a {@code CharInput}.
*/
static CharInput asCharInput(final CharSequence chars) {
checkNotNull(chars);
return new CharInput() {
int index = 0;
@Override
public int read() {
if (index < chars.length()) {
return chars.charAt(index++);
} else {
return -1;
}
}
@Override
public void close() {
index = chars.length();
}
};
}
/**
* A GWT-compatible substitute for an {@code InputStream}.
*/
interface ByteInput {
int read() throws IOException;
void close() throws IOException;
}
/**
* A GWT-compatible substitute for an {@code OutputStream}.
*/
interface ByteOutput {
void write(byte b) throws IOException;
void flush() throws IOException;
void close() throws IOException;
}
/**
* A GWT-compatible substitute for a {@code Writer}.
*/
interface CharOutput {
void write(char c) throws IOException;
void flush() throws IOException;
void close() throws IOException;
}
/**
* Returns a {@code CharOutput} whose {@code toString()} method can be used
* to get the combined output.
*/
static CharOutput stringBuilderOutput(int initialSize) {
final StringBuilder builder = new StringBuilder(initialSize);
return new CharOutput() {
@Override
public void write(char c) {
builder.append(c);
}
@Override
public void flush() {}
@Override
public void close() {}
@Override
public String toString() {
return builder.toString();
}
};
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/io/super/com/google/common/io/GwtWorkarounds.java | Java | asf20 | 2,952 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.escape;
/**
* @author Jesse Wilson
*/
final class Platform {
private static final char[] CHAR_BUFFER = new char[1024];
static char[] charBufferFromThreadLocal() {
// ThreadLocal is not available to GWT, so we always reuse the same
// instance. It is always safe to return the same instance because
// javascript is single-threaded, and only used by blocks that doesn't
// involve async callbacks.
return CHAR_BUFFER;
}
private Platform() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/escape/super/com/google/common/escape/Platform.java | Java | asf20 | 1,106 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.math;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.math.MathPreconditions.checkNonNegative;
import static com.google.common.math.MathPreconditions.checkPositive;
import static com.google.common.math.MathPreconditions.checkRoundingUnnecessary;
import static java.lang.Math.min;
import static java.math.RoundingMode.HALF_EVEN;
import static java.math.RoundingMode.HALF_UP;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import java.math.RoundingMode;
/**
* A class for arithmetic on values of type {@code long}. Where possible, methods are defined and
* named analogously to their {@code BigInteger} counterparts.
*
* <p>The implementations of many methods in this class are based on material from Henry S. Warren,
* Jr.'s <i>Hacker's Delight</i>, (Addison Wesley, 2002).
*
* <p>Similar functionality for {@code int} and for {@link BigInteger} can be found in
* {@link IntMath} and {@link BigIntegerMath} respectively. For other common operations on
* {@code long} values, see {@link com.google.common.primitives.Longs}.
*
* @author Louis Wasserman
* @since 11.0
*/
@GwtCompatible(emulated = true)
public final class LongMath {
// NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||
/**
* Returns {@code true} if {@code x} represents a power of two.
*
* <p>This differs from {@code Long.bitCount(x) == 1}, because
* {@code Long.bitCount(Long.MIN_VALUE) == 1}, but {@link Long#MIN_VALUE} is not a power of two.
*/
public static boolean isPowerOfTwo(long x) {
return x > 0 & (x & (x - 1)) == 0;
}
/**
* Returns 1 if {@code x < y} as unsigned longs, and 0 otherwise. Assumes that x - y fits into a
* signed long. The implementation is branch-free, and benchmarks suggest it is measurably
* faster than the straightforward ternary expression.
*/
@VisibleForTesting
static int lessThanBranchFree(long x, long y) {
// Returns the sign bit of x - y.
return (int) (~~(x - y) >>> (Long.SIZE - 1));
}
/**
* Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x <= 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and {@code x}
* is not a power of two
*/
@SuppressWarnings("fallthrough")
// TODO(kevinb): remove after this warning is disabled globally
public static int log2(long x, RoundingMode mode) {
checkPositive("x", x);
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(isPowerOfTwo(x));
// fall through
case DOWN:
case FLOOR:
return (Long.SIZE - 1) - Long.numberOfLeadingZeros(x);
case UP:
case CEILING:
return Long.SIZE - Long.numberOfLeadingZeros(x - 1);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
// Since sqrt(2) is irrational, log2(x) - logFloor cannot be exactly 0.5
int leadingZeros = Long.numberOfLeadingZeros(x);
long cmp = MAX_POWER_OF_SQRT2_UNSIGNED >>> leadingZeros;
// floor(2^(logFloor + 0.5))
int logFloor = (Long.SIZE - 1) - leadingZeros;
return logFloor + lessThanBranchFree(cmp, x);
default:
throw new AssertionError("impossible");
}
}
/** The biggest half power of two that fits into an unsigned long */
@VisibleForTesting static final long MAX_POWER_OF_SQRT2_UNSIGNED = 0xB504F333F9DE6484L;
// maxLog10ForLeadingZeros[i] == floor(log10(2^(Long.SIZE - i)))
@VisibleForTesting static final byte[] maxLog10ForLeadingZeros = {
19, 18, 18, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12,
12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 4, 4, 4,
3, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0 };
// halfPowersOf10[i] = largest long less than 10^(i + 0.5)
/**
* Returns the greatest common divisor of {@code a, b}. Returns {@code 0} if
* {@code a == 0 && b == 0}.
*
* @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
*/
public static long gcd(long a, long b) {
/*
* The reason we require both arguments to be >= 0 is because otherwise, what do you return on
* gcd(0, Long.MIN_VALUE)? BigInteger.gcd would return positive 2^63, but positive 2^63 isn't
* an int.
*/
checkNonNegative("a", a);
checkNonNegative("b", b);
if (a == 0) {
// 0 % b == 0, so b divides a, but the converse doesn't hold.
// BigInteger.gcd is consistent with this decision.
return b;
} else if (b == 0) {
return a; // similar logic
}
/*
* Uses the binary GCD algorithm; see http://en.wikipedia.org/wiki/Binary_GCD_algorithm.
* This is >60% faster than the Euclidean algorithm in benchmarks.
*/
int aTwos = Long.numberOfTrailingZeros(a);
a >>= aTwos; // divide out all 2s
int bTwos = Long.numberOfTrailingZeros(b);
b >>= bTwos; // divide out all 2s
while (a != b) { // both a, b are odd
// The key to the binary GCD algorithm is as follows:
// Both a and b are odd. Assume a > b; then gcd(a - b, b) = gcd(a, b).
// But in gcd(a - b, b), a - b is even and b is odd, so we can divide out powers of two.
// We bend over backwards to avoid branching, adapting a technique from
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
long delta = a - b; // can't overflow, since a and b are nonnegative
long minDeltaOrZero = delta & (delta >> (Long.SIZE - 1));
// equivalent to Math.min(delta, 0)
a = delta - minDeltaOrZero - minDeltaOrZero; // sets a to Math.abs(a - b)
// a is now nonnegative and even
b += minDeltaOrZero; // sets b to min(old a, b)
a >>= Long.numberOfTrailingZeros(a); // divide out all 2s, since 2 doesn't divide b
}
return a << min(aTwos, bTwos);
}
@VisibleForTesting static final long FLOOR_SQRT_MAX_LONG = 3037000499L;
static final long[] factorials = {
1L,
1L,
1L * 2,
1L * 2 * 3,
1L * 2 * 3 * 4,
1L * 2 * 3 * 4 * 5,
1L * 2 * 3 * 4 * 5 * 6,
1L * 2 * 3 * 4 * 5 * 6 * 7,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19,
1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20
};
/**
* Returns {@code n} choose {@code k}, also known as the binomial coefficient of {@code n} and
* {@code k}, or {@link Long#MAX_VALUE} if the result does not fit in a {@code long}.
*
* @throws IllegalArgumentException if {@code n < 0}, {@code k < 0}, or {@code k > n}
*/
public static long binomial(int n, int k) {
checkNonNegative("n", n);
checkNonNegative("k", k);
checkArgument(k <= n, "k (%s) > n (%s)", k, n);
if (k > (n >> 1)) {
k = n - k;
}
switch (k) {
case 0:
return 1;
case 1:
return n;
default:
if (n < factorials.length) {
return factorials[n] / (factorials[k] * factorials[n - k]);
} else if (k >= biggestBinomials.length || n > biggestBinomials[k]) {
return Long.MAX_VALUE;
} else if (k < biggestSimpleBinomials.length && n <= biggestSimpleBinomials[k]) {
// guaranteed not to overflow
long result = n--;
for (int i = 2; i <= k; n--, i++) {
result *= n;
result /= i;
}
return result;
} else {
int nBits = LongMath.log2(n, RoundingMode.CEILING);
long result = 1;
long numerator = n--;
long denominator = 1;
int numeratorBits = nBits;
// This is an upper bound on log2(numerator, ceiling).
/*
* We want to do this in long math for speed, but want to avoid overflow. We adapt the
* technique previously used by BigIntegerMath: maintain separate numerator and
* denominator accumulators, multiplying the fraction into result when near overflow.
*/
for (int i = 2; i <= k; i++, n--) {
if (numeratorBits + nBits < Long.SIZE - 1) {
// It's definitely safe to multiply into numerator and denominator.
numerator *= n;
denominator *= i;
numeratorBits += nBits;
} else {
// It might not be safe to multiply into numerator and denominator,
// so multiply (numerator / denominator) into result.
result = multiplyFraction(result, numerator, denominator);
numerator = n;
denominator = i;
numeratorBits = nBits;
}
}
return multiplyFraction(result, numerator, denominator);
}
}
}
/**
* Returns (x * numerator / denominator), which is assumed to come out to an integral value.
*/
static long multiplyFraction(long x, long numerator, long denominator) {
if (x == 1) {
return numerator / denominator;
}
long commonDivisor = gcd(x, denominator);
x /= commonDivisor;
denominator /= commonDivisor;
// We know gcd(x, denominator) = 1, and x * numerator / denominator is exact,
// so denominator must be a divisor of numerator.
return x * (numerator / denominator);
}
/*
* binomial(biggestBinomials[k], k) fits in a long, but not
* binomial(biggestBinomials[k] + 1, k).
*/
static final int[] biggestBinomials =
{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, 3810779, 121977, 16175, 4337, 1733,
887, 534, 361, 265, 206, 169, 143, 125, 111, 101, 94, 88, 83, 79, 76, 74, 72, 70, 69, 68,
67, 67, 66, 66, 66, 66};
/*
* binomial(biggestSimpleBinomials[k], k) doesn't need to use the slower GCD-based impl,
* but binomial(biggestSimpleBinomials[k] + 1, k) does.
*/
@VisibleForTesting static final int[] biggestSimpleBinomials =
{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, 2642246, 86251, 11724, 3218, 1313,
684, 419, 287, 214, 169, 139, 119, 105, 95, 87, 81, 76, 73, 70, 68, 66, 64, 63, 62, 62,
61, 61, 61};
// These values were generated by using checkedMultiply to see when the simple multiply/divide
// algorithm would lead to an overflow.
static boolean fitsInInt(long x) {
return (int) x == x;
}
/**
* Returns the arithmetic mean of {@code x} and {@code y}, rounded toward
* negative infinity. This method is resilient to overflow.
*
* @since 14.0
*/
public static long mean(long x, long y) {
// Efficient method for computing the arithmetic mean.
// The alternative (x + y) / 2 fails for large values.
// The alternative (x + y) >>> 1 fails for negative values.
return (x & y) + ((x ^ y) >> 1);
}
private LongMath() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/math/super/com/google/common/math/LongMath.java | Java | asf20 | 12,327 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.math;
import static com.google.common.math.MathPreconditions.checkNonNegative;
import static java.lang.Math.log;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.primitives.Booleans;
/**
* A class for arithmetic on doubles that is not covered by {@link java.lang.Math}.
*
* @author Louis Wasserman
* @since 11.0
*/
@GwtCompatible(emulated = true)
public final class DoubleMath {
/*
* This method returns a value y such that rounding y DOWN (towards zero) gives the same result
* as rounding x according to the specified mode.
*/
private static final double MIN_INT_AS_DOUBLE = -0x1p31;
private static final double MAX_INT_AS_DOUBLE = 0x1p31 - 1.0;
private static final double MIN_LONG_AS_DOUBLE = -0x1p63;
/*
* We cannot store Long.MAX_VALUE as a double without losing precision. Instead, we store
* Long.MAX_VALUE + 1 == -Long.MIN_VALUE, and then offset all comparisons by 1.
*/
private static final double MAX_LONG_AS_DOUBLE_PLUS_ONE = 0x1p63;
/**
* Returns the base 2 logarithm of a double value.
*
* <p>Special cases:
* <ul>
* <li>If {@code x} is NaN or less than zero, the result is NaN.
* <li>If {@code x} is positive infinity, the result is positive infinity.
* <li>If {@code x} is positive or negative zero, the result is negative infinity.
* </ul>
*
* <p>The computed result is within 1 ulp of the exact result.
*
* <p>If the result of this method will be immediately rounded to an {@code int},
* {@link #log2(double, RoundingMode)} is faster.
*/
public static double log2(double x) {
return log(x) / LN_2; // surprisingly within 1 ulp according to tests
}
private static final double LN_2 = log(2);
/**
* Returns {@code n!}, that is, the product of the first {@code n} positive
* integers, {@code 1} if {@code n == 0}, or e n!}, or
* {@link Double#POSITIVE_INFINITY} if {@code n! > Double.MAX_VALUE}.
*
* <p>The result is within 1 ulp of the true value.
*
* @throws IllegalArgumentException if {@code n < 0}
*/
public static double factorial(int n) {
checkNonNegative("n", n);
if (n > MAX_FACTORIAL) {
return Double.POSITIVE_INFINITY;
} else {
// Multiplying the last (n & 0xf) values into their own accumulator gives a more accurate
// result than multiplying by everySixteenthFactorial[n >> 4] directly.
double accum = 1.0;
for (int i = 1 + (n & ~0xf); i <= n; i++) {
accum *= i;
}
return accum * everySixteenthFactorial[n >> 4];
}
}
@VisibleForTesting
static final int MAX_FACTORIAL = 170;
@VisibleForTesting
static final double[] everySixteenthFactorial = {
0x1.0p0,
0x1.30777758p44,
0x1.956ad0aae33a4p117,
0x1.ee69a78d72cb6p202,
0x1.fe478ee34844ap295,
0x1.c619094edabffp394,
0x1.3638dd7bd6347p498,
0x1.7cac197cfe503p605,
0x1.1e5dfc140e1e5p716,
0x1.8ce85fadb707ep829,
0x1.95d5f3d928edep945};
/**
* Returns {@code true} if {@code a} and {@code b} are within {@code tolerance} of each other.
*
* <p>Technically speaking, this is equivalent to
* {@code Math.abs(a - b) <= tolerance || Double.valueOf(a).equals(Double.valueOf(b))}.
*
* <p>Notable special cases include:
* <ul>
* <li>All NaNs are fuzzily equal.
* <li>If {@code a == b}, then {@code a} and {@code b} are always fuzzily equal.
* <li>Positive and negative zero are always fuzzily equal.
* <li>If {@code tolerance} is zero, and neither {@code a} nor {@code b} is NaN, then
* {@code a} and {@code b} are fuzzily equal if and only if {@code a == b}.
* <li>With {@link Double#POSITIVE_INFINITY} tolerance, all non-NaN values are fuzzily equal.
* <li>With finite tolerance, {@code Double.POSITIVE_INFINITY} and {@code
* Double.NEGATIVE_INFINITY} are fuzzily equal only to themselves.
* </li>
*
* <p>This is reflexive and symmetric, but <em>not</em> transitive, so it is <em>not</em> an
* equivalence relation and <em>not</em> suitable for use in {@link Object#equals}
* implementations.
*
* @throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN
* @since 13.0
*/
public static boolean fuzzyEquals(double a, double b, double tolerance) {
MathPreconditions.checkNonNegative("tolerance", tolerance);
return
Math.copySign(a - b, 1.0) <= tolerance
// copySign(x, 1.0) is a branch-free version of abs(x), but with different NaN semantics
|| (a == b) // needed to ensure that infinities equal themselves
|| (Double.isNaN(a) && Double.isNaN(b));
}
/**
* Compares {@code a} and {@code b} "fuzzily," with a tolerance for nearly-equal values.
*
* <p>This method is equivalent to
* {@code fuzzyEquals(a, b, tolerance) ? 0 : Double.compare(a, b)}. In particular, like
* {@link Double#compare(double, double)}, it treats all NaN values as equal and greater than all
* other values (including {@link Double#POSITIVE_INFINITY}).
*
* <p>This is <em>not</em> a total ordering and is <em>not</em> suitable for use in
* {@link Comparable#compareTo} implementations. In particular, it is not transitive.
*
* @throws IllegalArgumentException if {@code tolerance} is {@code < 0} or NaN
* @since 13.0
*/
public static int fuzzyCompare(double a, double b, double tolerance) {
if (fuzzyEquals(a, b, tolerance)) {
return 0;
} else if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return Booleans.compare(Double.isNaN(a), Double.isNaN(b));
}
}
private DoubleMath() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/math/super/com/google/common/math/DoubleMath.java | Java | asf20 | 6,350 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.math;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.math.MathPreconditions.checkNonNegative;
import static com.google.common.math.MathPreconditions.checkPositive;
import static com.google.common.math.MathPreconditions.checkRoundingUnnecessary;
import static java.math.RoundingMode.CEILING;
import static java.math.RoundingMode.FLOOR;
import static java.math.RoundingMode.HALF_EVEN;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
/**
* A class for arithmetic on values of type {@code BigInteger}.
*
* <p>The implementations of many methods in this class are based on material from Henry S. Warren,
* Jr.'s <i>Hacker's Delight</i>, (Addison Wesley, 2002).
*
* <p>Similar functionality for {@code int} and for {@code long} can be found in
* {@link IntMath} and {@link LongMath} respectively.
*
* @author Louis Wasserman
* @since 11.0
*/
@GwtCompatible(emulated = true)
public final class BigIntegerMath {
/**
* Returns {@code true} if {@code x} represents a power of two.
*/
public static boolean isPowerOfTwo(BigInteger x) {
checkNotNull(x);
return x.signum() > 0 && x.getLowestSetBit() == x.bitLength() - 1;
}
/**
* Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x <= 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and {@code x}
* is not a power of two
*/
@SuppressWarnings("fallthrough")
// TODO(kevinb): remove after this warning is disabled globally
public static int log2(BigInteger x, RoundingMode mode) {
checkPositive("x", checkNotNull(x));
int logFloor = x.bitLength() - 1;
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(isPowerOfTwo(x)); // fall through
case DOWN:
case FLOOR:
return logFloor;
case UP:
case CEILING:
return isPowerOfTwo(x) ? logFloor : logFloor + 1;
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
if (logFloor < SQRT2_PRECOMPUTE_THRESHOLD) {
BigInteger halfPower = SQRT2_PRECOMPUTED_BITS.shiftRight(
SQRT2_PRECOMPUTE_THRESHOLD - logFloor);
if (x.compareTo(halfPower) <= 0) {
return logFloor;
} else {
return logFloor + 1;
}
}
/*
* Since sqrt(2) is irrational, log2(x) - logFloor cannot be exactly 0.5
*
* To determine which side of logFloor.5 the logarithm is, we compare x^2 to 2^(2 *
* logFloor + 1).
*/
BigInteger x2 = x.pow(2);
int logX2Floor = x2.bitLength() - 1;
return (logX2Floor < 2 * logFloor + 1) ? logFloor : logFloor + 1;
default:
throw new AssertionError();
}
}
/*
* The maximum number of bits in a square root for which we'll precompute an explicit half power
* of two. This can be any value, but higher values incur more class load time and linearly
* increasing memory consumption.
*/
@VisibleForTesting static final int SQRT2_PRECOMPUTE_THRESHOLD = 256;
@VisibleForTesting static final BigInteger SQRT2_PRECOMPUTED_BITS =
new BigInteger("16a09e667f3bcc908b2fb1366ea957d3e3adec17512775099da2f590b0667322a", 16);
private static final double LN_10 = Math.log(10);
private static final double LN_2 = Math.log(2);
/**
* Returns {@code n!}, that is, the product of the first {@code n} positive
* integers, or {@code 1} if {@code n == 0}.
*
* <p><b>Warning</b>: the result takes <i>O(n log n)</i> space, so use cautiously.
*
* <p>This uses an efficient binary recursive algorithm to compute the factorial
* with balanced multiplies. It also removes all the 2s from the intermediate
* products (shifting them back in at the end).
*
* @throws IllegalArgumentException if {@code n < 0}
*/
public static BigInteger factorial(int n) {
checkNonNegative("n", n);
// If the factorial is small enough, just use LongMath to do it.
if (n < LongMath.factorials.length) {
return BigInteger.valueOf(LongMath.factorials[n]);
}
// Pre-allocate space for our list of intermediate BigIntegers.
int approxSize = IntMath.divide(n * IntMath.log2(n, CEILING), Long.SIZE, CEILING);
ArrayList<BigInteger> bignums = new ArrayList<BigInteger>(approxSize);
// Start from the pre-computed maximum long factorial.
int startingNumber = LongMath.factorials.length;
long product = LongMath.factorials[startingNumber - 1];
// Strip off 2s from this value.
int shift = Long.numberOfTrailingZeros(product);
product >>= shift;
// Use floor(log2(num)) + 1 to prevent overflow of multiplication.
int productBits = LongMath.log2(product, FLOOR) + 1;
int bits = LongMath.log2(startingNumber, FLOOR) + 1;
// Check for the next power of two boundary, to save us a CLZ operation.
int nextPowerOfTwo = 1 << (bits - 1);
// Iteratively multiply the longs as big as they can go.
for (long num = startingNumber; num <= n; num++) {
// Check to see if the floor(log2(num)) + 1 has changed.
if ((num & nextPowerOfTwo) != 0) {
nextPowerOfTwo <<= 1;
bits++;
}
// Get rid of the 2s in num.
int tz = Long.numberOfTrailingZeros(num);
long normalizedNum = num >> tz;
shift += tz;
// Adjust floor(log2(num)) + 1.
int normalizedBits = bits - tz;
// If it won't fit in a long, then we store off the intermediate product.
if (normalizedBits + productBits >= Long.SIZE) {
bignums.add(BigInteger.valueOf(product));
product = 1;
productBits = 0;
}
product *= normalizedNum;
productBits = LongMath.log2(product, FLOOR) + 1;
}
// Check for leftovers.
if (product > 1) {
bignums.add(BigInteger.valueOf(product));
}
// Efficiently multiply all the intermediate products together.
return listProduct(bignums).shiftLeft(shift);
}
static BigInteger listProduct(List<BigInteger> nums) {
return listProduct(nums, 0, nums.size());
}
static BigInteger listProduct(List<BigInteger> nums, int start, int end) {
switch (end - start) {
case 0:
return BigInteger.ONE;
case 1:
return nums.get(start);
case 2:
return nums.get(start).multiply(nums.get(start + 1));
case 3:
return nums.get(start).multiply(nums.get(start + 1)).multiply(nums.get(start + 2));
default:
// Otherwise, split the list in half and recursively do this.
int m = (end + start) >>> 1;
return listProduct(nums, start, m).multiply(listProduct(nums, m, end));
}
}
/**
* Returns {@code n} choose {@code k}, also known as the binomial coefficient of {@code n} and
* {@code k}, that is, {@code n! / (k! (n - k)!)}.
*
* <p><b>Warning</b>: the result can take as much as <i>O(k log n)</i> space.
*
* @throws IllegalArgumentException if {@code n < 0}, {@code k < 0}, or {@code k > n}
*/
public static BigInteger binomial(int n, int k) {
checkNonNegative("n", n);
checkNonNegative("k", k);
checkArgument(k <= n, "k (%s) > n (%s)", k, n);
if (k > (n >> 1)) {
k = n - k;
}
if (k < LongMath.biggestBinomials.length && n <= LongMath.biggestBinomials[k]) {
return BigInteger.valueOf(LongMath.binomial(n, k));
}
BigInteger accum = BigInteger.ONE;
long numeratorAccum = n;
long denominatorAccum = 1;
int bits = LongMath.log2(n, RoundingMode.CEILING);
int numeratorBits = bits;
for (int i = 1; i < k; i++) {
int p = n - i;
int q = i + 1;
// log2(p) >= bits - 1, because p >= n/2
if (numeratorBits + bits >= Long.SIZE - 1) {
// The numerator is as big as it can get without risking overflow.
// Multiply numeratorAccum / denominatorAccum into accum.
accum = accum
.multiply(BigInteger.valueOf(numeratorAccum))
.divide(BigInteger.valueOf(denominatorAccum));
numeratorAccum = p;
denominatorAccum = q;
numeratorBits = bits;
} else {
// We can definitely multiply into the long accumulators without overflowing them.
numeratorAccum *= p;
denominatorAccum *= q;
numeratorBits += bits;
}
}
return accum
.multiply(BigInteger.valueOf(numeratorAccum))
.divide(BigInteger.valueOf(denominatorAccum));
}
// Returns true if BigInteger.valueOf(x.longValue()).equals(x).
private BigIntegerMath() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/math/super/com/google/common/math/BigIntegerMath.java | Java | asf20 | 9,493 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.math;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.math.MathPreconditions.checkNoOverflow;
import static com.google.common.math.MathPreconditions.checkNonNegative;
import static com.google.common.math.MathPreconditions.checkPositive;
import static com.google.common.math.MathPreconditions.checkRoundingUnnecessary;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.math.RoundingMode.HALF_EVEN;
import static java.math.RoundingMode.HALF_UP;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import java.math.RoundingMode;
/**
* A class for arithmetic on values of type {@code int}. Where possible, methods are defined and
* named analogously to their {@code BigInteger} counterparts.
*
* <p>The implementations of many methods in this class are based on material from Henry S. Warren,
* Jr.'s <i>Hacker's Delight</i>, (Addison Wesley, 2002).
*
* <p>Similar functionality for {@code long} and for {@link BigInteger} can be found in
* {@link LongMath} and {@link BigIntegerMath} respectively. For other common operations on
* {@code int} values, see {@link com.google.common.primitives.Ints}.
*
* @author Louis Wasserman
* @since 11.0
*/
@GwtCompatible(emulated = true)
public final class IntMath {
// NOTE: Whenever both tests are cheap and functional, it's faster to use &, | instead of &&, ||
/**
* Returns {@code true} if {@code x} represents a power of two.
*
* <p>This differs from {@code Integer.bitCount(x) == 1}, because
* {@code Integer.bitCount(Integer.MIN_VALUE) == 1}, but {@link Integer#MIN_VALUE} is not a power
* of two.
*/
public static boolean isPowerOfTwo(int x) {
return x > 0 & (x & (x - 1)) == 0;
}
/**
* Returns 1 if {@code x < y} as unsigned integers, and 0 otherwise. Assumes that x - y fits into
* a signed int. The implementation is branch-free, and benchmarks suggest it is measurably (if
* narrowly) faster than the straightforward ternary expression.
*/
@VisibleForTesting
static int lessThanBranchFree(int x, int y) {
// The double negation is optimized away by normal Java, but is necessary for GWT
// to make sure bit twiddling works as expected.
return ~~(x - y) >>> (Integer.SIZE - 1);
}
/**
* Returns the base-2 logarithm of {@code x}, rounded according to the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x <= 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and {@code x}
* is not a power of two
*/
@SuppressWarnings("fallthrough")
// TODO(kevinb): remove after this warning is disabled globally
public static int log2(int x, RoundingMode mode) {
checkPositive("x", x);
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(isPowerOfTwo(x));
// fall through
case DOWN:
case FLOOR:
return (Integer.SIZE - 1) - Integer.numberOfLeadingZeros(x);
case UP:
case CEILING:
return Integer.SIZE - Integer.numberOfLeadingZeros(x - 1);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
// Since sqrt(2) is irrational, log2(x) - logFloor cannot be exactly 0.5
int leadingZeros = Integer.numberOfLeadingZeros(x);
int cmp = MAX_POWER_OF_SQRT2_UNSIGNED >>> leadingZeros;
// floor(2^(logFloor + 0.5))
int logFloor = (Integer.SIZE - 1) - leadingZeros;
return logFloor + lessThanBranchFree(cmp, x);
default:
throw new AssertionError();
}
}
/** The biggest half power of two that can fit in an unsigned int. */
@VisibleForTesting static final int MAX_POWER_OF_SQRT2_UNSIGNED = 0xB504F333;
private static int log10Floor(int x) {
/*
* Based on Hacker's Delight Fig. 11-5, the two-table-lookup, branch-free implementation.
*
* The key idea is that based on the number of leading zeros (equivalently, floor(log2(x))),
* we can narrow the possible floor(log10(x)) values to two. For example, if floor(log2(x))
* is 6, then 64 <= x < 128, so floor(log10(x)) is either 1 or 2.
*/
int y = maxLog10ForLeadingZeros[Integer.numberOfLeadingZeros(x)];
/*
* y is the higher of the two possible values of floor(log10(x)). If x < 10^y, then we want the
* lower of the two possible values, or y - 1, otherwise, we want y.
*/
return y - lessThanBranchFree(x, powersOf10[y]);
}
// maxLog10ForLeadingZeros[i] == floor(log10(2^(Long.SIZE - i)))
@VisibleForTesting static final byte[] maxLog10ForLeadingZeros = {9, 9, 9, 8, 8, 8,
7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0};
@VisibleForTesting static final int[] powersOf10 = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
// halfPowersOf10[i] = largest int less than 10^(i + 0.5)
@VisibleForTesting static final int[] halfPowersOf10 =
{3, 31, 316, 3162, 31622, 316227, 3162277, 31622776, 316227766, Integer.MAX_VALUE};
private static int sqrtFloor(int x) {
// There is no loss of precision in converting an int to a double, according to
// http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.2
return (int) Math.sqrt(x);
}
/**
* Returns the result of dividing {@code p} by {@code q}, rounding using the specified
* {@code RoundingMode}.
*
* @throws ArithmeticException if {@code q == 0}, or if {@code mode == UNNECESSARY} and {@code a}
* is not an integer multiple of {@code b}
*/
@SuppressWarnings("fallthrough")
public static int divide(int p, int q, RoundingMode mode) {
checkNotNull(mode);
if (q == 0) {
throw new ArithmeticException("/ by zero"); // for GWT
}
int div = p / q;
int rem = p - q * div; // equal to p % q
if (rem == 0) {
return div;
}
/*
* Normal Java division rounds towards 0, consistently with RoundingMode.DOWN. We just have to
* deal with the cases where rounding towards 0 is wrong, which typically depends on the sign of
* p / q.
*
* signum is 1 if p and q are both nonnegative or both negative, and -1 otherwise.
*/
int signum = 1 | ((p ^ q) >> (Integer.SIZE - 1));
boolean increment;
switch (mode) {
case UNNECESSARY:
checkRoundingUnnecessary(rem == 0);
// fall through
case DOWN:
increment = false;
break;
case UP:
increment = true;
break;
case CEILING:
increment = signum > 0;
break;
case FLOOR:
increment = signum < 0;
break;
case HALF_EVEN:
case HALF_DOWN:
case HALF_UP:
int absRem = abs(rem);
int cmpRemToHalfDivisor = absRem - (abs(q) - absRem);
// subtracting two nonnegative ints can't overflow
// cmpRemToHalfDivisor has the same sign as compare(abs(rem), abs(q) / 2).
if (cmpRemToHalfDivisor == 0) { // exactly on the half mark
increment = (mode == HALF_UP || (mode == HALF_EVEN & (div & 1) != 0));
} else {
increment = cmpRemToHalfDivisor > 0; // closer to the UP value
}
break;
default:
throw new AssertionError();
}
return increment ? div + signum : div;
}
/**
* Returns {@code x mod m}, a non-negative value less than {@code m}.
* This differs from {@code x % m}, which might be negative.
*
* <p>For example:<pre> {@code
*
* mod(7, 4) == 3
* mod(-7, 4) == 1
* mod(-1, 4) == 3
* mod(-8, 4) == 0
* mod(8, 4) == 0}</pre>
*
* @throws ArithmeticException if {@code m <= 0}
* @see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17.3">
* Remainder Operator</a>
*/
public static int mod(int x, int m) {
if (m <= 0) {
throw new ArithmeticException("Modulus " + m + " must be > 0");
}
int result = x % m;
return (result >= 0) ? result : result + m;
}
/**
* Returns the greatest common divisor of {@code a, b}. Returns {@code 0} if
* {@code a == 0 && b == 0}.
*
* @throws IllegalArgumentException if {@code a < 0} or {@code b < 0}
*/
public static int gcd(int a, int b) {
/*
* The reason we require both arguments to be >= 0 is because otherwise, what do you return on
* gcd(0, Integer.MIN_VALUE)? BigInteger.gcd would return positive 2^31, but positive 2^31
* isn't an int.
*/
checkNonNegative("a", a);
checkNonNegative("b", b);
if (a == 0) {
// 0 % b == 0, so b divides a, but the converse doesn't hold.
// BigInteger.gcd is consistent with this decision.
return b;
} else if (b == 0) {
return a; // similar logic
}
/*
* Uses the binary GCD algorithm; see http://en.wikipedia.org/wiki/Binary_GCD_algorithm.
* This is >40% faster than the Euclidean algorithm in benchmarks.
*/
int aTwos = Integer.numberOfTrailingZeros(a);
a >>= aTwos; // divide out all 2s
int bTwos = Integer.numberOfTrailingZeros(b);
b >>= bTwos; // divide out all 2s
while (a != b) { // both a, b are odd
// The key to the binary GCD algorithm is as follows:
// Both a and b are odd. Assume a > b; then gcd(a - b, b) = gcd(a, b).
// But in gcd(a - b, b), a - b is even and b is odd, so we can divide out powers of two.
// We bend over backwards to avoid branching, adapting a technique from
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
int delta = a - b; // can't overflow, since a and b are nonnegative
int minDeltaOrZero = delta & (delta >> (Integer.SIZE - 1));
// equivalent to Math.min(delta, 0)
a = delta - minDeltaOrZero - minDeltaOrZero; // sets a to Math.abs(a - b)
// a is now nonnegative and even
b += minDeltaOrZero; // sets b to min(old a, b)
a >>= Integer.numberOfTrailingZeros(a); // divide out all 2s, since 2 doesn't divide b
}
return a << min(aTwos, bTwos);
}
/**
* Returns the sum of {@code a} and {@code b}, provided it does not overflow.
*
* @throws ArithmeticException if {@code a + b} overflows in signed {@code int} arithmetic
*/
public static int checkedAdd(int a, int b) {
long result = (long) a + b;
checkNoOverflow(result == (int) result);
return (int) result;
}
/**
* Returns the difference of {@code a} and {@code b}, provided it does not overflow.
*
* @throws ArithmeticException if {@code a - b} overflows in signed {@code int} arithmetic
*/
public static int checkedSubtract(int a, int b) {
long result = (long) a - b;
checkNoOverflow(result == (int) result);
return (int) result;
}
/**
* Returns the product of {@code a} and {@code b}, provided it does not overflow.
*
* @throws ArithmeticException if {@code a * b} overflows in signed {@code int} arithmetic
*/
public static int checkedMultiply(int a, int b) {
long result = (long) a * b;
checkNoOverflow(result == (int) result);
return (int) result;
}
/**
* Returns the {@code b} to the {@code k}th power, provided it does not overflow.
*
* <p>{@link #pow} may be faster, but does not check for overflow.
*
* @throws ArithmeticException if {@code b} to the {@code k}th power overflows in signed
* {@code int} arithmetic
*/
public static int checkedPow(int b, int k) {
checkNonNegative("exponent", k);
switch (b) {
case 0:
return (k == 0) ? 1 : 0;
case 1:
return 1;
case (-1):
return ((k & 1) == 0) ? 1 : -1;
case 2:
checkNoOverflow(k < Integer.SIZE - 1);
return 1 << k;
case (-2):
checkNoOverflow(k < Integer.SIZE);
return ((k & 1) == 0) ? 1 << k : -1 << k;
default:
// continue below to handle the general case
}
int accum = 1;
while (true) {
switch (k) {
case 0:
return accum;
case 1:
return checkedMultiply(accum, b);
default:
if ((k & 1) != 0) {
accum = checkedMultiply(accum, b);
}
k >>= 1;
if (k > 0) {
checkNoOverflow(-FLOOR_SQRT_MAX_INT <= b & b <= FLOOR_SQRT_MAX_INT);
b *= b;
}
}
}
}
@VisibleForTesting static final int FLOOR_SQRT_MAX_INT = 46340;
/**
* Returns {@code n!}, that is, the product of the first {@code n} positive
* integers, {@code 1} if {@code n == 0}, or {@link Integer#MAX_VALUE} if the
* result does not fit in a {@code int}.
*
* @throws IllegalArgumentException if {@code n < 0}
*/
public static int factorial(int n) {
checkNonNegative("n", n);
return (n < factorials.length) ? factorials[n] : Integer.MAX_VALUE;
}
private static final int[] factorials = {
1,
1,
1 * 2,
1 * 2 * 3,
1 * 2 * 3 * 4,
1 * 2 * 3 * 4 * 5,
1 * 2 * 3 * 4 * 5 * 6,
1 * 2 * 3 * 4 * 5 * 6 * 7,
1 * 2 * 3 * 4 * 5 * 6 * 7 * 8,
1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9,
1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10,
1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11,
1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12};
// binomial(biggestBinomials[k], k) fits in an int, but not binomial(biggestBinomials[k]+1,k).
@VisibleForTesting static int[] biggestBinomials = {
Integer.MAX_VALUE,
Integer.MAX_VALUE,
65536,
2345,
477,
193,
110,
75,
58,
49,
43,
39,
37,
35,
34,
34,
33
};
/**
* Returns the arithmetic mean of {@code x} and {@code y}, rounded towards
* negative infinity. This method is overflow resilient.
*
* @since 14.0
*/
public static int mean(int x, int y) {
// Efficient method for computing the arithmetic mean.
// The alternative (x + y) / 2 fails for large values.
// The alternative (x + y) >>> 1 fails for negative values.
return (x & y) + ((x ^ y) >> 1);
}
private IntMath() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/math/super/com/google/common/math/IntMath.java | Java | asf20 | 14,763 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static java.lang.Float.NEGATIVE_INFINITY;
import static java.lang.Float.POSITIVE_INFINITY;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Converter;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
/**
* Static utility methods pertaining to {@code float} primitives, that are not
* already found in either {@link Float} or {@link Arrays}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained">
* primitive utilities</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Floats {
private Floats() {}
/**
* The number of bytes required to represent a primitive {@code float}
* value.
*
* @since 10.0
*/
public static final int BYTES = Float.SIZE / Byte.SIZE;
/**
* Returns a hash code for {@code value}; equal to the result of invoking
* {@code ((Float) value).hashCode()}.
*
* @param value a primitive {@code float} value
* @return a hash code for the value
*/
public static int hashCode(float value) {
// TODO(kevinb): is there a better way, that's still gwt-safe?
return ((Float) value).hashCode();
}
/**
* Compares the two specified {@code float} values using {@link
* Float#compare(float, float)}. You may prefer to invoke that method
* directly; this method exists only for consistency with the other utilities
* in this package.
*
* <p><b>Note:</b> this method simply delegates to the JDK method {@link
* Float#compare}. It is provided for consistency with the other primitive
* types, whose compare methods were not added to the JDK until JDK 7.
*
* @param a the first {@code float} to compare
* @param b the second {@code float} to compare
* @return the result of invoking {@link Float#compare(float, float)}
*/
public static int compare(float a, float b) {
return Float.compare(a, b);
}
/**
* Returns {@code true} if {@code value} represents a real number. This is
* equivalent to, but not necessarily implemented as,
* {@code !(Float.isInfinite(value) || Float.isNaN(value))}.
*
* @since 10.0
*/
public static boolean isFinite(float value) {
return NEGATIVE_INFINITY < value & value < POSITIVE_INFINITY;
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in
* {@code array}. Note that this always returns {@code false} when {@code
* target} is {@code NaN}.
*
* @param array an array of {@code float} values, possibly empty
* @param target a primitive {@code float} value
* @return {@code true} if {@code array[i] == target} for some value of {@code
* i}
*/
public static boolean contains(float[] array, float target) {
for (float value : array) {
if (value == target) {
return true;
}
}
return false;
}
/**
* Returns the index of the first appearance of the value {@code target} in
* {@code array}. Note that this always returns {@code -1} when {@code target}
* is {@code NaN}.
*
* @param array an array of {@code float} values, possibly empty
* @param target a primitive {@code float} value
* @return the least index {@code i} for which {@code array[i] == target}, or
* {@code -1} if no such index exists.
*/
public static int indexOf(float[] array, float target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(
float[] array, float target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the start position of the first occurrence of the specified {@code
* target} within {@code array}, or {@code -1} if there is no such occurrence.
*
* <p>More formally, returns the lowest index {@code i} such that {@code
* java.util.Arrays.copyOfRange(array, i, i + target.length)} contains exactly
* the same elements as {@code target}.
*
* <p>Note that this always returns {@code -1} when {@code target} contains
* {@code NaN}.
*
* @param array the array to search for the sequence {@code target}
* @param target the array to search for as a sub-sequence of {@code array}
*/
public static int indexOf(float[] array, float[] target) {
checkNotNull(array, "array");
checkNotNull(target, "target");
if (target.length == 0) {
return 0;
}
outer:
for (int i = 0; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
/**
* Returns the index of the last appearance of the value {@code target} in
* {@code array}. Note that this always returns {@code -1} when {@code target}
* is {@code NaN}.
*
* @param array an array of {@code float} values, possibly empty
* @param target a primitive {@code float} value
* @return the greatest index {@code i} for which {@code array[i] == target},
* or {@code -1} if no such index exists.
*/
public static int lastIndexOf(float[] array, float target) {
return lastIndexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int lastIndexOf(
float[] array, float target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the least value present in {@code array}, using the same rules of
* comparison as {@link Math#min(float, float)}.
*
* @param array a <i>nonempty</i> array of {@code float} values
* @return the value present in {@code array} that is less than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static float min(float... array) {
checkArgument(array.length > 0);
float min = array[0];
for (int i = 1; i < array.length; i++) {
min = Math.min(min, array[i]);
}
return min;
}
/**
* Returns the greatest value present in {@code array}, using the same rules
* of comparison as {@link Math#min(float, float)}.
*
* @param array a <i>nonempty</i> array of {@code float} values
* @return the value present in {@code array} that is greater than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static float max(float... array) {
checkArgument(array.length > 0);
float max = array[0];
for (int i = 1; i < array.length; i++) {
max = Math.max(max, array[i]);
}
return max;
}
/**
* Returns the values from each provided array combined into a single array.
* For example, {@code concat(new float[] {a, b}, new float[] {}, new
* float[] {c}} returns the array {@code {a, b, c}}.
*
* @param arrays zero or more {@code float} arrays
* @return a single array containing all the values from the source arrays, in
* order
*/
public static float[] concat(float[]... arrays) {
int length = 0;
for (float[] array : arrays) {
length += array.length;
}
float[] result = new float[length];
int pos = 0;
for (float[] array : arrays) {
System.arraycopy(array, 0, result, pos, array.length);
pos += array.length;
}
return result;
}
private static final class FloatConverter
extends Converter<String, Float> implements Serializable {
static final FloatConverter INSTANCE = new FloatConverter();
@Override
protected Float doForward(String value) {
return Float.valueOf(value);
}
@Override
protected String doBackward(Float value) {
return value.toString();
}
@Override
public String toString() {
return "Floats.stringConverter()";
}
private Object readResolve() {
return INSTANCE;
}
private static final long serialVersionUID = 1;
}
/**
* Returns a serializable converter object that converts between strings and
* floats using {@link Float#valueOf} and {@link Float#toString()}.
*
* @since 16.0
*/
@Beta
public static Converter<String, Float> stringConverter() {
return FloatConverter.INSTANCE;
}
/**
* Returns an array containing the same values as {@code array}, but
* guaranteed to be of a specified minimum length. If {@code array} already
* has a length of at least {@code minLength}, it is returned directly.
* Otherwise, a new array of size {@code minLength + padding} is returned,
* containing the values of {@code array}, and zeroes in the remaining places.
*
* @param array the source array
* @param minLength the minimum length the returned array must guarantee
* @param padding an extra amount to "grow" the array by if growth is
* necessary
* @throws IllegalArgumentException if {@code minLength} or {@code padding} is
* negative
* @return an array containing the values of {@code array}, with guaranteed
* minimum length {@code minLength}
*/
public static float[] ensureCapacity(
float[] array, int minLength, int padding) {
checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
checkArgument(padding >= 0, "Invalid padding: %s", padding);
return (array.length < minLength)
? copyOf(array, minLength + padding)
: array;
}
// Arrays.copyOf() requires Java 6
private static float[] copyOf(float[] original, int length) {
float[] copy = new float[length];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, length));
return copy;
}
/**
* Returns a string containing the supplied {@code float} values, converted
* to strings as specified by {@link Float#toString(float)}, and separated by
* {@code separator}. For example, {@code join("-", 1.0f, 2.0f, 3.0f)}
* returns the string {@code "1.0-2.0-3.0"}.
*
* <p>Note that {@link Float#toString(float)} formats {@code float}
* differently in GWT. In the previous example, it returns the string {@code
* "1-2-3"}.
*
* @param separator the text that should appear between consecutive values in
* the resulting string (but not at the start or end)
* @param array an array of {@code float} values, possibly empty
*/
public static String join(String separator, float... array) {
checkNotNull(separator);
if (array.length == 0) {
return "";
}
// For pre-sizing a builder, just get the right order of magnitude
StringBuilder builder = new StringBuilder(array.length * 12);
builder.append(array[0]);
for (int i = 1; i < array.length; i++) {
builder.append(separator).append(array[i]);
}
return builder.toString();
}
/**
* Returns a comparator that compares two {@code float} arrays
* lexicographically. That is, it compares, using {@link
* #compare(float, float)}), the first pair of values that follow any
* common prefix, or when one array is a prefix of the other, treats the
* shorter array as the lesser. For example, {@code [] < [1.0f] < [1.0f, 2.0f]
* < [2.0f]}.
*
* <p>The returned comparator is inconsistent with {@link
* Object#equals(Object)} (since arrays support only identity equality), but
* it is consistent with {@link Arrays#equals(float[], float[])}.
*
* @see <a href="http://en.wikipedia.org/wiki/Lexicographical_order">
* Lexicographical order article at Wikipedia</a>
* @since 2.0
*/
public static Comparator<float[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
private enum LexicographicalComparator implements Comparator<float[]> {
INSTANCE;
@Override
public int compare(float[] left, float[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Floats.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
}
/**
* Returns an array containing each value of {@code collection}, converted to
* a {@code float} value in the manner of {@link Number#floatValue}.
*
* <p>Elements are copied from the argument collection as if by {@code
* collection.toArray()}. Calling this method is as thread-safe as calling
* that method.
*
* @param collection a collection of {@code Number} instances
* @return an array containing the same values as {@code collection}, in the
* same order, converted to primitives
* @throws NullPointerException if {@code collection} or any of its elements
* is null
* @since 1.0 (parameter was {@code Collection<Float>} before 12.0)
*/
public static float[] toArray(Collection<? extends Number> collection) {
if (collection instanceof FloatArrayAsList) {
return ((FloatArrayAsList) collection).toFloatArray();
}
Object[] boxedArray = collection.toArray();
int len = boxedArray.length;
float[] array = new float[len];
for (int i = 0; i < len; i++) {
// checkNotNull for GWT (do not optimize)
array[i] = ((Number) checkNotNull(boxedArray[i])).floatValue();
}
return array;
}
/**
* Returns a fixed-size list backed by the specified array, similar to {@link
* Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)},
* but any attempt to set a value to {@code null} will result in a {@link
* NullPointerException}.
*
* <p>The returned list maintains the values, but not the identities, of
* {@code Float} objects written to or read from it. For example, whether
* {@code list.get(0) == list.get(0)} is true for the returned list is
* unspecified.
*
* <p>The returned list may have unexpected behavior if it contains {@code
* NaN}, or if {@code NaN} is used as a parameter to any of its methods.
*
* @param backingArray the array to back the list
* @return a list view of the array
*/
public static List<Float> asList(float... backingArray) {
if (backingArray.length == 0) {
return Collections.emptyList();
}
return new FloatArrayAsList(backingArray);
}
@GwtCompatible
private static class FloatArrayAsList extends AbstractList<Float>
implements RandomAccess, Serializable {
final float[] array;
final int start;
final int end;
FloatArrayAsList(float[] array) {
this(array, 0, array.length);
}
FloatArrayAsList(float[] array, int start, int end) {
this.array = array;
this.start = start;
this.end = end;
}
@Override public int size() {
return end - start;
}
@Override public boolean isEmpty() {
return false;
}
@Override public Float get(int index) {
checkElementIndex(index, size());
return array[start + index];
}
@Override public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Float)
&& Floats.indexOf(array, (Float) target, start, end) != -1;
}
@Override public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Float) {
int i = Floats.indexOf(array, (Float) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Float) {
int i = Floats.lastIndexOf(array, (Float) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public Float set(int index, Float element) {
checkElementIndex(index, size());
float oldValue = array[start + index];
// checkNotNull for GWT (do not optimize)
array[start + index] = checkNotNull(element);
return oldValue;
}
@Override public List<Float> subList(int fromIndex, int toIndex) {
int size = size();
checkPositionIndexes(fromIndex, toIndex, size);
if (fromIndex == toIndex) {
return Collections.emptyList();
}
return new FloatArrayAsList(array, start + fromIndex, start + toIndex);
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof FloatArrayAsList) {
FloatArrayAsList that = (FloatArrayAsList) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (array[start + i] != that.array[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Floats.hashCode(array[i]);
}
return result;
}
@Override public String toString() {
StringBuilder builder = new StringBuilder(size() * 12);
builder.append('[').append(array[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(array[i]);
}
return builder.append(']').toString();
}
float[] toFloatArray() {
// Arrays.copyOfRange() is not available under GWT
int size = size();
float[] result = new float[size];
System.arraycopy(array, start, result, 0, size);
return result;
}
private static final long serialVersionUID = 0;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/Floats.java | Java | asf20 | 18,953 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Converter;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
/**
* Static utility methods pertaining to {@code int} primitives, that are not
* already found in either {@link Integer} or {@link Arrays}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained">
* primitive utilities</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Ints {
private Ints() {}
/**
* The number of bytes required to represent a primitive {@code int}
* value.
*/
public static final int BYTES = Integer.SIZE / Byte.SIZE;
/**
* The largest power of two that can be represented as an {@code int}.
*
* @since 10.0
*/
public static final int MAX_POWER_OF_TWO = 1 << (Integer.SIZE - 2);
/**
* Returns a hash code for {@code value}; equal to the result of invoking
* {@code ((Integer) value).hashCode()}.
*
* @param value a primitive {@code int} value
* @return a hash code for the value
*/
public static int hashCode(int value) {
return value;
}
/**
* Returns the {@code int} value that is equal to {@code value}, if possible.
*
* @param value any value in the range of the {@code int} type
* @return the {@code int} value that equals {@code value}
* @throws IllegalArgumentException if {@code value} is greater than {@link
* Integer#MAX_VALUE} or less than {@link Integer#MIN_VALUE}
*/
public static int checkedCast(long value) {
int result = (int) value;
if (result != value) {
// don't use checkArgument here, to avoid boxing
throw new IllegalArgumentException("Out of range: " + value);
}
return result;
}
/**
* Returns the {@code int} nearest in value to {@code value}.
*
* @param value any {@code long} value
* @return the same value cast to {@code int} if it is in the range of the
* {@code int} type, {@link Integer#MAX_VALUE} if it is too large,
* or {@link Integer#MIN_VALUE} if it is too small
*/
public static int saturatedCast(long value) {
if (value > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
}
if (value < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
}
return (int) value;
}
/**
* Compares the two specified {@code int} values. The sign of the value
* returned is the same as that of {@code ((Integer) a).compareTo(b)}.
*
* <p><b>Note:</b> projects using JDK 7 or later should use the equivalent
* {@link Integer#compare} method instead.
*
* @param a the first {@code int} to compare
* @param b the second {@code int} to compare
* @return a negative value if {@code a} is less than {@code b}; a positive
* value if {@code a} is greater than {@code b}; or zero if they are equal
*/
public static int compare(int a, int b) {
return (a < b) ? -1 : ((a > b) ? 1 : 0);
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in
* {@code array}.
*
* @param array an array of {@code int} values, possibly empty
* @param target a primitive {@code int} value
* @return {@code true} if {@code array[i] == target} for some value of {@code
* i}
*/
public static boolean contains(int[] array, int target) {
for (int value : array) {
if (value == target) {
return true;
}
}
return false;
}
/**
* Returns the index of the first appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code int} values, possibly empty
* @param target a primitive {@code int} value
* @return the least index {@code i} for which {@code array[i] == target}, or
* {@code -1} if no such index exists.
*/
public static int indexOf(int[] array, int target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(
int[] array, int target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the start position of the first occurrence of the specified {@code
* target} within {@code array}, or {@code -1} if there is no such occurrence.
*
* <p>More formally, returns the lowest index {@code i} such that {@code
* java.util.Arrays.copyOfRange(array, i, i + target.length)} contains exactly
* the same elements as {@code target}.
*
* @param array the array to search for the sequence {@code target}
* @param target the array to search for as a sub-sequence of {@code array}
*/
public static int indexOf(int[] array, int[] target) {
checkNotNull(array, "array");
checkNotNull(target, "target");
if (target.length == 0) {
return 0;
}
outer:
for (int i = 0; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
/**
* Returns the index of the last appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code int} values, possibly empty
* @param target a primitive {@code int} value
* @return the greatest index {@code i} for which {@code array[i] == target},
* or {@code -1} if no such index exists.
*/
public static int lastIndexOf(int[] array, int target) {
return lastIndexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int lastIndexOf(
int[] array, int target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the least value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code int} values
* @return the value present in {@code array} that is less than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static int min(int... array) {
checkArgument(array.length > 0);
int min = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
/**
* Returns the greatest value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code int} values
* @return the value present in {@code array} that is greater than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static int max(int... array) {
checkArgument(array.length > 0);
int max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
/**
* Returns the values from each provided array combined into a single array.
* For example, {@code concat(new int[] {a, b}, new int[] {}, new
* int[] {c}} returns the array {@code {a, b, c}}.
*
* @param arrays zero or more {@code int} arrays
* @return a single array containing all the values from the source arrays, in
* order
*/
public static int[] concat(int[]... arrays) {
int length = 0;
for (int[] array : arrays) {
length += array.length;
}
int[] result = new int[length];
int pos = 0;
for (int[] array : arrays) {
System.arraycopy(array, 0, result, pos, array.length);
pos += array.length;
}
return result;
}
private static final class IntConverter
extends Converter<String, Integer> implements Serializable {
static final IntConverter INSTANCE = new IntConverter();
@Override
protected Integer doForward(String value) {
return Integer.decode(value);
}
@Override
protected String doBackward(Integer value) {
return value.toString();
}
@Override
public String toString() {
return "Ints.stringConverter()";
}
private Object readResolve() {
return INSTANCE;
}
private static final long serialVersionUID = 1;
}
/**
* Returns a serializable converter object that converts between strings and
* integers using {@link Integer#decode} and {@link Integer#toString()}.
*
* @since 16.0
*/
@Beta
public static Converter<String, Integer> stringConverter() {
return IntConverter.INSTANCE;
}
/**
* Returns an array containing the same values as {@code array}, but
* guaranteed to be of a specified minimum length. If {@code array} already
* has a length of at least {@code minLength}, it is returned directly.
* Otherwise, a new array of size {@code minLength + padding} is returned,
* containing the values of {@code array}, and zeroes in the remaining places.
*
* @param array the source array
* @param minLength the minimum length the returned array must guarantee
* @param padding an extra amount to "grow" the array by if growth is
* necessary
* @throws IllegalArgumentException if {@code minLength} or {@code padding} is
* negative
* @return an array containing the values of {@code array}, with guaranteed
* minimum length {@code minLength}
*/
public static int[] ensureCapacity(
int[] array, int minLength, int padding) {
checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
checkArgument(padding >= 0, "Invalid padding: %s", padding);
return (array.length < minLength)
? copyOf(array, minLength + padding)
: array;
}
// Arrays.copyOf() requires Java 6
private static int[] copyOf(int[] original, int length) {
int[] copy = new int[length];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, length));
return copy;
}
/**
* Returns a string containing the supplied {@code int} values separated
* by {@code separator}. For example, {@code join("-", 1, 2, 3)} returns
* the string {@code "1-2-3"}.
*
* @param separator the text that should appear between consecutive values in
* the resulting string (but not at the start or end)
* @param array an array of {@code int} values, possibly empty
*/
public static String join(String separator, int... array) {
checkNotNull(separator);
if (array.length == 0) {
return "";
}
// For pre-sizing a builder, just get the right order of magnitude
StringBuilder builder = new StringBuilder(array.length * 5);
builder.append(array[0]);
for (int i = 1; i < array.length; i++) {
builder.append(separator).append(array[i]);
}
return builder.toString();
}
/**
* Returns a comparator that compares two {@code int} arrays
* lexicographically. That is, it compares, using {@link
* #compare(int, int)}), the first pair of values that follow any
* common prefix, or when one array is a prefix of the other, treats the
* shorter array as the lesser. For example, {@code [] < [1] < [1, 2] < [2]}.
*
* <p>The returned comparator is inconsistent with {@link
* Object#equals(Object)} (since arrays support only identity equality), but
* it is consistent with {@link Arrays#equals(int[], int[])}.
*
* @see <a href="http://en.wikipedia.org/wiki/Lexicographical_order">
* Lexicographical order article at Wikipedia</a>
* @since 2.0
*/
public static Comparator<int[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
private enum LexicographicalComparator implements Comparator<int[]> {
INSTANCE;
@Override
public int compare(int[] left, int[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Ints.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
}
/**
* Returns an array containing each value of {@code collection}, converted to
* a {@code int} value in the manner of {@link Number#intValue}.
*
* <p>Elements are copied from the argument collection as if by {@code
* collection.toArray()}. Calling this method is as thread-safe as calling
* that method.
*
* @param collection a collection of {@code Number} instances
* @return an array containing the same values as {@code collection}, in the
* same order, converted to primitives
* @throws NullPointerException if {@code collection} or any of its elements
* is null
* @since 1.0 (parameter was {@code Collection<Integer>} before 12.0)
*/
public static int[] toArray(Collection<? extends Number> collection) {
if (collection instanceof IntArrayAsList) {
return ((IntArrayAsList) collection).toIntArray();
}
Object[] boxedArray = collection.toArray();
int len = boxedArray.length;
int[] array = new int[len];
for (int i = 0; i < len; i++) {
// checkNotNull for GWT (do not optimize)
array[i] = ((Number) checkNotNull(boxedArray[i])).intValue();
}
return array;
}
/**
* Returns a fixed-size list backed by the specified array, similar to {@link
* Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)},
* but any attempt to set a value to {@code null} will result in a {@link
* NullPointerException}.
*
* <p>The returned list maintains the values, but not the identities, of
* {@code Integer} objects written to or read from it. For example, whether
* {@code list.get(0) == list.get(0)} is true for the returned list is
* unspecified.
*
* @param backingArray the array to back the list
* @return a list view of the array
*/
public static List<Integer> asList(int... backingArray) {
if (backingArray.length == 0) {
return Collections.emptyList();
}
return new IntArrayAsList(backingArray);
}
@GwtCompatible
private static class IntArrayAsList extends AbstractList<Integer>
implements RandomAccess, Serializable {
final int[] array;
final int start;
final int end;
IntArrayAsList(int[] array) {
this(array, 0, array.length);
}
IntArrayAsList(int[] array, int start, int end) {
this.array = array;
this.start = start;
this.end = end;
}
@Override public int size() {
return end - start;
}
@Override public boolean isEmpty() {
return false;
}
@Override public Integer get(int index) {
checkElementIndex(index, size());
return array[start + index];
}
@Override public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Integer)
&& Ints.indexOf(array, (Integer) target, start, end) != -1;
}
@Override public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Integer) {
int i = Ints.indexOf(array, (Integer) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Integer) {
int i = Ints.lastIndexOf(array, (Integer) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public Integer set(int index, Integer element) {
checkElementIndex(index, size());
int oldValue = array[start + index];
// checkNotNull for GWT (do not optimize)
array[start + index] = checkNotNull(element);
return oldValue;
}
@Override public List<Integer> subList(int fromIndex, int toIndex) {
int size = size();
checkPositionIndexes(fromIndex, toIndex, size);
if (fromIndex == toIndex) {
return Collections.emptyList();
}
return new IntArrayAsList(array, start + fromIndex, start + toIndex);
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof IntArrayAsList) {
IntArrayAsList that = (IntArrayAsList) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (array[start + i] != that.array[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Ints.hashCode(array[i]);
}
return result;
}
@Override public String toString() {
StringBuilder builder = new StringBuilder(size() * 5);
builder.append('[').append(array[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(array[i]);
}
return builder.append(']').toString();
}
int[] toIntArray() {
// Arrays.copyOfRange() is not available under GWT
int size = size();
int[] result = new int[size];
System.arraycopy(array, start, result, 0, size);
return result;
}
private static final long serialVersionUID = 0;
}
private static final byte[] asciiDigits = new byte[128];
static {
Arrays.fill(asciiDigits, (byte) -1);
for (int i = 0; i <= 9; i++) {
asciiDigits['0' + i] = (byte) i;
}
for (int i = 0; i <= 26; i++) {
asciiDigits['A' + i] = (byte) (10 + i);
asciiDigits['a' + i] = (byte) (10 + i);
}
}
private static int digit(char c) {
return (c < 128) ? asciiDigits[c] : -1;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/Ints.java | Java | asf20 | 19,053 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import com.google.common.annotations.GwtCompatible;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
/**
* Static utility methods pertaining to {@code char} primitives, that are not
* already found in either {@link Character} or {@link Arrays}.
*
* <p>All the operations in this class treat {@code char} values strictly
* numerically; they are neither Unicode-aware nor locale-dependent.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained">
* primitive utilities</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Chars {
private Chars() {}
/**
* The number of bytes required to represent a primitive {@code char}
* value.
*/
public static final int BYTES = Character.SIZE / Byte.SIZE;
/**
* Returns a hash code for {@code value}; equal to the result of invoking
* {@code ((Character) value).hashCode()}.
*
* @param value a primitive {@code char} value
* @return a hash code for the value
*/
public static int hashCode(char value) {
return value;
}
/**
* Returns the {@code char} value that is equal to {@code value}, if possible.
*
* @param value any value in the range of the {@code char} type
* @return the {@code char} value that equals {@code value}
* @throws IllegalArgumentException if {@code value} is greater than {@link
* Character#MAX_VALUE} or less than {@link Character#MIN_VALUE}
*/
public static char checkedCast(long value) {
char result = (char) value;
if (result != value) {
// don't use checkArgument here, to avoid boxing
throw new IllegalArgumentException("Out of range: " + value);
}
return result;
}
/**
* Returns the {@code char} nearest in value to {@code value}.
*
* @param value any {@code long} value
* @return the same value cast to {@code char} if it is in the range of the
* {@code char} type, {@link Character#MAX_VALUE} if it is too large,
* or {@link Character#MIN_VALUE} if it is too small
*/
public static char saturatedCast(long value) {
if (value > Character.MAX_VALUE) {
return Character.MAX_VALUE;
}
if (value < Character.MIN_VALUE) {
return Character.MIN_VALUE;
}
return (char) value;
}
/**
* Compares the two specified {@code char} values. The sign of the value
* returned is the same as that of {@code ((Character) a).compareTo(b)}.
*
* <p><b>Note:</b> projects using JDK 7 or later should use the equivalent
* {@link Character#compare} method instead.
*
* @param a the first {@code char} to compare
* @param b the second {@code char} to compare
* @return a negative value if {@code a} is less than {@code b}; a positive
* value if {@code a} is greater than {@code b}; or zero if they are equal
*/
public static int compare(char a, char b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in
* {@code array}.
*
* @param array an array of {@code char} values, possibly empty
* @param target a primitive {@code char} value
* @return {@code true} if {@code array[i] == target} for some value of {@code
* i}
*/
public static boolean contains(char[] array, char target) {
for (char value : array) {
if (value == target) {
return true;
}
}
return false;
}
/**
* Returns the index of the first appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code char} values, possibly empty
* @param target a primitive {@code char} value
* @return the least index {@code i} for which {@code array[i] == target}, or
* {@code -1} if no such index exists.
*/
public static int indexOf(char[] array, char target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(
char[] array, char target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the start position of the first occurrence of the specified {@code
* target} within {@code array}, or {@code -1} if there is no such occurrence.
*
* <p>More formally, returns the lowest index {@code i} such that {@code
* java.util.Arrays.copyOfRange(array, i, i + target.length)} contains exactly
* the same elements as {@code target}.
*
* @param array the array to search for the sequence {@code target}
* @param target the array to search for as a sub-sequence of {@code array}
*/
public static int indexOf(char[] array, char[] target) {
checkNotNull(array, "array");
checkNotNull(target, "target");
if (target.length == 0) {
return 0;
}
outer:
for (int i = 0; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
/**
* Returns the index of the last appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code char} values, possibly empty
* @param target a primitive {@code char} value
* @return the greatest index {@code i} for which {@code array[i] == target},
* or {@code -1} if no such index exists.
*/
public static int lastIndexOf(char[] array, char target) {
return lastIndexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int lastIndexOf(
char[] array, char target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the least value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code char} values
* @return the value present in {@code array} that is less than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static char min(char... array) {
checkArgument(array.length > 0);
char min = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
/**
* Returns the greatest value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code char} values
* @return the value present in {@code array} that is greater than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static char max(char... array) {
checkArgument(array.length > 0);
char max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
/**
* Returns the values from each provided array combined into a single array.
* For example, {@code concat(new char[] {a, b}, new char[] {}, new
* char[] {c}} returns the array {@code {a, b, c}}.
*
* @param arrays zero or more {@code char} arrays
* @return a single array containing all the values from the source arrays, in
* order
*/
public static char[] concat(char[]... arrays) {
int length = 0;
for (char[] array : arrays) {
length += array.length;
}
char[] result = new char[length];
int pos = 0;
for (char[] array : arrays) {
System.arraycopy(array, 0, result, pos, array.length);
pos += array.length;
}
return result;
}
/**
* Returns an array containing the same values as {@code array}, but
* guaranteed to be of a specified minimum length. If {@code array} already
* has a length of at least {@code minLength}, it is returned directly.
* Otherwise, a new array of size {@code minLength + padding} is returned,
* containing the values of {@code array}, and zeroes in the remaining places.
*
* @param array the source array
* @param minLength the minimum length the returned array must guarantee
* @param padding an extra amount to "grow" the array by if growth is
* necessary
* @throws IllegalArgumentException if {@code minLength} or {@code padding} is
* negative
* @return an array containing the values of {@code array}, with guaranteed
* minimum length {@code minLength}
*/
public static char[] ensureCapacity(
char[] array, int minLength, int padding) {
checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
checkArgument(padding >= 0, "Invalid padding: %s", padding);
return (array.length < minLength)
? copyOf(array, minLength + padding)
: array;
}
// Arrays.copyOf() requires Java 6
private static char[] copyOf(char[] original, int length) {
char[] copy = new char[length];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, length));
return copy;
}
/**
* Returns a string containing the supplied {@code char} values separated
* by {@code separator}. For example, {@code join("-", '1', '2', '3')} returns
* the string {@code "1-2-3"}.
*
* @param separator the text that should appear between consecutive values in
* the resulting string (but not at the start or end)
* @param array an array of {@code char} values, possibly empty
*/
public static String join(String separator, char... array) {
checkNotNull(separator);
int len = array.length;
if (len == 0) {
return "";
}
StringBuilder builder
= new StringBuilder(len + separator.length() * (len - 1));
builder.append(array[0]);
for (int i = 1; i < len; i++) {
builder.append(separator).append(array[i]);
}
return builder.toString();
}
/**
* Returns a comparator that compares two {@code char} arrays
* lexicographically. That is, it compares, using {@link
* #compare(char, char)}), the first pair of values that follow any
* common prefix, or when one array is a prefix of the other, treats the
* shorter array as the lesser. For example,
* {@code [] < ['a'] < ['a', 'b'] < ['b']}.
*
* <p>The returned comparator is inconsistent with {@link
* Object#equals(Object)} (since arrays support only identity equality), but
* it is consistent with {@link Arrays#equals(char[], char[])}.
*
* @see <a href="http://en.wikipedia.org/wiki/Lexicographical_order">
* Lexicographical order article at Wikipedia</a>
* @since 2.0
*/
public static Comparator<char[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
private enum LexicographicalComparator implements Comparator<char[]> {
INSTANCE;
@Override
public int compare(char[] left, char[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Chars.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
}
/**
* Copies a collection of {@code Character} instances into a new array of
* primitive {@code char} values.
*
* <p>Elements are copied from the argument collection as if by {@code
* collection.toArray()}. Calling this method is as thread-safe as calling
* that method.
*
* @param collection a collection of {@code Character} objects
* @return an array containing the same values as {@code collection}, in the
* same order, converted to primitives
* @throws NullPointerException if {@code collection} or any of its elements
* is null
*/
public static char[] toArray(Collection<Character> collection) {
if (collection instanceof CharArrayAsList) {
return ((CharArrayAsList) collection).toCharArray();
}
Object[] boxedArray = collection.toArray();
int len = boxedArray.length;
char[] array = new char[len];
for (int i = 0; i < len; i++) {
// checkNotNull for GWT (do not optimize)
array[i] = (Character) checkNotNull(boxedArray[i]);
}
return array;
}
/**
* Returns a fixed-size list backed by the specified array, similar to {@link
* Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)},
* but any attempt to set a value to {@code null} will result in a {@link
* NullPointerException}.
*
* <p>The returned list maintains the values, but not the identities, of
* {@code Character} objects written to or read from it. For example, whether
* {@code list.get(0) == list.get(0)} is true for the returned list is
* unspecified.
*
* @param backingArray the array to back the list
* @return a list view of the array
*/
public static List<Character> asList(char... backingArray) {
if (backingArray.length == 0) {
return Collections.emptyList();
}
return new CharArrayAsList(backingArray);
}
@GwtCompatible
private static class CharArrayAsList extends AbstractList<Character>
implements RandomAccess, Serializable {
final char[] array;
final int start;
final int end;
CharArrayAsList(char[] array) {
this(array, 0, array.length);
}
CharArrayAsList(char[] array, int start, int end) {
this.array = array;
this.start = start;
this.end = end;
}
@Override public int size() {
return end - start;
}
@Override public boolean isEmpty() {
return false;
}
@Override public Character get(int index) {
checkElementIndex(index, size());
return array[start + index];
}
@Override public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Character)
&& Chars.indexOf(array, (Character) target, start, end) != -1;
}
@Override public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Character) {
int i = Chars.indexOf(array, (Character) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Character) {
int i = Chars.lastIndexOf(array, (Character) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public Character set(int index, Character element) {
checkElementIndex(index, size());
char oldValue = array[start + index];
// checkNotNull for GWT (do not optimize)
array[start + index] = checkNotNull(element);
return oldValue;
}
@Override public List<Character> subList(int fromIndex, int toIndex) {
int size = size();
checkPositionIndexes(fromIndex, toIndex, size);
if (fromIndex == toIndex) {
return Collections.emptyList();
}
return new CharArrayAsList(array, start + fromIndex, start + toIndex);
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof CharArrayAsList) {
CharArrayAsList that = (CharArrayAsList) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (array[start + i] != that.array[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Chars.hashCode(array[i]);
}
return result;
}
@Override public String toString() {
StringBuilder builder = new StringBuilder(size() * 3);
builder.append('[').append(array[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(array[i]);
}
return builder.append(']').toString();
}
char[] toCharArray() {
// Arrays.copyOfRange() is not available under GWT
int size = size();
char[] result = new char[size];
System.arraycopy(array, start, result, 0, size);
return result;
}
private static final long serialVersionUID = 0;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/Chars.java | Java | asf20 | 17,633 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static java.lang.Double.NEGATIVE_INFINITY;
import static java.lang.Double.POSITIVE_INFINITY;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Converter;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
/**
* Static utility methods pertaining to {@code double} primitives, that are not
* already found in either {@link Double} or {@link Arrays}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained">
* primitive utilities</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Doubles {
private Doubles() {}
/**
* The number of bytes required to represent a primitive {@code double}
* value.
*
* @since 10.0
*/
public static final int BYTES = Double.SIZE / Byte.SIZE;
/**
* Returns a hash code for {@code value}; equal to the result of invoking
* {@code ((Double) value).hashCode()}.
*
* @param value a primitive {@code double} value
* @return a hash code for the value
*/
public static int hashCode(double value) {
return ((Double) value).hashCode();
// TODO(kevinb): do it this way when we can (GWT problem):
// long bits = Double.doubleToLongBits(value);
// return (int) (bits ^ (bits >>> 32));
}
/**
* Compares the two specified {@code double} values. The sign of the value
* returned is the same as that of <code>((Double) a).{@linkplain
* Double#compareTo compareTo}(b)</code>. As with that method, {@code NaN} is
* treated as greater than all other values, and {@code 0.0 > -0.0}.
*
* <p><b>Note:</b> this method simply delegates to the JDK method {@link
* Double#compare}. It is provided for consistency with the other primitive
* types, whose compare methods were not added to the JDK until JDK 7.
*
* @param a the first {@code double} to compare
* @param b the second {@code double} to compare
* @return a negative value if {@code a} is less than {@code b}; a positive
* value if {@code a} is greater than {@code b}; or zero if they are equal
*/
public static int compare(double a, double b) {
return Double.compare(a, b);
}
/**
* Returns {@code true} if {@code value} represents a real number. This is
* equivalent to, but not necessarily implemented as,
* {@code !(Double.isInfinite(value) || Double.isNaN(value))}.
*
* @since 10.0
*/
public static boolean isFinite(double value) {
return NEGATIVE_INFINITY < value & value < POSITIVE_INFINITY;
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in
* {@code array}. Note that this always returns {@code false} when {@code
* target} is {@code NaN}.
*
* @param array an array of {@code double} values, possibly empty
* @param target a primitive {@code double} value
* @return {@code true} if {@code array[i] == target} for some value of {@code
* i}
*/
public static boolean contains(double[] array, double target) {
for (double value : array) {
if (value == target) {
return true;
}
}
return false;
}
/**
* Returns the index of the first appearance of the value {@code target} in
* {@code array}. Note that this always returns {@code -1} when {@code target}
* is {@code NaN}.
*
* @param array an array of {@code double} values, possibly empty
* @param target a primitive {@code double} value
* @return the least index {@code i} for which {@code array[i] == target}, or
* {@code -1} if no such index exists.
*/
public static int indexOf(double[] array, double target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(
double[] array, double target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the start position of the first occurrence of the specified {@code
* target} within {@code array}, or {@code -1} if there is no such occurrence.
*
* <p>More formally, returns the lowest index {@code i} such that {@code
* java.util.Arrays.copyOfRange(array, i, i + target.length)} contains exactly
* the same elements as {@code target}.
*
* <p>Note that this always returns {@code -1} when {@code target} contains
* {@code NaN}.
*
* @param array the array to search for the sequence {@code target}
* @param target the array to search for as a sub-sequence of {@code array}
*/
public static int indexOf(double[] array, double[] target) {
checkNotNull(array, "array");
checkNotNull(target, "target");
if (target.length == 0) {
return 0;
}
outer:
for (int i = 0; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
/**
* Returns the index of the last appearance of the value {@code target} in
* {@code array}. Note that this always returns {@code -1} when {@code target}
* is {@code NaN}.
*
* @param array an array of {@code double} values, possibly empty
* @param target a primitive {@code double} value
* @return the greatest index {@code i} for which {@code array[i] == target},
* or {@code -1} if no such index exists.
*/
public static int lastIndexOf(double[] array, double target) {
return lastIndexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int lastIndexOf(
double[] array, double target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the least value present in {@code array}, using the same rules of
* comparison as {@link Math#min(double, double)}.
*
* @param array a <i>nonempty</i> array of {@code double} values
* @return the value present in {@code array} that is less than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static double min(double... array) {
checkArgument(array.length > 0);
double min = array[0];
for (int i = 1; i < array.length; i++) {
min = Math.min(min, array[i]);
}
return min;
}
/**
* Returns the greatest value present in {@code array}, using the same rules
* of comparison as {@link Math#max(double, double)}.
*
* @param array a <i>nonempty</i> array of {@code double} values
* @return the value present in {@code array} that is greater than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static double max(double... array) {
checkArgument(array.length > 0);
double max = array[0];
for (int i = 1; i < array.length; i++) {
max = Math.max(max, array[i]);
}
return max;
}
/**
* Returns the values from each provided array combined into a single array.
* For example, {@code concat(new double[] {a, b}, new double[] {}, new
* double[] {c}} returns the array {@code {a, b, c}}.
*
* @param arrays zero or more {@code double} arrays
* @return a single array containing all the values from the source arrays, in
* order
*/
public static double[] concat(double[]... arrays) {
int length = 0;
for (double[] array : arrays) {
length += array.length;
}
double[] result = new double[length];
int pos = 0;
for (double[] array : arrays) {
System.arraycopy(array, 0, result, pos, array.length);
pos += array.length;
}
return result;
}
private static final class DoubleConverter
extends Converter<String, Double> implements Serializable {
static final DoubleConverter INSTANCE = new DoubleConverter();
@Override
protected Double doForward(String value) {
return Double.valueOf(value);
}
@Override
protected String doBackward(Double value) {
return value.toString();
}
@Override
public String toString() {
return "Doubles.stringConverter()";
}
private Object readResolve() {
return INSTANCE;
}
private static final long serialVersionUID = 1;
}
/**
* Returns a serializable converter object that converts between strings and
* doubles using {@link Double#valueOf} and {@link Double#toString()}.
*
* @since 16.0
*/
@Beta
public static Converter<String, Double> stringConverter() {
return DoubleConverter.INSTANCE;
}
/**
* Returns an array containing the same values as {@code array}, but
* guaranteed to be of a specified minimum length. If {@code array} already
* has a length of at least {@code minLength}, it is returned directly.
* Otherwise, a new array of size {@code minLength + padding} is returned,
* containing the values of {@code array}, and zeroes in the remaining places.
*
* @param array the source array
* @param minLength the minimum length the returned array must guarantee
* @param padding an extra amount to "grow" the array by if growth is
* necessary
* @throws IllegalArgumentException if {@code minLength} or {@code padding} is
* negative
* @return an array containing the values of {@code array}, with guaranteed
* minimum length {@code minLength}
*/
public static double[] ensureCapacity(
double[] array, int minLength, int padding) {
checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
checkArgument(padding >= 0, "Invalid padding: %s", padding);
return (array.length < minLength)
? copyOf(array, minLength + padding)
: array;
}
// Arrays.copyOf() requires Java 6
private static double[] copyOf(double[] original, int length) {
double[] copy = new double[length];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, length));
return copy;
}
/**
* Returns a string containing the supplied {@code double} values, converted
* to strings as specified by {@link Double#toString(double)}, and separated
* by {@code separator}. For example, {@code join("-", 1.0, 2.0, 3.0)} returns
* the string {@code "1.0-2.0-3.0"}.
*
* <p>Note that {@link Double#toString(double)} formats {@code double}
* differently in GWT sometimes. In the previous example, it returns the
* string {@code "1-2-3"}.
*
* @param separator the text that should appear between consecutive values in
* the resulting string (but not at the start or end)
* @param array an array of {@code double} values, possibly empty
*/
public static String join(String separator, double... array) {
checkNotNull(separator);
if (array.length == 0) {
return "";
}
// For pre-sizing a builder, just get the right order of magnitude
StringBuilder builder = new StringBuilder(array.length * 12);
builder.append(array[0]);
for (int i = 1; i < array.length; i++) {
builder.append(separator).append(array[i]);
}
return builder.toString();
}
/**
* Returns a comparator that compares two {@code double} arrays
* lexicographically. That is, it compares, using {@link
* #compare(double, double)}), the first pair of values that follow any
* common prefix, or when one array is a prefix of the other, treats the
* shorter array as the lesser. For example,
* {@code [] < [1.0] < [1.0, 2.0] < [2.0]}.
*
* <p>The returned comparator is inconsistent with {@link
* Object#equals(Object)} (since arrays support only identity equality), but
* it is consistent with {@link Arrays#equals(double[], double[])}.
*
* @see <a href="http://en.wikipedia.org/wiki/Lexicographical_order">
* Lexicographical order article at Wikipedia</a>
* @since 2.0
*/
public static Comparator<double[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
private enum LexicographicalComparator implements Comparator<double[]> {
INSTANCE;
@Override
public int compare(double[] left, double[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Doubles.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
}
/**
* Returns an array containing each value of {@code collection}, converted to
* a {@code double} value in the manner of {@link Number#doubleValue}.
*
* <p>Elements are copied from the argument collection as if by {@code
* collection.toArray()}. Calling this method is as thread-safe as calling
* that method.
*
* @param collection a collection of {@code Number} instances
* @return an array containing the same values as {@code collection}, in the
* same order, converted to primitives
* @throws NullPointerException if {@code collection} or any of its elements
* is null
* @since 1.0 (parameter was {@code Collection<Double>} before 12.0)
*/
public static double[] toArray(Collection<? extends Number> collection) {
if (collection instanceof DoubleArrayAsList) {
return ((DoubleArrayAsList) collection).toDoubleArray();
}
Object[] boxedArray = collection.toArray();
int len = boxedArray.length;
double[] array = new double[len];
for (int i = 0; i < len; i++) {
// checkNotNull for GWT (do not optimize)
array[i] = ((Number) checkNotNull(boxedArray[i])).doubleValue();
}
return array;
}
/**
* Returns a fixed-size list backed by the specified array, similar to {@link
* Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)},
* but any attempt to set a value to {@code null} will result in a {@link
* NullPointerException}.
*
* <p>The returned list maintains the values, but not the identities, of
* {@code Double} objects written to or read from it. For example, whether
* {@code list.get(0) == list.get(0)} is true for the returned list is
* unspecified.
*
* <p>The returned list may have unexpected behavior if it contains {@code
* NaN}, or if {@code NaN} is used as a parameter to any of its methods.
*
* @param backingArray the array to back the list
* @return a list view of the array
*/
public static List<Double> asList(double... backingArray) {
if (backingArray.length == 0) {
return Collections.emptyList();
}
return new DoubleArrayAsList(backingArray);
}
@GwtCompatible
private static class DoubleArrayAsList extends AbstractList<Double>
implements RandomAccess, Serializable {
final double[] array;
final int start;
final int end;
DoubleArrayAsList(double[] array) {
this(array, 0, array.length);
}
DoubleArrayAsList(double[] array, int start, int end) {
this.array = array;
this.start = start;
this.end = end;
}
@Override public int size() {
return end - start;
}
@Override public boolean isEmpty() {
return false;
}
@Override public Double get(int index) {
checkElementIndex(index, size());
return array[start + index];
}
@Override public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Double)
&& Doubles.indexOf(array, (Double) target, start, end) != -1;
}
@Override public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Double) {
int i = Doubles.indexOf(array, (Double) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Double) {
int i = Doubles.lastIndexOf(array, (Double) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public Double set(int index, Double element) {
checkElementIndex(index, size());
double oldValue = array[start + index];
// checkNotNull for GWT (do not optimize)
array[start + index] = checkNotNull(element);
return oldValue;
}
@Override public List<Double> subList(int fromIndex, int toIndex) {
int size = size();
checkPositionIndexes(fromIndex, toIndex, size);
if (fromIndex == toIndex) {
return Collections.emptyList();
}
return new DoubleArrayAsList(array, start + fromIndex, start + toIndex);
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof DoubleArrayAsList) {
DoubleArrayAsList that = (DoubleArrayAsList) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (array[start + i] != that.array[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Doubles.hashCode(array[i]);
}
return result;
}
@Override public String toString() {
StringBuilder builder = new StringBuilder(size() * 12);
builder.append('[').append(array[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(array[i]);
}
return builder.append(']').toString();
}
double[] toDoubleArray() {
// Arrays.copyOfRange() is not available under GWT
int size = size();
double[] result = new double[size];
System.arraycopy(array, start, result, 0, size);
return result;
}
private static final long serialVersionUID = 0;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/Doubles.java | Java | asf20 | 19,333 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.primitives.UnsignedInts.INT_MASK;
import static com.google.common.primitives.UnsignedInts.compare;
import static com.google.common.primitives.UnsignedInts.toLong;
import com.google.common.annotations.GwtCompatible;
import java.math.BigInteger;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
/**
* A wrapper class for unsigned {@code int} values, supporting arithmetic operations.
*
* <p>In some cases, when speed is more important than code readability, it may be faster simply to
* treat primitive {@code int} values as unsigned, using the methods from {@link UnsignedInts}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained#Unsigned_support">
* unsigned primitive utilities</a>.
*
* @author Louis Wasserman
* @since 11.0
*/
@GwtCompatible(emulated = true)
public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> {
public static final UnsignedInteger ZERO = fromIntBits(0);
public static final UnsignedInteger ONE = fromIntBits(1);
public static final UnsignedInteger MAX_VALUE = fromIntBits(-1);
private final int value;
private UnsignedInteger(int value) {
// GWT doesn't consistently overflow values to make them 32-bit, so we need to force it.
this.value = value & 0xffffffff;
}
/**
* Returns an {@code UnsignedInteger} corresponding to a given bit representation.
* The argument is interpreted as an unsigned 32-bit value. Specifically, the sign bit
* of {@code bits} is interpreted as a normal bit, and all other bits are treated as usual.
*
* <p>If the argument is nonnegative, the returned result will be equal to {@code bits},
* otherwise, the result will be equal to {@code 2^32 + bits}.
*
* <p>To represent unsigned decimal constants, consider {@link #valueOf(long)} instead.
*
* @since 14.0
*/
public static UnsignedInteger fromIntBits(int bits) {
return new UnsignedInteger(bits);
}
/**
* Returns an {@code UnsignedInteger} that is equal to {@code value},
* if possible. The inverse operation of {@link #longValue()}.
*/
public static UnsignedInteger valueOf(long value) {
checkArgument((value & INT_MASK) == value,
"value (%s) is outside the range for an unsigned integer value", value);
return fromIntBits((int) value);
}
/**
* Returns a {@code UnsignedInteger} representing the same value as the specified
* {@link BigInteger}. This is the inverse operation of {@link #bigIntegerValue()}.
*
* @throws IllegalArgumentException if {@code value} is negative or {@code value >= 2^32}
*/
public static UnsignedInteger valueOf(BigInteger value) {
checkNotNull(value);
checkArgument(value.signum() >= 0 && value.bitLength() <= Integer.SIZE,
"value (%s) is outside the range for an unsigned integer value", value);
return fromIntBits(value.intValue());
}
/**
* Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed
* as an unsigned {@code int} value.
*
* @throws NumberFormatException if the string does not contain a parsable unsigned {@code int}
* value
*/
public static UnsignedInteger valueOf(String string) {
return valueOf(string, 10);
}
/**
* Returns an {@code UnsignedInteger} holding the value of the specified {@code String}, parsed
* as an unsigned {@code int} value in the specified radix.
*
* @throws NumberFormatException if the string does not contain a parsable unsigned {@code int}
* value
*/
public static UnsignedInteger valueOf(String string, int radix) {
return fromIntBits(UnsignedInts.parseUnsignedInt(string, radix));
}
/**
* Returns the result of adding this and {@code val}. If the result would have more than 32 bits,
* returns the low 32 bits of the result.
*
* @since 14.0
*/
@CheckReturnValue
public UnsignedInteger plus(UnsignedInteger val) {
return fromIntBits(this.value + checkNotNull(val).value);
}
/**
* Returns the result of subtracting this and {@code val}. If the result would be negative,
* returns the low 32 bits of the result.
*
* @since 14.0
*/
@CheckReturnValue
public UnsignedInteger minus(UnsignedInteger val) {
return fromIntBits(value - checkNotNull(val).value);
}
/**
* Returns the result of dividing this by {@code val}.
*
* @throws ArithmeticException if {@code val} is zero
* @since 14.0
*/
@CheckReturnValue
public UnsignedInteger dividedBy(UnsignedInteger val) {
return fromIntBits(UnsignedInts.divide(value, checkNotNull(val).value));
}
/**
* Returns this mod {@code val}.
*
* @throws ArithmeticException if {@code val} is zero
* @since 14.0
*/
@CheckReturnValue
public UnsignedInteger mod(UnsignedInteger val) {
return fromIntBits(UnsignedInts.remainder(value, checkNotNull(val).value));
}
/**
* Returns the value of this {@code UnsignedInteger} as an {@code int}. This is an inverse
* operation to {@link #fromIntBits}.
*
* <p>Note that if this {@code UnsignedInteger} holds a value {@code >= 2^31}, the returned value
* will be equal to {@code this - 2^32}.
*/
@Override
public int intValue() {
return value;
}
/**
* Returns the value of this {@code UnsignedInteger} as a {@code long}.
*/
@Override
public long longValue() {
return toLong(value);
}
/**
* Returns the value of this {@code UnsignedInteger} as a {@code float}, analogous to a widening
* primitive conversion from {@code int} to {@code float}, and correctly rounded.
*/
@Override
public float floatValue() {
return longValue();
}
/**
* Returns the value of this {@code UnsignedInteger} as a {@code float}, analogous to a widening
* primitive conversion from {@code int} to {@code double}, and correctly rounded.
*/
@Override
public double doubleValue() {
return longValue();
}
/**
* Returns the value of this {@code UnsignedInteger} as a {@link BigInteger}.
*/
public BigInteger bigIntegerValue() {
return BigInteger.valueOf(longValue());
}
/**
* Compares this unsigned integer to another unsigned integer.
* Returns {@code 0} if they are equal, a negative number if {@code this < other},
* and a positive number if {@code this > other}.
*/
@Override
public int compareTo(UnsignedInteger other) {
checkNotNull(other);
return compare(value, other.value);
}
@Override
public int hashCode() {
return value;
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof UnsignedInteger) {
UnsignedInteger other = (UnsignedInteger) obj;
return value == other.value;
}
return false;
}
/**
* Returns a string representation of the {@code UnsignedInteger} value, in base 10.
*/
@Override
public String toString() {
return toString(10);
}
/**
* Returns a string representation of the {@code UnsignedInteger} value, in base {@code radix}.
* If {@code radix < Character.MIN_RADIX} or {@code radix > Character.MAX_RADIX}, the radix
* {@code 10} is used.
*/
public String toString(int radix) {
return UnsignedInts.toString(value, radix);
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/UnsignedInteger.java | Java | asf20 | 8,128 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.primitives;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Converter;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
/**
* Static utility methods pertaining to {@code short} primitives, that are not
* already found in either {@link Short} or {@link Arrays}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/PrimitivesExplained">
* primitive utilities</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Shorts {
private Shorts() {}
/**
* The number of bytes required to represent a primitive {@code short}
* value.
*/
public static final int BYTES = Short.SIZE / Byte.SIZE;
/**
* The largest power of two that can be represented as a {@code short}.
*
* @since 10.0
*/
public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);
/**
* Returns a hash code for {@code value}; equal to the result of invoking
* {@code ((Short) value).hashCode()}.
*
* @param value a primitive {@code short} value
* @return a hash code for the value
*/
public static int hashCode(short value) {
return value;
}
/**
* Returns the {@code short} value that is equal to {@code value}, if
* possible.
*
* @param value any value in the range of the {@code short} type
* @return the {@code short} value that equals {@code value}
* @throws IllegalArgumentException if {@code value} is greater than {@link
* Short#MAX_VALUE} or less than {@link Short#MIN_VALUE}
*/
public static short checkedCast(long value) {
short result = (short) value;
if (result != value) {
// don't use checkArgument here, to avoid boxing
throw new IllegalArgumentException("Out of range: " + value);
}
return result;
}
/**
* Returns the {@code short} nearest in value to {@code value}.
*
* @param value any {@code long} value
* @return the same value cast to {@code short} if it is in the range of the
* {@code short} type, {@link Short#MAX_VALUE} if it is too large,
* or {@link Short#MIN_VALUE} if it is too small
*/
public static short saturatedCast(long value) {
if (value > Short.MAX_VALUE) {
return Short.MAX_VALUE;
}
if (value < Short.MIN_VALUE) {
return Short.MIN_VALUE;
}
return (short) value;
}
/**
* Compares the two specified {@code short} values. The sign of the value
* returned is the same as that of {@code ((Short) a).compareTo(b)}.
*
* <p><b>Note:</b> projects using JDK 7 or later should use the equivalent
* {@link Short#compare} method instead.
*
* @param a the first {@code short} to compare
* @param b the second {@code short} to compare
* @return a negative value if {@code a} is less than {@code b}; a positive
* value if {@code a} is greater than {@code b}; or zero if they are equal
*/
public static int compare(short a, short b) {
return a - b; // safe due to restricted range
}
/**
* Returns {@code true} if {@code target} is present as an element anywhere in
* {@code array}.
*
* @param array an array of {@code short} values, possibly empty
* @param target a primitive {@code short} value
* @return {@code true} if {@code array[i] == target} for some value of {@code
* i}
*/
public static boolean contains(short[] array, short target) {
for (short value : array) {
if (value == target) {
return true;
}
}
return false;
}
/**
* Returns the index of the first appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code short} values, possibly empty
* @param target a primitive {@code short} value
* @return the least index {@code i} for which {@code array[i] == target}, or
* {@code -1} if no such index exists.
*/
public static int indexOf(short[] array, short target) {
return indexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int indexOf(
short[] array, short target, int start, int end) {
for (int i = start; i < end; i++) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the start position of the first occurrence of the specified {@code
* target} within {@code array}, or {@code -1} if there is no such occurrence.
*
* <p>More formally, returns the lowest index {@code i} such that {@code
* java.util.Arrays.copyOfRange(array, i, i + target.length)} contains exactly
* the same elements as {@code target}.
*
* @param array the array to search for the sequence {@code target}
* @param target the array to search for as a sub-sequence of {@code array}
*/
public static int indexOf(short[] array, short[] target) {
checkNotNull(array, "array");
checkNotNull(target, "target");
if (target.length == 0) {
return 0;
}
outer:
for (int i = 0; i < array.length - target.length + 1; i++) {
for (int j = 0; j < target.length; j++) {
if (array[i + j] != target[j]) {
continue outer;
}
}
return i;
}
return -1;
}
/**
* Returns the index of the last appearance of the value {@code target} in
* {@code array}.
*
* @param array an array of {@code short} values, possibly empty
* @param target a primitive {@code short} value
* @return the greatest index {@code i} for which {@code array[i] == target},
* or {@code -1} if no such index exists.
*/
public static int lastIndexOf(short[] array, short target) {
return lastIndexOf(array, target, 0, array.length);
}
// TODO(kevinb): consider making this public
private static int lastIndexOf(
short[] array, short target, int start, int end) {
for (int i = end - 1; i >= start; i--) {
if (array[i] == target) {
return i;
}
}
return -1;
}
/**
* Returns the least value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code short} values
* @return the value present in {@code array} that is less than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static short min(short... array) {
checkArgument(array.length > 0);
short min = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
/**
* Returns the greatest value present in {@code array}.
*
* @param array a <i>nonempty</i> array of {@code short} values
* @return the value present in {@code array} that is greater than or equal to
* every other value in the array
* @throws IllegalArgumentException if {@code array} is empty
*/
public static short max(short... array) {
checkArgument(array.length > 0);
short max = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
/**
* Returns the values from each provided array combined into a single array.
* For example, {@code concat(new short[] {a, b}, new short[] {}, new
* short[] {c}} returns the array {@code {a, b, c}}.
*
* @param arrays zero or more {@code short} arrays
* @return a single array containing all the values from the source arrays, in
* order
*/
public static short[] concat(short[]... arrays) {
int length = 0;
for (short[] array : arrays) {
length += array.length;
}
short[] result = new short[length];
int pos = 0;
for (short[] array : arrays) {
System.arraycopy(array, 0, result, pos, array.length);
pos += array.length;
}
return result;
}
private static final class ShortConverter
extends Converter<String, Short> implements Serializable {
static final ShortConverter INSTANCE = new ShortConverter();
@Override
protected Short doForward(String value) {
return Short.decode(value);
}
@Override
protected String doBackward(Short value) {
return value.toString();
}
@Override
public String toString() {
return "Shorts.stringConverter()";
}
private Object readResolve() {
return INSTANCE;
}
private static final long serialVersionUID = 1;
}
/**
* Returns a serializable converter object that converts between strings and
* shorts using {@link Short#decode} and {@link Short#toString()}.
*
* @since 16.0
*/
@Beta
public static Converter<String, Short> stringConverter() {
return ShortConverter.INSTANCE;
}
/**
* Returns an array containing the same values as {@code array}, but
* guaranteed to be of a specified minimum length. If {@code array} already
* has a length of at least {@code minLength}, it is returned directly.
* Otherwise, a new array of size {@code minLength + padding} is returned,
* containing the values of {@code array}, and zeroes in the remaining places.
*
* @param array the source array
* @param minLength the minimum length the returned array must guarantee
* @param padding an extra amount to "grow" the array by if growth is
* necessary
* @throws IllegalArgumentException if {@code minLength} or {@code padding} is
* negative
* @return an array containing the values of {@code array}, with guaranteed
* minimum length {@code minLength}
*/
public static short[] ensureCapacity(
short[] array, int minLength, int padding) {
checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
checkArgument(padding >= 0, "Invalid padding: %s", padding);
return (array.length < minLength)
? copyOf(array, minLength + padding)
: array;
}
// Arrays.copyOf() requires Java 6
private static short[] copyOf(short[] original, int length) {
short[] copy = new short[length];
System.arraycopy(original, 0, copy, 0, Math.min(original.length, length));
return copy;
}
/**
* Returns a string containing the supplied {@code short} values separated
* by {@code separator}. For example, {@code join("-", (short) 1, (short) 2,
* (short) 3)} returns the string {@code "1-2-3"}.
*
* @param separator the text that should appear between consecutive values in
* the resulting string (but not at the start or end)
* @param array an array of {@code short} values, possibly empty
*/
public static String join(String separator, short... array) {
checkNotNull(separator);
if (array.length == 0) {
return "";
}
// For pre-sizing a builder, just get the right order of magnitude
StringBuilder builder = new StringBuilder(array.length * 6);
builder.append(array[0]);
for (int i = 1; i < array.length; i++) {
builder.append(separator).append(array[i]);
}
return builder.toString();
}
/**
* Returns a comparator that compares two {@code short} arrays
* lexicographically. That is, it compares, using {@link
* #compare(short, short)}), the first pair of values that follow any
* common prefix, or when one array is a prefix of the other, treats the
* shorter array as the lesser. For example, {@code [] < [(short) 1] <
* [(short) 1, (short) 2] < [(short) 2]}.
*
* <p>The returned comparator is inconsistent with {@link
* Object#equals(Object)} (since arrays support only identity equality), but
* it is consistent with {@link Arrays#equals(short[], short[])}.
*
* @see <a href="http://en.wikipedia.org/wiki/Lexicographical_order">
* Lexicographical order article at Wikipedia</a>
* @since 2.0
*/
public static Comparator<short[]> lexicographicalComparator() {
return LexicographicalComparator.INSTANCE;
}
private enum LexicographicalComparator implements Comparator<short[]> {
INSTANCE;
@Override
public int compare(short[] left, short[] right) {
int minLength = Math.min(left.length, right.length);
for (int i = 0; i < minLength; i++) {
int result = Shorts.compare(left[i], right[i]);
if (result != 0) {
return result;
}
}
return left.length - right.length;
}
}
/**
* Returns an array containing each value of {@code collection}, converted to
* a {@code short} value in the manner of {@link Number#shortValue}.
*
* <p>Elements are copied from the argument collection as if by {@code
* collection.toArray()}. Calling this method is as thread-safe as calling
* that method.
*
* @param collection a collection of {@code Number} instances
* @return an array containing the same values as {@code collection}, in the
* same order, converted to primitives
* @throws NullPointerException if {@code collection} or any of its elements
* is null
* @since 1.0 (parameter was {@code Collection<Short>} before 12.0)
*/
public static short[] toArray(Collection<? extends Number> collection) {
if (collection instanceof ShortArrayAsList) {
return ((ShortArrayAsList) collection).toShortArray();
}
Object[] boxedArray = collection.toArray();
int len = boxedArray.length;
short[] array = new short[len];
for (int i = 0; i < len; i++) {
// checkNotNull for GWT (do not optimize)
array[i] = ((Number) checkNotNull(boxedArray[i])).shortValue();
}
return array;
}
/**
* Returns a fixed-size list backed by the specified array, similar to {@link
* Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)},
* but any attempt to set a value to {@code null} will result in a {@link
* NullPointerException}.
*
* <p>The returned list maintains the values, but not the identities, of
* {@code Short} objects written to or read from it. For example, whether
* {@code list.get(0) == list.get(0)} is true for the returned list is
* unspecified.
*
* @param backingArray the array to back the list
* @return a list view of the array
*/
public static List<Short> asList(short... backingArray) {
if (backingArray.length == 0) {
return Collections.emptyList();
}
return new ShortArrayAsList(backingArray);
}
@GwtCompatible
private static class ShortArrayAsList extends AbstractList<Short>
implements RandomAccess, Serializable {
final short[] array;
final int start;
final int end;
ShortArrayAsList(short[] array) {
this(array, 0, array.length);
}
ShortArrayAsList(short[] array, int start, int end) {
this.array = array;
this.start = start;
this.end = end;
}
@Override public int size() {
return end - start;
}
@Override public boolean isEmpty() {
return false;
}
@Override public Short get(int index) {
checkElementIndex(index, size());
return array[start + index];
}
@Override public boolean contains(Object target) {
// Overridden to prevent a ton of boxing
return (target instanceof Short)
&& Shorts.indexOf(array, (Short) target, start, end) != -1;
}
@Override public int indexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Short) {
int i = Shorts.indexOf(array, (Short) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public int lastIndexOf(Object target) {
// Overridden to prevent a ton of boxing
if (target instanceof Short) {
int i = Shorts.lastIndexOf(array, (Short) target, start, end);
if (i >= 0) {
return i - start;
}
}
return -1;
}
@Override public Short set(int index, Short element) {
checkElementIndex(index, size());
short oldValue = array[start + index];
// checkNotNull for GWT (do not optimize)
array[start + index] = checkNotNull(element);
return oldValue;
}
@Override public List<Short> subList(int fromIndex, int toIndex) {
int size = size();
checkPositionIndexes(fromIndex, toIndex, size);
if (fromIndex == toIndex) {
return Collections.emptyList();
}
return new ShortArrayAsList(array, start + fromIndex, start + toIndex);
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof ShortArrayAsList) {
ShortArrayAsList that = (ShortArrayAsList) object;
int size = size();
if (that.size() != size) {
return false;
}
for (int i = 0; i < size; i++) {
if (array[start + i] != that.array[that.start + i]) {
return false;
}
}
return true;
}
return super.equals(object);
}
@Override public int hashCode() {
int result = 1;
for (int i = start; i < end; i++) {
result = 31 * result + Shorts.hashCode(array[i]);
}
return result;
}
@Override public String toString() {
StringBuilder builder = new StringBuilder(size() * 6);
builder.append('[').append(array[start]);
for (int i = start + 1; i < end; i++) {
builder.append(", ").append(array[i]);
}
return builder.append(']').toString();
}
short[] toShortArray() {
// Arrays.copyOfRange() is not available under GWT
int size = size();
short[] result = new short[size];
System.arraycopy(array, start, result, 0, size);
return result;
}
private static final long serialVersionUID = 0;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/primitives/super/com/google/common/primitives/Shorts.java | Java | asf20 | 18,839 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.base;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import java.util.Arrays;
import javax.annotation.CheckReturnValue;
/**
* Determines a true or false value for any Java {@code char} value, just as {@link Predicate} does
* for any {@link Object}. Also offers basic text processing methods based on this function.
* Implementations are strongly encouraged to be side-effect-free and immutable.
*
* <p>Throughout the documentation of this class, the phrase "matching character" is used to mean
* "any character {@code c} for which {@code this.matches(c)} returns {@code true}".
*
* <p><b>Note:</b> This class deals only with {@code char} values; it does not understand
* supplementary Unicode code points in the range {@code 0x10000} to {@code 0x10FFFF}. Such logical
* characters are encoded into a {@code String} using surrogate pairs, and a {@code CharMatcher}
* treats these just as two separate characters.
*
* <p>Example usages: <pre>
* String trimmed = {@link #WHITESPACE WHITESPACE}.{@link #trimFrom trimFrom}(userInput);
* if ({@link #ASCII ASCII}.{@link #matchesAllOf matchesAllOf}(s)) { ... }</pre>
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/StringsExplained#CharMatcher">
* {@code CharMatcher}</a>.
*
* @author Kevin Bourrillion
* @since 1.0
*/
@Beta // Possibly change from chars to code points; decide constants vs. methods
@GwtCompatible(emulated = true)
public abstract class CharMatcher implements Predicate<Character> {
// Constants
/**
* Determines whether a character is a breaking whitespace (that is, a whitespace which can be
* interpreted as a break between words for formatting purposes). See {@link #WHITESPACE} for a
* discussion of that term.
*
* @since 2.0
*/
public static final CharMatcher BREAKING_WHITESPACE = new CharMatcher() {
@Override
public boolean matches(char c) {
switch (c) {
case '\t':
case '\n':
case '\013':
case '\f':
case '\r':
case ' ':
case '\u0085':
case '\u1680':
case '\u2028':
case '\u2029':
case '\u205f':
case '\u3000':
return true;
case '\u2007':
return false;
default:
return c >= '\u2000' && c <= '\u200a';
}
}
@Override
public String toString() {
return "CharMatcher.BREAKING_WHITESPACE";
}
};
/**
* Determines whether a character is ASCII, meaning that its code point is less than 128.
*/
public static final CharMatcher ASCII = inRange('\0', '\u007f', "CharMatcher.ASCII");
private static class RangesMatcher extends CharMatcher {
private final char[] rangeStarts;
private final char[] rangeEnds;
RangesMatcher(String description, char[] rangeStarts, char[] rangeEnds) {
super(description);
this.rangeStarts = rangeStarts;
this.rangeEnds = rangeEnds;
checkArgument(rangeStarts.length == rangeEnds.length);
for (int i = 0; i < rangeStarts.length; i++) {
checkArgument(rangeStarts[i] <= rangeEnds[i]);
if (i + 1 < rangeStarts.length) {
checkArgument(rangeEnds[i] < rangeStarts[i + 1]);
}
}
}
@Override
public boolean matches(char c) {
int index = Arrays.binarySearch(rangeStarts, c);
if (index >= 0) {
return true;
} else {
index = ~index - 1;
return index >= 0 && c <= rangeEnds[index];
}
}
}
// Must be in ascending order.
private static final String ZEROES = "0\u0660\u06f0\u07c0\u0966\u09e6\u0a66\u0ae6\u0b66\u0be6"
+ "\u0c66\u0ce6\u0d66\u0e50\u0ed0\u0f20\u1040\u1090\u17e0\u1810\u1946\u19d0\u1b50\u1bb0"
+ "\u1c40\u1c50\ua620\ua8d0\ua900\uaa50\uff10";
private static final String NINES;
static {
StringBuilder builder = new StringBuilder(ZEROES.length());
for (int i = 0; i < ZEROES.length(); i++) {
builder.append((char) (ZEROES.charAt(i) + 9));
}
NINES = builder.toString();
}
/**
* Determines whether a character is a digit according to
* <a href="http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7Bdigit%7D">Unicode</a>.
* If you only care to match ASCII digits, you can use {@code inRange('0', '9')}.
*/
public static final CharMatcher DIGIT = new RangesMatcher(
"CharMatcher.DIGIT", ZEROES.toCharArray(), NINES.toCharArray());
/**
* Determines whether a character is a digit according to {@linkplain Character#isDigit(char)
* Java's definition}. If you only care to match ASCII digits, you can use {@code
* inRange('0', '9')}.
*/
public static final CharMatcher JAVA_DIGIT = new CharMatcher("CharMatcher.JAVA_DIGIT") {
@Override public boolean matches(char c) {
return Character.isDigit(c);
}
};
/**
* Determines whether a character is a letter according to {@linkplain Character#isLetter(char)
* Java's definition}. If you only care to match letters of the Latin alphabet, you can use {@code
* inRange('a', 'z').or(inRange('A', 'Z'))}.
*/
public static final CharMatcher JAVA_LETTER = new CharMatcher("CharMatcher.JAVA_LETTER") {
@Override public boolean matches(char c) {
return Character.isLetter(c);
}
};
/**
* Determines whether a character is a letter or digit according to {@linkplain
* Character#isLetterOrDigit(char) Java's definition}.
*/
public static final CharMatcher JAVA_LETTER_OR_DIGIT =
new CharMatcher("CharMatcher.JAVA_LETTER_OR_DIGIT") {
@Override public boolean matches(char c) {
return Character.isLetterOrDigit(c);
}
};
/**
* Determines whether a character is upper case according to {@linkplain
* Character#isUpperCase(char) Java's definition}.
*/
public static final CharMatcher JAVA_UPPER_CASE =
new CharMatcher("CharMatcher.JAVA_UPPER_CASE") {
@Override public boolean matches(char c) {
return Character.isUpperCase(c);
}
};
/**
* Determines whether a character is lower case according to {@linkplain
* Character#isLowerCase(char) Java's definition}.
*/
public static final CharMatcher JAVA_LOWER_CASE =
new CharMatcher("CharMatcher.JAVA_LOWER_CASE") {
@Override public boolean matches(char c) {
return Character.isLowerCase(c);
}
};
/**
* Determines whether a character is an ISO control character as specified by {@link
* Character#isISOControl(char)}.
*/
public static final CharMatcher JAVA_ISO_CONTROL =
inRange('\u0000', '\u001f')
.or(inRange('\u007f', '\u009f'))
.withToString("CharMatcher.JAVA_ISO_CONTROL");
/**
* Determines whether a character is invisible; that is, if its Unicode category is any of
* SPACE_SEPARATOR, LINE_SEPARATOR, PARAGRAPH_SEPARATOR, CONTROL, FORMAT, SURROGATE, and
* PRIVATE_USE according to ICU4J.
*/
public static final CharMatcher INVISIBLE = new RangesMatcher("CharMatcher.INVISIBLE", (
"\u0000\u007f\u00ad\u0600\u061c\u06dd\u070f\u1680\u180e\u2000\u2028\u205f\u2066\u2067\u2068"
+ "\u2069\u206a\u3000\ud800\ufeff\ufff9\ufffa").toCharArray(), (
"\u0020\u00a0\u00ad\u0604\u061c\u06dd\u070f\u1680\u180e\u200f\u202f\u2064\u2066\u2067\u2068"
+ "\u2069\u206f\u3000\uf8ff\ufeff\ufff9\ufffb").toCharArray());
private static String showCharacter(char c) {
String hex = "0123456789ABCDEF";
char[] tmp = {'\\', 'u', '\0', '\0', '\0', '\0'};
for (int i = 0; i < 4; i++) {
tmp[5 - i] = hex.charAt(c & 0xF);
c >>= 4;
}
return String.copyValueOf(tmp);
}
/**
* Determines whether a character is single-width (not double-width). When in doubt, this matcher
* errs on the side of returning {@code false} (that is, it tends to assume a character is
* double-width).
*
* <p><b>Note:</b> as the reference file evolves, we will modify this constant to keep it up to
* date.
*/
public static final CharMatcher SINGLE_WIDTH = new RangesMatcher("CharMatcher.SINGLE_WIDTH",
"\u0000\u05be\u05d0\u05f3\u0600\u0750\u0e00\u1e00\u2100\ufb50\ufe70\uff61".toCharArray(),
"\u04f9\u05be\u05ea\u05f4\u06ff\u077f\u0e7f\u20af\u213a\ufdff\ufeff\uffdc".toCharArray());
/** Matches any character. */
public static final CharMatcher ANY =
new FastMatcher("CharMatcher.ANY") {
@Override public boolean matches(char c) {
return true;
}
@Override public int indexIn(CharSequence sequence) {
return (sequence.length() == 0) ? -1 : 0;
}
@Override public int indexIn(CharSequence sequence, int start) {
int length = sequence.length();
Preconditions.checkPositionIndex(start, length);
return (start == length) ? -1 : start;
}
@Override public int lastIndexIn(CharSequence sequence) {
return sequence.length() - 1;
}
@Override public boolean matchesAllOf(CharSequence sequence) {
checkNotNull(sequence);
return true;
}
@Override public boolean matchesNoneOf(CharSequence sequence) {
return sequence.length() == 0;
}
@Override public String removeFrom(CharSequence sequence) {
checkNotNull(sequence);
return "";
}
@Override public String replaceFrom(CharSequence sequence, char replacement) {
char[] array = new char[sequence.length()];
Arrays.fill(array, replacement);
return new String(array);
}
@Override public String replaceFrom(CharSequence sequence, CharSequence replacement) {
StringBuilder retval = new StringBuilder(sequence.length() * replacement.length());
for (int i = 0; i < sequence.length(); i++) {
retval.append(replacement);
}
return retval.toString();
}
@Override public String collapseFrom(CharSequence sequence, char replacement) {
return (sequence.length() == 0) ? "" : String.valueOf(replacement);
}
@Override public String trimFrom(CharSequence sequence) {
checkNotNull(sequence);
return "";
}
@Override public int countIn(CharSequence sequence) {
return sequence.length();
}
@Override public CharMatcher and(CharMatcher other) {
return checkNotNull(other);
}
@Override public CharMatcher or(CharMatcher other) {
checkNotNull(other);
return this;
}
@Override public CharMatcher negate() {
return NONE;
}
};
/** Matches no characters. */
public static final CharMatcher NONE =
new FastMatcher("CharMatcher.NONE") {
@Override public boolean matches(char c) {
return false;
}
@Override public int indexIn(CharSequence sequence) {
checkNotNull(sequence);
return -1;
}
@Override public int indexIn(CharSequence sequence, int start) {
int length = sequence.length();
Preconditions.checkPositionIndex(start, length);
return -1;
}
@Override public int lastIndexIn(CharSequence sequence) {
checkNotNull(sequence);
return -1;
}
@Override public boolean matchesAllOf(CharSequence sequence) {
return sequence.length() == 0;
}
@Override public boolean matchesNoneOf(CharSequence sequence) {
checkNotNull(sequence);
return true;
}
@Override public String removeFrom(CharSequence sequence) {
return sequence.toString();
}
@Override public String replaceFrom(CharSequence sequence, char replacement) {
return sequence.toString();
}
@Override public String replaceFrom(CharSequence sequence, CharSequence replacement) {
checkNotNull(replacement);
return sequence.toString();
}
@Override public String collapseFrom(CharSequence sequence, char replacement) {
return sequence.toString();
}
@Override public String trimFrom(CharSequence sequence) {
return sequence.toString();
}
@Override
public String trimLeadingFrom(CharSequence sequence) {
return sequence.toString();
}
@Override
public String trimTrailingFrom(CharSequence sequence) {
return sequence.toString();
}
@Override public int countIn(CharSequence sequence) {
checkNotNull(sequence);
return 0;
}
@Override public CharMatcher and(CharMatcher other) {
checkNotNull(other);
return this;
}
@Override public CharMatcher or(CharMatcher other) {
return checkNotNull(other);
}
@Override public CharMatcher negate() {
return ANY;
}
};
// Static factories
/**
* Returns a {@code char} matcher that matches only one specified character.
*/
public static CharMatcher is(final char match) {
String description = "CharMatcher.is('" + showCharacter(match) + "')";
return new FastMatcher(description) {
@Override public boolean matches(char c) {
return c == match;
}
@Override public String replaceFrom(CharSequence sequence, char replacement) {
return sequence.toString().replace(match, replacement);
}
@Override public CharMatcher and(CharMatcher other) {
return other.matches(match) ? this : NONE;
}
@Override public CharMatcher or(CharMatcher other) {
return other.matches(match) ? other : super.or(other);
}
@Override public CharMatcher negate() {
return isNot(match);
}
};
}
/**
* Returns a {@code char} matcher that matches any character except the one specified.
*
* <p>To negate another {@code CharMatcher}, use {@link #negate()}.
*/
public static CharMatcher isNot(final char match) {
String description = "CharMatcher.isNot('" + showCharacter(match) + "')";
return new FastMatcher(description) {
@Override public boolean matches(char c) {
return c != match;
}
@Override public CharMatcher and(CharMatcher other) {
return other.matches(match) ? super.and(other) : other;
}
@Override public CharMatcher or(CharMatcher other) {
return other.matches(match) ? ANY : this;
}
@Override public CharMatcher negate() {
return is(match);
}
};
}
/**
* Returns a {@code char} matcher that matches any character present in the given character
* sequence.
*/
public static CharMatcher anyOf(final CharSequence sequence) {
switch (sequence.length()) {
case 0:
return NONE;
case 1:
return is(sequence.charAt(0));
case 2:
return isEither(sequence.charAt(0), sequence.charAt(1));
default:
// continue below to handle the general case
}
// TODO(user): is it potentially worth just going ahead and building a precomputed matcher?
final char[] chars = sequence.toString().toCharArray();
Arrays.sort(chars);
StringBuilder description = new StringBuilder("CharMatcher.anyOf(\"");
for (char c : chars) {
description.append(showCharacter(c));
}
description.append("\")");
return new CharMatcher(description.toString()) {
@Override public boolean matches(char c) {
return Arrays.binarySearch(chars, c) >= 0;
}
};
}
private static CharMatcher isEither(
final char match1,
final char match2) {
String description = "CharMatcher.anyOf(\"" +
showCharacter(match1) + showCharacter(match2) + "\")";
return new FastMatcher(description) {
@Override public boolean matches(char c) {
return c == match1 || c == match2;
}
};
}
/**
* Returns a {@code char} matcher that matches any character not present in the given character
* sequence.
*/
public static CharMatcher noneOf(CharSequence sequence) {
return anyOf(sequence).negate();
}
/**
* Returns a {@code char} matcher that matches any character in a given range (both endpoints are
* inclusive). For example, to match any lowercase letter of the English alphabet, use {@code
* CharMatcher.inRange('a', 'z')}.
*
* @throws IllegalArgumentException if {@code endInclusive < startInclusive}
*/
public static CharMatcher inRange(final char startInclusive, final char endInclusive) {
checkArgument(endInclusive >= startInclusive);
String description = "CharMatcher.inRange('" +
showCharacter(startInclusive) + "', '" +
showCharacter(endInclusive) + "')";
return inRange(startInclusive, endInclusive, description);
}
static CharMatcher inRange(final char startInclusive, final char endInclusive,
String description) {
return new FastMatcher(description) {
@Override public boolean matches(char c) {
return startInclusive <= c && c <= endInclusive;
}
};
}
/**
* Returns a matcher with identical behavior to the given {@link Character}-based predicate, but
* which operates on primitive {@code char} instances instead.
*/
public static CharMatcher forPredicate(final Predicate<? super Character> predicate) {
checkNotNull(predicate);
if (predicate instanceof CharMatcher) {
return (CharMatcher) predicate;
}
String description = "CharMatcher.forPredicate(" + predicate + ")";
return new CharMatcher(description) {
@Override public boolean matches(char c) {
return predicate.apply(c);
}
@Override public boolean apply(Character character) {
return predicate.apply(checkNotNull(character));
}
};
}
// State
final String description;
// Constructors
/**
* Sets the {@code toString()} from the given description.
*/
CharMatcher(String description) {
this.description = description;
}
/**
* Constructor for use by subclasses. When subclassing, you may want to override
* {@code toString()} to provide a useful description.
*/
protected CharMatcher() {
description = super.toString();
}
// Abstract methods
/** Determines a true or false value for the given character. */
public abstract boolean matches(char c);
// Non-static factories
/**
* Returns a matcher that matches any character not matched by this matcher.
*/
public CharMatcher negate() {
return new NegatedMatcher(this);
}
private static class NegatedMatcher extends CharMatcher {
final CharMatcher original;
NegatedMatcher(String toString, CharMatcher original) {
super(toString);
this.original = original;
}
NegatedMatcher(CharMatcher original) {
this(original + ".negate()", original);
}
@Override public boolean matches(char c) {
return !original.matches(c);
}
@Override public boolean matchesAllOf(CharSequence sequence) {
return original.matchesNoneOf(sequence);
}
@Override public boolean matchesNoneOf(CharSequence sequence) {
return original.matchesAllOf(sequence);
}
@Override public int countIn(CharSequence sequence) {
return sequence.length() - original.countIn(sequence);
}
@Override public CharMatcher negate() {
return original;
}
@Override
CharMatcher withToString(String description) {
return new NegatedMatcher(description, original);
}
}
/**
* Returns a matcher that matches any character matched by both this matcher and {@code other}.
*/
public CharMatcher and(CharMatcher other) {
return new And(this, checkNotNull(other));
}
private static class And extends CharMatcher {
final CharMatcher first;
final CharMatcher second;
And(CharMatcher a, CharMatcher b) {
this(a, b, "CharMatcher.and(" + a + ", " + b + ")");
}
And(CharMatcher a, CharMatcher b, String description) {
super(description);
first = checkNotNull(a);
second = checkNotNull(b);
}
@Override
public boolean matches(char c) {
return first.matches(c) && second.matches(c);
}
@Override
CharMatcher withToString(String description) {
return new And(first, second, description);
}
}
/**
* Returns a matcher that matches any character matched by either this matcher or {@code other}.
*/
public CharMatcher or(CharMatcher other) {
return new Or(this, checkNotNull(other));
}
private static class Or extends CharMatcher {
final CharMatcher first;
final CharMatcher second;
Or(CharMatcher a, CharMatcher b, String description) {
super(description);
first = checkNotNull(a);
second = checkNotNull(b);
}
Or(CharMatcher a, CharMatcher b) {
this(a, b, "CharMatcher.or(" + a + ", " + b + ")");
}
@Override
public boolean matches(char c) {
return first.matches(c) || second.matches(c);
}
@Override
CharMatcher withToString(String description) {
return new Or(first, second, description);
}
}
/**
* Returns a {@code char} matcher functionally equivalent to this one, but which may be faster to
* query than the original; your mileage may vary. Precomputation takes time and is likely to be
* worthwhile only if the precomputed matcher is queried many thousands of times.
*
* <p>This method has no effect (returns {@code this}) when called in GWT: it's unclear whether a
* precomputed matcher is faster, but it certainly consumes more memory, which doesn't seem like a
* worthwhile tradeoff in a browser.
*/
public CharMatcher precomputed() {
return Platform.precomputeCharMatcher(this);
}
/**
* Subclasses should provide a new CharMatcher with the same characteristics as {@code this},
* but with their {@code toString} method overridden with the new description.
*
* <p>This is unsupported by default.
*/
CharMatcher withToString(String description) {
throw new UnsupportedOperationException();
}
private static final int DISTINCT_CHARS = Character.MAX_VALUE - Character.MIN_VALUE + 1;
/**
* A matcher for which precomputation will not yield any significant benefit.
*/
abstract static class FastMatcher extends CharMatcher {
FastMatcher() {
super();
}
FastMatcher(String description) {
super(description);
}
@Override
public final CharMatcher precomputed() {
return this;
}
@Override
public CharMatcher negate() {
return new NegatedFastMatcher(this);
}
}
static final class NegatedFastMatcher extends NegatedMatcher {
NegatedFastMatcher(CharMatcher original) {
super(original);
}
NegatedFastMatcher(String toString, CharMatcher original) {
super(toString, original);
}
@Override
public final CharMatcher precomputed() {
return this;
}
@Override
CharMatcher withToString(String description) {
return new NegatedFastMatcher(description, original);
}
}
// Text processing routines
/**
* Returns {@code true} if a character sequence contains at least one matching character.
* Equivalent to {@code !matchesNoneOf(sequence)}.
*
* <p>The default implementation iterates over the sequence, invoking {@link #matches} for each
* character, until this returns {@code true} or the end is reached.
*
* @param sequence the character sequence to examine, possibly empty
* @return {@code true} if this matcher matches at least one character in the sequence
* @since 8.0
*/
public boolean matchesAnyOf(CharSequence sequence) {
return !matchesNoneOf(sequence);
}
/**
* Returns {@code true} if a character sequence contains only matching characters.
*
* <p>The default implementation iterates over the sequence, invoking {@link #matches} for each
* character, until this returns {@code false} or the end is reached.
*
* @param sequence the character sequence to examine, possibly empty
* @return {@code true} if this matcher matches every character in the sequence, including when
* the sequence is empty
*/
public boolean matchesAllOf(CharSequence sequence) {
for (int i = sequence.length() - 1; i >= 0; i--) {
if (!matches(sequence.charAt(i))) {
return false;
}
}
return true;
}
/**
* Returns {@code true} if a character sequence contains no matching characters. Equivalent to
* {@code !matchesAnyOf(sequence)}.
*
* <p>The default implementation iterates over the sequence, invoking {@link #matches} for each
* character, until this returns {@code false} or the end is reached.
*
* @param sequence the character sequence to examine, possibly empty
* @return {@code true} if this matcher matches every character in the sequence, including when
* the sequence is empty
*/
public boolean matchesNoneOf(CharSequence sequence) {
return indexIn(sequence) == -1;
}
/**
* Returns the index of the first matching character in a character sequence, or {@code -1} if no
* matching character is present.
*
* <p>The default implementation iterates over the sequence in forward order calling {@link
* #matches} for each character.
*
* @param sequence the character sequence to examine from the beginning
* @return an index, or {@code -1} if no character matches
*/
public int indexIn(CharSequence sequence) {
int length = sequence.length();
for (int i = 0; i < length; i++) {
if (matches(sequence.charAt(i))) {
return i;
}
}
return -1;
}
/**
* Returns the index of the first matching character in a character sequence, starting from a
* given position, or {@code -1} if no character matches after that position.
*
* <p>The default implementation iterates over the sequence in forward order, beginning at {@code
* start}, calling {@link #matches} for each character.
*
* @param sequence the character sequence to examine
* @param start the first index to examine; must be nonnegative and no greater than {@code
* sequence.length()}
* @return the index of the first matching character, guaranteed to be no less than {@code start},
* or {@code -1} if no character matches
* @throws IndexOutOfBoundsException if start is negative or greater than {@code
* sequence.length()}
*/
public int indexIn(CharSequence sequence, int start) {
int length = sequence.length();
Preconditions.checkPositionIndex(start, length);
for (int i = start; i < length; i++) {
if (matches(sequence.charAt(i))) {
return i;
}
}
return -1;
}
/**
* Returns the index of the last matching character in a character sequence, or {@code -1} if no
* matching character is present.
*
* <p>The default implementation iterates over the sequence in reverse order calling {@link
* #matches} for each character.
*
* @param sequence the character sequence to examine from the end
* @return an index, or {@code -1} if no character matches
*/
public int lastIndexIn(CharSequence sequence) {
for (int i = sequence.length() - 1; i >= 0; i--) {
if (matches(sequence.charAt(i))) {
return i;
}
}
return -1;
}
/**
* Returns the number of matching characters found in a character sequence.
*/
public int countIn(CharSequence sequence) {
int count = 0;
for (int i = 0; i < sequence.length(); i++) {
if (matches(sequence.charAt(i))) {
count++;
}
}
return count;
}
/**
* Returns a string containing all non-matching characters of a character sequence, in order. For
* example: <pre> {@code
*
* CharMatcher.is('a').removeFrom("bazaar")}</pre>
*
* ... returns {@code "bzr"}.
*/
@CheckReturnValue
public String removeFrom(CharSequence sequence) {
String string = sequence.toString();
int pos = indexIn(string);
if (pos == -1) {
return string;
}
char[] chars = string.toCharArray();
int spread = 1;
// This unusual loop comes from extensive benchmarking
OUT: while (true) {
pos++;
while (true) {
if (pos == chars.length) {
break OUT;
}
if (matches(chars[pos])) {
break;
}
chars[pos - spread] = chars[pos];
pos++;
}
spread++;
}
return new String(chars, 0, pos - spread);
}
/**
* Returns a string containing all matching characters of a character sequence, in order. For
* example: <pre> {@code
*
* CharMatcher.is('a').retainFrom("bazaar")}</pre>
*
* ... returns {@code "aaa"}.
*/
@CheckReturnValue
public String retainFrom(CharSequence sequence) {
return negate().removeFrom(sequence);
}
/**
* Returns a string copy of the input character sequence, with each character that matches this
* matcher replaced by a given replacement character. For example: <pre> {@code
*
* CharMatcher.is('a').replaceFrom("radar", 'o')}</pre>
*
* ... returns {@code "rodor"}.
*
* <p>The default implementation uses {@link #indexIn(CharSequence)} to find the first matching
* character, then iterates the remainder of the sequence calling {@link #matches(char)} for each
* character.
*
* @param sequence the character sequence to replace matching characters in
* @param replacement the character to append to the result string in place of each matching
* character in {@code sequence}
* @return the new string
*/
@CheckReturnValue
public String replaceFrom(CharSequence sequence, char replacement) {
String string = sequence.toString();
int pos = indexIn(string);
if (pos == -1) {
return string;
}
char[] chars = string.toCharArray();
chars[pos] = replacement;
for (int i = pos + 1; i < chars.length; i++) {
if (matches(chars[i])) {
chars[i] = replacement;
}
}
return new String(chars);
}
/**
* Returns a string copy of the input character sequence, with each character that matches this
* matcher replaced by a given replacement sequence. For example: <pre> {@code
*
* CharMatcher.is('a').replaceFrom("yaha", "oo")}</pre>
*
* ... returns {@code "yoohoo"}.
*
* <p><b>Note:</b> If the replacement is a fixed string with only one character, you are better
* off calling {@link #replaceFrom(CharSequence, char)} directly.
*
* @param sequence the character sequence to replace matching characters in
* @param replacement the characters to append to the result string in place of each matching
* character in {@code sequence}
* @return the new string
*/
@CheckReturnValue
public String replaceFrom(CharSequence sequence, CharSequence replacement) {
int replacementLen = replacement.length();
if (replacementLen == 0) {
return removeFrom(sequence);
}
if (replacementLen == 1) {
return replaceFrom(sequence, replacement.charAt(0));
}
String string = sequence.toString();
int pos = indexIn(string);
if (pos == -1) {
return string;
}
int len = string.length();
StringBuilder buf = new StringBuilder((len * 3 / 2) + 16);
int oldpos = 0;
do {
buf.append(string, oldpos, pos);
buf.append(replacement);
oldpos = pos + 1;
pos = indexIn(string, oldpos);
} while (pos != -1);
buf.append(string, oldpos, len);
return buf.toString();
}
/**
* Returns a substring of the input character sequence that omits all characters this matcher
* matches from the beginning and from the end of the string. For example: <pre> {@code
*
* CharMatcher.anyOf("ab").trimFrom("abacatbab")}</pre>
*
* ... returns {@code "cat"}.
*
* <p>Note that: <pre> {@code
*
* CharMatcher.inRange('\0', ' ').trimFrom(str)}</pre>
*
* ... is equivalent to {@link String#trim()}.
*/
@CheckReturnValue
public String trimFrom(CharSequence sequence) {
int len = sequence.length();
int first;
int last;
for (first = 0; first < len; first++) {
if (!matches(sequence.charAt(first))) {
break;
}
}
for (last = len - 1; last > first; last--) {
if (!matches(sequence.charAt(last))) {
break;
}
}
return sequence.subSequence(first, last + 1).toString();
}
/**
* Returns a substring of the input character sequence that omits all characters this matcher
* matches from the beginning of the string. For example: <pre> {@code
*
* CharMatcher.anyOf("ab").trimLeadingFrom("abacatbab")}</pre>
*
* ... returns {@code "catbab"}.
*/
@CheckReturnValue
public String trimLeadingFrom(CharSequence sequence) {
int len = sequence.length();
for (int first = 0; first < len; first++) {
if (!matches(sequence.charAt(first))) {
return sequence.subSequence(first, len).toString();
}
}
return "";
}
/**
* Returns a substring of the input character sequence that omits all characters this matcher
* matches from the end of the string. For example: <pre> {@code
*
* CharMatcher.anyOf("ab").trimTrailingFrom("abacatbab")}</pre>
*
* ... returns {@code "abacat"}.
*/
@CheckReturnValue
public String trimTrailingFrom(CharSequence sequence) {
int len = sequence.length();
for (int last = len - 1; last >= 0; last--) {
if (!matches(sequence.charAt(last))) {
return sequence.subSequence(0, last + 1).toString();
}
}
return "";
}
/**
* Returns a string copy of the input character sequence, with each group of consecutive
* characters that match this matcher replaced by a single replacement character. For example:
* <pre> {@code
*
* CharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')}</pre>
*
* ... returns {@code "b-p-r"}.
*
* <p>The default implementation uses {@link #indexIn(CharSequence)} to find the first matching
* character, then iterates the remainder of the sequence calling {@link #matches(char)} for each
* character.
*
* @param sequence the character sequence to replace matching groups of characters in
* @param replacement the character to append to the result string in place of each group of
* matching characters in {@code sequence}
* @return the new string
*/
@CheckReturnValue
public String collapseFrom(CharSequence sequence, char replacement) {
// This implementation avoids unnecessary allocation.
int len = sequence.length();
for (int i = 0; i < len; i++) {
char c = sequence.charAt(i);
if (matches(c)) {
if (c == replacement
&& (i == len - 1 || !matches(sequence.charAt(i + 1)))) {
// a no-op replacement
i++;
} else {
StringBuilder builder = new StringBuilder(len)
.append(sequence.subSequence(0, i))
.append(replacement);
return finishCollapseFrom(sequence, i + 1, len, replacement, builder, true);
}
}
}
// no replacement needed
return sequence.toString();
}
/**
* Collapses groups of matching characters exactly as {@link #collapseFrom} does, except that
* groups of matching characters at the start or end of the sequence are removed without
* replacement.
*/
@CheckReturnValue
public String trimAndCollapseFrom(CharSequence sequence, char replacement) {
// This implementation avoids unnecessary allocation.
int len = sequence.length();
int first;
int last;
for (first = 0; first < len && matches(sequence.charAt(first)); first++) {}
for (last = len - 1; last > first && matches(sequence.charAt(last)); last--) {}
return (first == 0 && last == len - 1)
? collapseFrom(sequence, replacement)
: finishCollapseFrom(
sequence, first, last + 1, replacement,
new StringBuilder(last + 1 - first),
false);
}
private String finishCollapseFrom(
CharSequence sequence, int start, int end, char replacement,
StringBuilder builder, boolean inMatchingGroup) {
for (int i = start; i < end; i++) {
char c = sequence.charAt(i);
if (matches(c)) {
if (!inMatchingGroup) {
builder.append(replacement);
inMatchingGroup = true;
}
} else {
builder.append(c);
inMatchingGroup = false;
}
}
return builder.toString();
}
/**
* @deprecated Provided only to satisfy the {@link Predicate} interface; use {@link #matches}
* instead.
*/
@Deprecated
@Override
public boolean apply(Character character) {
return matches(character);
}
/**
* Returns a string representation of this {@code CharMatcher}, such as
* {@code CharMatcher.or(WHITESPACE, JAVA_DIGIT)}.
*/
@Override
public String toString() {
return description;
}
static final String WHITESPACE_TABLE = ""
+ "\u2002\u3000\r\u0085\u200A\u2005\u2000\u3000"
+ "\u2029\u000B\u3000\u2008\u2003\u205F\u3000\u1680"
+ "\u0009\u0020\u2006\u2001\u202F\u00A0\u000C\u2009"
+ "\u3000\u2004\u3000\u3000\u2028\n\u2007\u3000";
static final int WHITESPACE_MULTIPLIER = 1682554634;
static final int WHITESPACE_SHIFT = Integer.numberOfLeadingZeros(WHITESPACE_TABLE.length() - 1);
/**
* Determines whether a character is whitespace according to the latest Unicode standard, as
* illustrated
* <a href="http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5Cp%7Bwhitespace%7D">here</a>.
* This is not the same definition used by other Java APIs. (See a
* <a href="http://spreadsheets.google.com/pub?key=pd8dAQyHbdewRsnE5x5GzKQ">comparison of several
* definitions of "whitespace"</a>.)
*
* <p><b>Note:</b> as the Unicode definition evolves, we will modify this constant to keep it up
* to date.
*/
public static final CharMatcher WHITESPACE = new FastMatcher("WHITESPACE") {
@Override
public boolean matches(char c) {
return WHITESPACE_TABLE.charAt((WHITESPACE_MULTIPLIER * c) >>> WHITESPACE_SHIFT) == c;
}
};
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/CharMatcher.java | Java | asf20 | 39,222 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.base;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckReturnValue;
/**
* Extracts non-overlapping substrings from an input string, typically by
* recognizing appearances of a <i>separator</i> sequence. This separator can be
* specified as a single {@linkplain #on(char) character}, fixed {@linkplain
* #on(String) string}, {@linkplain #onPattern regular expression} or {@link
* #on(CharMatcher) CharMatcher} instance. Or, instead of using a separator at
* all, a splitter can extract adjacent substrings of a given {@linkplain
* #fixedLength fixed length}.
*
* <p>For example, this expression: <pre> {@code
*
* Splitter.on(',').split("foo,bar,qux")}</pre>
*
* ... produces an {@code Iterable} containing {@code "foo"}, {@code "bar"} and
* {@code "qux"}, in that order.
*
* <p>By default, {@code Splitter}'s behavior is simplistic and unassuming. The
* following expression: <pre> {@code
*
* Splitter.on(',').split(" foo,,, bar ,")}</pre>
*
* ... yields the substrings {@code [" foo", "", "", " bar ", ""]}. If this
* is not the desired behavior, use configuration methods to obtain a <i>new</i>
* splitter instance with modified behavior: <pre> {@code
*
* private static final Splitter MY_SPLITTER = Splitter.on(',')
* .trimResults()
* .omitEmptyStrings();}</pre>
*
* <p>Now {@code MY_SPLITTER.split("foo,,, bar ,")} returns just {@code ["foo",
* "bar"]}. Note that the order in which these configuration methods are called
* is never significant.
*
* <p><b>Warning:</b> Splitter instances are immutable. Invoking a configuration
* method has no effect on the receiving instance; you must store and use the
* new splitter instance it returns instead. <pre> {@code
*
* // Do NOT do this
* Splitter splitter = Splitter.on('/');
* splitter.trimResults(); // does nothing!
* return splitter.split("wrong / wrong / wrong");}</pre>
*
* <p>For separator-based splitters that do not use {@code omitEmptyStrings}, an
* input string containing {@code n} occurrences of the separator naturally
* yields an iterable of size {@code n + 1}. So if the separator does not occur
* anywhere in the input, a single substring is returned containing the entire
* input. Consequently, all splitters split the empty string to {@code [""]}
* (note: even fixed-length splitters).
*
* <p>Splitter instances are thread-safe immutable, and are therefore safe to
* store as {@code static final} constants.
*
* <p>The {@link Joiner} class provides the inverse operation to splitting, but
* note that a round-trip between the two should be assumed to be lossy.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/StringsExplained#Splitter">
* {@code Splitter}</a>.
*
* @author Julien Silland
* @author Jesse Wilson
* @author Kevin Bourrillion
* @author Louis Wasserman
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Splitter {
private final CharMatcher trimmer;
private final boolean omitEmptyStrings;
private final Strategy strategy;
private final int limit;
private Splitter(Strategy strategy) {
this(strategy, false, CharMatcher.NONE, Integer.MAX_VALUE);
}
private Splitter(Strategy strategy, boolean omitEmptyStrings,
CharMatcher trimmer, int limit) {
this.strategy = strategy;
this.omitEmptyStrings = omitEmptyStrings;
this.trimmer = trimmer;
this.limit = limit;
}
/**
* Returns a splitter that uses the given single-character separator. For
* example, {@code Splitter.on(',').split("foo,,bar")} returns an iterable
* containing {@code ["foo", "", "bar"]}.
*
* @param separator the character to recognize as a separator
* @return a splitter, with default settings, that recognizes that separator
*/
public static Splitter on(char separator) {
return on(CharMatcher.is(separator));
}
/**
* Returns a splitter that considers any single character matched by the
* given {@code CharMatcher} to be a separator. For example, {@code
* Splitter.on(CharMatcher.anyOf(";,")).split("foo,;bar,quux")} returns an
* iterable containing {@code ["foo", "", "bar", "quux"]}.
*
* @param separatorMatcher a {@link CharMatcher} that determines whether a
* character is a separator
* @return a splitter, with default settings, that uses this matcher
*/
public static Splitter on(final CharMatcher separatorMatcher) {
checkNotNull(separatorMatcher);
return new Splitter(new Strategy() {
@Override public SplittingIterator iterator(
Splitter splitter, final CharSequence toSplit) {
return new SplittingIterator(splitter, toSplit) {
@Override int separatorStart(int start) {
return separatorMatcher.indexIn(toSplit, start);
}
@Override int separatorEnd(int separatorPosition) {
return separatorPosition + 1;
}
};
}
});
}
/**
* Returns a splitter that uses the given fixed string as a separator. For
* example, {@code Splitter.on(", ").split("foo, bar,baz")} returns an
* iterable containing {@code ["foo", "bar,baz"]}.
*
* @param separator the literal, nonempty string to recognize as a separator
* @return a splitter, with default settings, that recognizes that separator
*/
public static Splitter on(final String separator) {
checkArgument(separator.length() != 0,
"The separator may not be the empty string.");
return new Splitter(new Strategy() {
@Override public SplittingIterator iterator(
Splitter splitter, CharSequence toSplit) {
return new SplittingIterator(splitter, toSplit) {
@Override public int separatorStart(int start) {
int separatorLength = separator.length();
positions:
for (int p = start, last = toSplit.length() - separatorLength;
p <= last; p++) {
for (int i = 0; i < separatorLength; i++) {
if (toSplit.charAt(i + p) != separator.charAt(i)) {
continue positions;
}
}
return p;
}
return -1;
}
@Override public int separatorEnd(int separatorPosition) {
return separatorPosition + separator.length();
}
};
}
});
}
/**
* Returns a splitter that divides strings into pieces of the given length.
* For example, {@code Splitter.fixedLength(2).split("abcde")} returns an
* iterable containing {@code ["ab", "cd", "e"]}. The last piece can be
* smaller than {@code length} but will never be empty.
*
* <p><b>Exception:</b> for consistency with separator-based splitters, {@code
* split("")} does not yield an empty iterable, but an iterable containing
* {@code ""}. This is the only case in which {@code
* Iterables.size(split(input))} does not equal {@code
* IntMath.divide(input.length(), length, CEILING)}. To avoid this behavior,
* use {@code omitEmptyStrings}.
*
* @param length the desired length of pieces after splitting, a positive
* integer
* @return a splitter, with default settings, that can split into fixed sized
* pieces
* @throws IllegalArgumentException if {@code length} is zero or negative
*/
public static Splitter fixedLength(final int length) {
checkArgument(length > 0, "The length may not be less than 1");
return new Splitter(new Strategy() {
@Override public SplittingIterator iterator(
final Splitter splitter, CharSequence toSplit) {
return new SplittingIterator(splitter, toSplit) {
@Override public int separatorStart(int start) {
int nextChunkStart = start + length;
return (nextChunkStart < toSplit.length() ? nextChunkStart : -1);
}
@Override public int separatorEnd(int separatorPosition) {
return separatorPosition;
}
};
}
});
}
/**
* Returns a splitter that behaves equivalently to {@code this} splitter, but
* automatically omits empty strings from the results. For example, {@code
* Splitter.on(',').omitEmptyStrings().split(",a,,,b,c,,")} returns an
* iterable containing only {@code ["a", "b", "c"]}.
*
* <p>If either {@code trimResults} option is also specified when creating a
* splitter, that splitter always trims results first before checking for
* emptiness. So, for example, {@code
* Splitter.on(':').omitEmptyStrings().trimResults().split(": : : ")} returns
* an empty iterable.
*
* <p>Note that it is ordinarily not possible for {@link #split(CharSequence)}
* to return an empty iterable, but when using this option, it can (if the
* input sequence consists of nothing but separators).
*
* @return a splitter with the desired configuration
*/
@CheckReturnValue
public Splitter omitEmptyStrings() {
return new Splitter(strategy, true, trimmer, limit);
}
/**
* Returns a splitter that behaves equivalently to {@code this} splitter but
* stops splitting after it reaches the limit.
* The limit defines the maximum number of items returned by the iterator.
*
* <p>For example,
* {@code Splitter.on(',').limit(3).split("a,b,c,d")} returns an iterable
* containing {@code ["a", "b", "c,d"]}. When omitting empty strings, the
* omitted strings do no count. Hence,
* {@code Splitter.on(',').limit(3).omitEmptyStrings().split("a,,,b,,,c,d")}
* returns an iterable containing {@code ["a", "b", "c,d"}.
* When trim is requested, all entries, including the last are trimmed. Hence
* {@code Splitter.on(',').limit(3).trimResults().split(" a , b , c , d ")}
* results in @{code ["a", "b", "c , d"]}.
*
* @param limit the maximum number of items returns
* @return a splitter with the desired configuration
* @since 9.0
*/
@CheckReturnValue
public Splitter limit(int limit) {
checkArgument(limit > 0, "must be greater than zero: %s", limit);
return new Splitter(strategy, omitEmptyStrings, trimmer, limit);
}
/**
* Returns a splitter that behaves equivalently to {@code this} splitter, but
* automatically removes leading and trailing {@linkplain
* CharMatcher#WHITESPACE whitespace} from each returned substring; equivalent
* to {@code trimResults(CharMatcher.WHITESPACE)}. For example, {@code
* Splitter.on(',').trimResults().split(" a, b ,c ")} returns an iterable
* containing {@code ["a", "b", "c"]}.
*
* @return a splitter with the desired configuration
*/
@CheckReturnValue
public Splitter trimResults() {
return trimResults(CharMatcher.WHITESPACE);
}
/**
* Returns a splitter that behaves equivalently to {@code this} splitter, but
* removes all leading or trailing characters matching the given {@code
* CharMatcher} from each returned substring. For example, {@code
* Splitter.on(',').trimResults(CharMatcher.is('_')).split("_a ,_b_ ,c__")}
* returns an iterable containing {@code ["a ", "b_ ", "c"]}.
*
* @param trimmer a {@link CharMatcher} that determines whether a character
* should be removed from the beginning/end of a subsequence
* @return a splitter with the desired configuration
*/
// TODO(kevinb): throw if a trimmer was already specified!
@CheckReturnValue
public Splitter trimResults(CharMatcher trimmer) {
checkNotNull(trimmer);
return new Splitter(strategy, omitEmptyStrings, trimmer, limit);
}
/**
* Splits {@code sequence} into string components and makes them available
* through an {@link Iterator}, which may be lazily evaluated. If you want
* an eagerly computed {@link List}, use {@link #splitToList(CharSequence)}.
*
* @param sequence the sequence of characters to split
* @return an iteration over the segments split from the parameter.
*/
public Iterable<String> split(final CharSequence sequence) {
checkNotNull(sequence);
return new Iterable<String>() {
@Override public Iterator<String> iterator() {
return splittingIterator(sequence);
}
@Override public String toString() {
return Joiner.on(", ")
.appendTo(new StringBuilder().append('['), this)
.append(']')
.toString();
}
};
}
private Iterator<String> splittingIterator(CharSequence sequence) {
return strategy.iterator(this, sequence);
}
/**
* Splits {@code sequence} into string components and returns them as
* an immutable list. If you want an {@link Iterable} which may be lazily
* evaluated, use {@link #split(CharSequence)}.
*
* @param sequence the sequence of characters to split
* @return an immutable list of the segments split from the parameter
* @since 15.0
*/
@Beta
public List<String> splitToList(CharSequence sequence) {
checkNotNull(sequence);
Iterator<String> iterator = splittingIterator(sequence);
List<String> result = new ArrayList<String>();
while (iterator.hasNext()) {
result.add(iterator.next());
}
return Collections.unmodifiableList(result);
}
/**
* Returns a {@code MapSplitter} which splits entries based on this splitter,
* and splits entries into keys and values using the specified separator.
*
* @since 10.0
*/
@CheckReturnValue
@Beta
public MapSplitter withKeyValueSeparator(String separator) {
return withKeyValueSeparator(on(separator));
}
/**
* Returns a {@code MapSplitter} which splits entries based on this splitter,
* and splits entries into keys and values using the specified separator.
*
* @since 14.0
*/
@CheckReturnValue
@Beta
public MapSplitter withKeyValueSeparator(char separator) {
return withKeyValueSeparator(on(separator));
}
/**
* Returns a {@code MapSplitter} which splits entries based on this splitter,
* and splits entries into keys and values using the specified key-value
* splitter.
*
* @since 10.0
*/
@CheckReturnValue
@Beta
public MapSplitter withKeyValueSeparator(Splitter keyValueSplitter) {
return new MapSplitter(this, keyValueSplitter);
}
/**
* An object that splits strings into maps as {@code Splitter} splits
* iterables and lists. Like {@code Splitter}, it is thread-safe and
* immutable.
*
* @since 10.0
*/
@Beta
public static final class MapSplitter {
private static final String INVALID_ENTRY_MESSAGE =
"Chunk [%s] is not a valid entry";
private final Splitter outerSplitter;
private final Splitter entrySplitter;
private MapSplitter(Splitter outerSplitter, Splitter entrySplitter) {
this.outerSplitter = outerSplitter; // only "this" is passed
this.entrySplitter = checkNotNull(entrySplitter);
}
/**
* Splits {@code sequence} into substrings, splits each substring into
* an entry, and returns an unmodifiable map with each of the entries. For
* example, <code>
* Splitter.on(';').trimResults().withKeyValueSeparator("=>")
* .split("a=>b ; c=>b")
* </code> will return a mapping from {@code "a"} to {@code "b"} and
* {@code "c"} to {@code b}.
*
* <p>The returned map preserves the order of the entries from
* {@code sequence}.
*
* @throws IllegalArgumentException if the specified sequence does not split
* into valid map entries, or if there are duplicate keys
*/
public Map<String, String> split(CharSequence sequence) {
Map<String, String> map = new LinkedHashMap<String, String>();
for (String entry : outerSplitter.split(sequence)) {
Iterator<String> entryFields = entrySplitter.splittingIterator(entry);
checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry);
String key = entryFields.next();
checkArgument(!map.containsKey(key), "Duplicate key [%s] found.", key);
checkArgument(entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry);
String value = entryFields.next();
map.put(key, value);
checkArgument(!entryFields.hasNext(), INVALID_ENTRY_MESSAGE, entry);
}
return Collections.unmodifiableMap(map);
}
}
private interface Strategy {
Iterator<String> iterator(Splitter splitter, CharSequence toSplit);
}
private abstract static class SplittingIterator extends AbstractIterator<String> {
final CharSequence toSplit;
final CharMatcher trimmer;
final boolean omitEmptyStrings;
/**
* Returns the first index in {@code toSplit} at or after {@code start}
* that contains the separator.
*/
abstract int separatorStart(int start);
/**
* Returns the first index in {@code toSplit} after {@code
* separatorPosition} that does not contain a separator. This method is only
* invoked after a call to {@code separatorStart}.
*/
abstract int separatorEnd(int separatorPosition);
int offset = 0;
int limit;
protected SplittingIterator(Splitter splitter, CharSequence toSplit) {
this.trimmer = splitter.trimmer;
this.omitEmptyStrings = splitter.omitEmptyStrings;
this.limit = splitter.limit;
this.toSplit = toSplit;
}
@Override protected String computeNext() {
/*
* The returned string will be from the end of the last match to the
* beginning of the next one. nextStart is the start position of the
* returned substring, while offset is the place to start looking for a
* separator.
*/
int nextStart = offset;
while (offset != -1) {
int start = nextStart;
int end;
int separatorPosition = separatorStart(offset);
if (separatorPosition == -1) {
end = toSplit.length();
offset = -1;
} else {
end = separatorPosition;
offset = separatorEnd(separatorPosition);
}
if (offset == nextStart) {
/*
* This occurs when some pattern has an empty match, even if it
* doesn't match the empty string -- for example, if it requires
* lookahead or the like. The offset must be increased to look for
* separators beyond this point, without changing the start position
* of the next returned substring -- so nextStart stays the same.
*/
offset++;
if (offset >= toSplit.length()) {
offset = -1;
}
continue;
}
while (start < end && trimmer.matches(toSplit.charAt(start))) {
start++;
}
while (end > start && trimmer.matches(toSplit.charAt(end - 1))) {
end--;
}
if (omitEmptyStrings && start == end) {
// Don't include the (unused) separator in next split string.
nextStart = offset;
continue;
}
if (limit == 1) {
// The limit has been reached, return the rest of the string as the
// final item. This is tested after empty string removal so that
// empty strings do not count towards the limit.
end = toSplit.length();
offset = -1;
// Since we may have changed the end, we need to trim it again.
while (end > start && trimmer.matches(toSplit.charAt(end - 1))) {
end--;
}
} else {
limit--;
}
return toSplit.subSequence(start, end).toString();
}
return endOfData();
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Splitter.java | Java | asf20 | 20,560 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.base;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import java.util.concurrent.TimeUnit;
/**
* An object that measures elapsed time in nanoseconds. It is useful to measure
* elapsed time using this class instead of direct calls to {@link
* System#nanoTime} for a few reasons:
*
* <ul>
* <li>An alternate time source can be substituted, for testing or performance
* reasons.
* <li>As documented by {@code nanoTime}, the value returned has no absolute
* meaning, and can only be interpreted as relative to another timestamp
* returned by {@code nanoTime} at a different time. {@code Stopwatch} is a
* more effective abstraction because it exposes only these relative values,
* not the absolute ones.
* </ul>
*
* <p>Basic usage:
* <pre>
* Stopwatch stopwatch = Stopwatch.{@link #createStarted createStarted}();
* doSomething();
* stopwatch.{@link #stop stop}(); // optional
*
* long millis = stopwatch.elapsed(MILLISECONDS);
*
* log.info("time: " + stopwatch); // formatted string like "12.3 ms"</pre>
*
* <p>Stopwatch methods are not idempotent; it is an error to start or stop a
* stopwatch that is already in the desired state.
*
* <p>When testing code that uses this class, use
* {@link #createUnstarted(Ticker)} or {@link #createStarted(Ticker)} to
* supply a fake or mock ticker.
* <!-- TODO(kevinb): restore the "such as" --> This allows you to
* simulate any valid behavior of the stopwatch.
*
* <p><b>Note:</b> This class is not thread-safe.
*
* @author Kevin Bourrillion
* @since 10.0
*/
@Beta
@GwtCompatible(emulated = true)
public final class Stopwatch {
private final Ticker ticker;
private boolean isRunning;
private long elapsedNanos;
private long startTick;
/**
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
* @since 15.0
*/
public static Stopwatch createUnstarted() {
return new Stopwatch();
}
/**
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*
* @since 15.0
*/
public static Stopwatch createUnstarted(Ticker ticker) {
return new Stopwatch(ticker);
}
/**
* Creates (and starts) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
* @since 15.0
*/
public static Stopwatch createStarted() {
return new Stopwatch().start();
}
/**
* Creates (and starts) a new stopwatch, using the specified time
* source.
*
* @since 15.0
*/
public static Stopwatch createStarted(Ticker ticker) {
return new Stopwatch(ticker).start();
}
/**
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
* @deprecated Use {@link Stopwatch#createUnstarted()} instead.
*/
@Deprecated
Stopwatch() {
this(Ticker.systemTicker());
}
/**
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*
* @deprecated Use {@link Stopwatch#createUnstarted(Ticker)} instead.
*/
@Deprecated
Stopwatch(Ticker ticker) {
this.ticker = checkNotNull(ticker, "ticker");
}
/**
* Returns {@code true} if {@link #start()} has been called on this stopwatch,
* and {@link #stop()} has not been called since the last call to {@code
* start()}.
*/
public boolean isRunning() {
return isRunning;
}
/**
* Starts the stopwatch.
*
* @return this {@code Stopwatch} instance
* @throws IllegalStateException if the stopwatch is already running.
*/
public Stopwatch start() {
checkState(!isRunning, "This stopwatch is already running.");
isRunning = true;
startTick = ticker.read();
return this;
}
/**
* Stops the stopwatch. Future reads will return the fixed duration that had
* elapsed up to this point.
*
* @return this {@code Stopwatch} instance
* @throws IllegalStateException if the stopwatch is already stopped.
*/
public Stopwatch stop() {
long tick = ticker.read();
checkState(isRunning, "This stopwatch is already stopped.");
isRunning = false;
elapsedNanos += tick - startTick;
return this;
}
/**
* Sets the elapsed time for this stopwatch to zero,
* and places it in a stopped state.
*
* @return this {@code Stopwatch} instance
*/
public Stopwatch reset() {
elapsedNanos = 0;
isRunning = false;
return this;
}
private long elapsedNanos() {
return isRunning ? ticker.read() - startTick + elapsedNanos : elapsedNanos;
}
/**
* Returns the current elapsed time shown on this stopwatch, expressed
* in the desired time unit, with any fraction rounded down.
*
* <p>Note that the overhead of measurement can be more than a microsecond, so
* it is generally not useful to specify {@link TimeUnit#NANOSECONDS}
* precision here.
*
* @since 14.0 (since 10.0 as {@code elapsedTime()})
*/
public long elapsed(TimeUnit desiredUnit) {
return desiredUnit.convert(elapsedNanos(), NANOSECONDS);
}
private static TimeUnit chooseUnit(long nanos) {
if (DAYS.convert(nanos, NANOSECONDS) > 0) {
return DAYS;
}
if (HOURS.convert(nanos, NANOSECONDS) > 0) {
return HOURS;
}
if (MINUTES.convert(nanos, NANOSECONDS) > 0) {
return MINUTES;
}
if (SECONDS.convert(nanos, NANOSECONDS) > 0) {
return SECONDS;
}
if (MILLISECONDS.convert(nanos, NANOSECONDS) > 0) {
return MILLISECONDS;
}
if (MICROSECONDS.convert(nanos, NANOSECONDS) > 0) {
return MICROSECONDS;
}
return NANOSECONDS;
}
private static String abbreviate(TimeUnit unit) {
switch (unit) {
case NANOSECONDS:
return "ns";
case MICROSECONDS:
return "\u03bcs"; // μs
case MILLISECONDS:
return "ms";
case SECONDS:
return "s";
case MINUTES:
return "min";
case HOURS:
return "h";
case DAYS:
return "d";
default:
throw new AssertionError();
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Stopwatch.java | Java | asf20 | 7,240 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.base;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
/**
* Static utility methods pertaining to {@code Predicate} instances.
*
* <p>All methods returns serializable predicates as long as they're given
* serializable parameters.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">the
* use of {@code Predicate}</a>.
*
* @author Kevin Bourrillion
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class Predicates {
private Predicates() {}
// TODO(kevinb): considering having these implement a VisitablePredicate
// interface which specifies an accept(PredicateVisitor) method.
/**
* Returns a predicate that always evaluates to {@code true}.
*/
@GwtCompatible(serializable = true)
public static <T> Predicate<T> alwaysTrue() {
return ObjectPredicate.ALWAYS_TRUE.withNarrowedType();
}
/**
* Returns a predicate that always evaluates to {@code false}.
*/
@GwtCompatible(serializable = true)
public static <T> Predicate<T> alwaysFalse() {
return ObjectPredicate.ALWAYS_FALSE.withNarrowedType();
}
/**
* Returns a predicate that evaluates to {@code true} if the object reference
* being tested is null.
*/
@GwtCompatible(serializable = true)
public static <T> Predicate<T> isNull() {
return ObjectPredicate.IS_NULL.withNarrowedType();
}
/**
* Returns a predicate that evaluates to {@code true} if the object reference
* being tested is not null.
*/
@GwtCompatible(serializable = true)
public static <T> Predicate<T> notNull() {
return ObjectPredicate.NOT_NULL.withNarrowedType();
}
/**
* Returns a predicate that evaluates to {@code true} if the given predicate
* evaluates to {@code false}.
*/
public static <T> Predicate<T> not(Predicate<T> predicate) {
return new NotPredicate<T>(predicate);
}
/**
* Returns a predicate that evaluates to {@code true} if each of its
* components evaluates to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a false
* predicate is found. It defensively copies the iterable passed in, so future
* changes to it won't alter the behavior of this predicate. If {@code
* components} is empty, the returned predicate will always evaluate to {@code
* true}.
*/
public static <T> Predicate<T> and(
Iterable<? extends Predicate<? super T>> components) {
return new AndPredicate<T>(defensiveCopy(components));
}
/**
* Returns a predicate that evaluates to {@code true} if each of its
* components evaluates to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a false
* predicate is found. It defensively copies the array passed in, so future
* changes to it won't alter the behavior of this predicate. If {@code
* components} is empty, the returned predicate will always evaluate to {@code
* true}.
*/
public static <T> Predicate<T> and(Predicate<? super T>... components) {
return new AndPredicate<T>(defensiveCopy(components));
}
/**
* Returns a predicate that evaluates to {@code true} if both of its
* components evaluate to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a false
* predicate is found.
*/
public static <T> Predicate<T> and(Predicate<? super T> first,
Predicate<? super T> second) {
return new AndPredicate<T>(Predicates.<T>asList(
checkNotNull(first), checkNotNull(second)));
}
/**
* Returns a predicate that evaluates to {@code true} if any one of its
* components evaluates to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a
* true predicate is found. It defensively copies the iterable passed in, so
* future changes to it won't alter the behavior of this predicate. If {@code
* components} is empty, the returned predicate will always evaluate to {@code
* false}.
*/
public static <T> Predicate<T> or(
Iterable<? extends Predicate<? super T>> components) {
return new OrPredicate<T>(defensiveCopy(components));
}
/**
* Returns a predicate that evaluates to {@code true} if any one of its
* components evaluates to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a
* true predicate is found. It defensively copies the array passed in, so
* future changes to it won't alter the behavior of this predicate. If {@code
* components} is empty, the returned predicate will always evaluate to {@code
* false}.
*/
public static <T> Predicate<T> or(Predicate<? super T>... components) {
return new OrPredicate<T>(defensiveCopy(components));
}
/**
* Returns a predicate that evaluates to {@code true} if either of its
* components evaluates to {@code true}. The components are evaluated in
* order, and evaluation will be "short-circuited" as soon as a
* true predicate is found.
*/
public static <T> Predicate<T> or(
Predicate<? super T> first, Predicate<? super T> second) {
return new OrPredicate<T>(Predicates.<T>asList(
checkNotNull(first), checkNotNull(second)));
}
/**
* Returns a predicate that evaluates to {@code true} if the object being
* tested {@code equals()} the given target or both are null.
*/
public static <T> Predicate<T> equalTo(@Nullable T target) {
return (target == null)
? Predicates.<T>isNull()
: new IsEqualToPredicate<T>(target);
}
/**
* Returns a predicate that evaluates to {@code true} if the object reference
* being tested is a member of the given collection. It does not defensively
* copy the collection passed in, so future changes to it will alter the
* behavior of the predicate.
*
* <p>This method can technically accept any {@code Collection<?>}, but using
* a typed collection helps prevent bugs. This approach doesn't block any
* potential users since it is always possible to use {@code
* Predicates.<Object>in()}.
*
* @param target the collection that may contain the function input
*/
public static <T> Predicate<T> in(Collection<? extends T> target) {
return new InPredicate<T>(target);
}
/**
* Returns the composition of a function and a predicate. For every {@code x},
* the generated predicate returns {@code predicate(function(x))}.
*
* @return the composition of the provided function and predicate
*/
public static <A, B> Predicate<A> compose(
Predicate<B> predicate, Function<A, ? extends B> function) {
return new CompositionPredicate<A, B>(predicate, function);
}
// End public API, begin private implementation classes.
// Package private for GWT serialization.
enum ObjectPredicate implements Predicate<Object> {
/** @see Predicates#alwaysTrue() */
ALWAYS_TRUE {
@Override public boolean apply(@Nullable Object o) {
return true;
}
@Override public String toString() {
return "Predicates.alwaysTrue()";
}
},
/** @see Predicates#alwaysFalse() */
ALWAYS_FALSE {
@Override public boolean apply(@Nullable Object o) {
return false;
}
@Override public String toString() {
return "Predicates.alwaysFalse()";
}
},
/** @see Predicates#isNull() */
IS_NULL {
@Override public boolean apply(@Nullable Object o) {
return o == null;
}
@Override public String toString() {
return "Predicates.isNull()";
}
},
/** @see Predicates#notNull() */
NOT_NULL {
@Override public boolean apply(@Nullable Object o) {
return o != null;
}
@Override public String toString() {
return "Predicates.notNull()";
}
};
@SuppressWarnings("unchecked") // safe contravariant cast
<T> Predicate<T> withNarrowedType() {
return (Predicate<T>) this;
}
}
/** @see Predicates#not(Predicate) */
private static class NotPredicate<T> implements Predicate<T>, Serializable {
final Predicate<T> predicate;
NotPredicate(Predicate<T> predicate) {
this.predicate = checkNotNull(predicate);
}
@Override
public boolean apply(@Nullable T t) {
return !predicate.apply(t);
}
@Override public int hashCode() {
return ~predicate.hashCode();
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof NotPredicate) {
NotPredicate<?> that = (NotPredicate<?>) obj;
return predicate.equals(that.predicate);
}
return false;
}
@Override public String toString() {
return "Predicates.not(" + predicate.toString() + ")";
}
private static final long serialVersionUID = 0;
}
private static final Joiner COMMA_JOINER = Joiner.on(',');
/** @see Predicates#and(Iterable) */
private static class AndPredicate<T> implements Predicate<T>, Serializable {
private final List<? extends Predicate<? super T>> components;
private AndPredicate(List<? extends Predicate<? super T>> components) {
this.components = components;
}
@Override
public boolean apply(@Nullable T t) {
// Avoid using the Iterator to avoid generating garbage (issue 820).
for (int i = 0; i < components.size(); i++) {
if (!components.get(i).apply(t)) {
return false;
}
}
return true;
}
@Override public int hashCode() {
// add a random number to avoid collisions with OrPredicate
return components.hashCode() + 0x12472c2c;
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof AndPredicate) {
AndPredicate<?> that = (AndPredicate<?>) obj;
return components.equals(that.components);
}
return false;
}
@Override public String toString() {
return "Predicates.and(" + COMMA_JOINER.join(components) + ")";
}
private static final long serialVersionUID = 0;
}
/** @see Predicates#or(Iterable) */
private static class OrPredicate<T> implements Predicate<T>, Serializable {
private final List<? extends Predicate<? super T>> components;
private OrPredicate(List<? extends Predicate<? super T>> components) {
this.components = components;
}
@Override
public boolean apply(@Nullable T t) {
// Avoid using the Iterator to avoid generating garbage (issue 820).
for (int i = 0; i < components.size(); i++) {
if (components.get(i).apply(t)) {
return true;
}
}
return false;
}
@Override public int hashCode() {
// add a random number to avoid collisions with AndPredicate
return components.hashCode() + 0x053c91cf;
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof OrPredicate) {
OrPredicate<?> that = (OrPredicate<?>) obj;
return components.equals(that.components);
}
return false;
}
@Override public String toString() {
return "Predicates.or(" + COMMA_JOINER.join(components) + ")";
}
private static final long serialVersionUID = 0;
}
/** @see Predicates#equalTo(Object) */
private static class IsEqualToPredicate<T>
implements Predicate<T>, Serializable {
private final T target;
private IsEqualToPredicate(T target) {
this.target = target;
}
@Override
public boolean apply(T t) {
return target.equals(t);
}
@Override public int hashCode() {
return target.hashCode();
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof IsEqualToPredicate) {
IsEqualToPredicate<?> that = (IsEqualToPredicate<?>) obj;
return target.equals(that.target);
}
return false;
}
@Override public String toString() {
return "Predicates.equalTo(" + target + ")";
}
private static final long serialVersionUID = 0;
}
/** @see Predicates#in(Collection) */
private static class InPredicate<T> implements Predicate<T>, Serializable {
private final Collection<?> target;
private InPredicate(Collection<?> target) {
this.target = checkNotNull(target);
}
@Override
public boolean apply(@Nullable T t) {
try {
return target.contains(t);
} catch (NullPointerException e) {
return false;
} catch (ClassCastException e) {
return false;
}
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof InPredicate) {
InPredicate<?> that = (InPredicate<?>) obj;
return target.equals(that.target);
}
return false;
}
@Override public int hashCode() {
return target.hashCode();
}
@Override public String toString() {
return "Predicates.in(" + target + ")";
}
private static final long serialVersionUID = 0;
}
/** @see Predicates#compose(Predicate, Function) */
private static class CompositionPredicate<A, B>
implements Predicate<A>, Serializable {
final Predicate<B> p;
final Function<A, ? extends B> f;
private CompositionPredicate(Predicate<B> p, Function<A, ? extends B> f) {
this.p = checkNotNull(p);
this.f = checkNotNull(f);
}
@Override
public boolean apply(@Nullable A a) {
return p.apply(f.apply(a));
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof CompositionPredicate) {
CompositionPredicate<?, ?> that = (CompositionPredicate<?, ?>) obj;
return f.equals(that.f) && p.equals(that.p);
}
return false;
}
@Override public int hashCode() {
return f.hashCode() ^ p.hashCode();
}
@Override public String toString() {
return p.toString() + "(" + f.toString() + ")";
}
private static final long serialVersionUID = 0;
}
private static <T> List<Predicate<? super T>> asList(
Predicate<? super T> first, Predicate<? super T> second) {
// TODO(kevinb): understand why we still get a warning despite @SafeVarargs!
return Arrays.<Predicate<? super T>>asList(first, second);
}
private static <T> List<T> defensiveCopy(T... array) {
return defensiveCopy(Arrays.asList(array));
}
static <T> List<T> defensiveCopy(Iterable<T> iterable) {
ArrayList<T> list = new ArrayList<T>();
for (T element : iterable) {
list.add(checkNotNull(element));
}
return list;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Predicates.java | Java | asf20 | 15,550 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.base;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import java.io.Serializable;
import javax.annotation.Nullable;
/**
* Utility methods for working with {@link Enum} instances.
*
* @author Steve McKay
*
* @since 9.0
*/
@GwtCompatible(emulated = true)
@Beta
public final class Enums {
private Enums() {}
/**
* Returns a {@link Function} that maps an {@link Enum} name to the associated {@code Enum}
* constant. The {@code Function} will return {@code null} if the {@code Enum} constant
* does not exist.
*
* @param enumClass the {@link Class} of the {@code Enum} declaring the constant values
* @deprecated Use {@link Enums#stringConverter} instead. Note that the string converter has
* slightly different behavior: it throws {@link IllegalArgumentException} if the enum
* constant does not exist rather than returning {@code null}. It also converts {@code null}
* to {@code null} rather than throwing {@link NullPointerException}. This method is
* scheduled for removal in Guava 18.0.
*/
@Deprecated
public static <T extends Enum<T>> Function<String, T> valueOfFunction(
Class<T> enumClass) {
return new ValueOfFunction<T>(enumClass);
}
/**
* A {@link Function} that maps an {@link Enum} name to the associated constant, or {@code null}
* if the constant does not exist.
*/
private static final class ValueOfFunction<T extends Enum<T>>
implements Function<String, T>, Serializable {
private final Class<T> enumClass;
private ValueOfFunction(Class<T> enumClass) {
this.enumClass = checkNotNull(enumClass);
}
@Override
public T apply(String value) {
try {
return Enum.valueOf(enumClass, value);
} catch (IllegalArgumentException e) {
return null;
}
}
@Override public boolean equals(@Nullable Object obj) {
return obj instanceof ValueOfFunction && enumClass.equals(((ValueOfFunction) obj).enumClass);
}
@Override public int hashCode() {
return enumClass.hashCode();
}
@Override public String toString() {
return "Enums.valueOf(" + enumClass + ")";
}
private static final long serialVersionUID = 0;
}
/**
* Returns an optional enum constant for the given type, using {@link Enum#valueOf}. If the
* constant does not exist, {@link Optional#absent} is returned. A common use case is for parsing
* user input or falling back to a default enum constant. For example,
* {@code Enums.getIfPresent(Country.class, countryInput).or(Country.DEFAULT);}
*
* @since 12.0
*/
public static <T extends Enum<T>> Optional<T> getIfPresent(Class<T> enumClass, String value) {
checkNotNull(enumClass);
checkNotNull(value);
try {
return Optional.of(Enum.valueOf(enumClass, value));
} catch (IllegalArgumentException iae) {
return Optional.absent();
}
}
/**
* Returns a converter that converts between strings and {@code enum} values of type
* {@code enumClass} using {@link Enum#valueOf(Class, String)} and {@link Enum#name()}. The
* converter will throw an {@code IllegalArgumentException} if the argument is not the name of
* any enum constant in the specified enum.
*
* @since 16.0
*/
public static <T extends Enum<T>> Converter<String, T> stringConverter(final Class<T> enumClass) {
return new StringConverter<T>(enumClass);
}
private static final class StringConverter<T extends Enum<T>>
extends Converter<String, T> implements Serializable {
private final Class<T> enumClass;
StringConverter(Class<T> enumClass) {
this.enumClass = checkNotNull(enumClass);
}
@Override
protected T doForward(String value) {
return Enum.valueOf(enumClass, value);
}
@Override
protected String doBackward(T enumValue) {
return enumValue.name();
}
@Override
public boolean equals(@Nullable Object object) {
if (object instanceof StringConverter) {
StringConverter<?> that = (StringConverter<?>) object;
return this.enumClass.equals(that.enumClass);
}
return false;
}
@Override
public int hashCode() {
return enumClass.hashCode();
}
@Override
public String toString() {
return "Enums.stringConverter(" + enumClass.getName() + ".class)";
}
private static final long serialVersionUID = 0L;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Enums.java | Java | asf20 | 5,166 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.base;
import java.util.concurrent.TimeUnit;
/**
* @author Jesse Wilson
*/
final class Platform {
static CharMatcher precomputeCharMatcher(CharMatcher matcher) {
// CharMatcher.precomputed() produces CharMatchers that are maybe a little
// faster (and that's debatable), but definitely more memory-hungry. We're
// choosing to turn .precomputed() into a no-op in GWT, because it doesn't
// seem to be a worthwhile tradeoff in a browser.
return matcher;
}
static long systemNanoTime() {
// System.nanoTime() is not available in GWT, so we get milliseconds
// and convert to nanos.
return TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
}
private Platform() {}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Platform.java | Java | asf20 | 1,347 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.base;
import com.google.common.annotations.GwtCompatible;
import java.nio.charset.Charset;
/**
* Contains constant definitions for the six standard {@link Charset} instances, which are
* guaranteed to be supported by all Java platform implementations.
*
* <p>Assuming you're free to choose, note that <b>{@link #UTF_8} is widely preferred</b>.
*
* <p>See the Guava User Guide article on <a
* href="http://code.google.com/p/guava-libraries/wiki/StringsExplained#Charsets">
* {@code Charsets}</a>.
*
* @author Mike Bostock
* @since 1.0
*/
@GwtCompatible(emulated = true)
public final class Charsets {
private Charsets() {}
/**
* UTF-8: eight-bit UCS Transformation Format.
*
*/
public static final Charset UTF_8 = Charset.forName("UTF-8");
/*
* Please do not add new Charset references to this class, unless those character encodings are
* part of the set required to be supported by all Java platform implementations! Any Charsets
* initialized here may cause unexpected delays when this class is loaded. See the Charset
* Javadocs for the list of built-in character encodings.
*/
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/base/super/com/google/common/base/Charsets.java | Java | asf20 | 1,759 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.util.Comparator;
import java.util.Iterator;
import java.util.SortedSet;
import javax.annotation.Nullable;
/**
* This class provides a skeletal implementation of the {@link SortedMultiset} interface.
*
* <p>The {@link #count} and {@link #size} implementations all iterate across the set returned by
* {@link Multiset#entrySet()}, as do many methods acting on the set returned by
* {@link #elementSet()}. Override those methods for better performance.
*
* @author Louis Wasserman
*/
@GwtCompatible(emulated = true)
abstract class AbstractSortedMultiset<E> extends AbstractMultiset<E> implements SortedMultiset<E> {
@GwtTransient final Comparator<? super E> comparator;
// needed for serialization
@SuppressWarnings("unchecked")
AbstractSortedMultiset() {
this((Comparator) Ordering.natural());
}
AbstractSortedMultiset(Comparator<? super E> comparator) {
this.comparator = checkNotNull(comparator);
}
@Override
public SortedSet<E> elementSet() {
return (SortedSet<E>) super.elementSet();
}
@Override
SortedSet<E> createElementSet() {
return new SortedMultisets.ElementSet<E>(this);
}
@Override
public Comparator<? super E> comparator() {
return comparator;
}
@Override
public Entry<E> firstEntry() {
Iterator<Entry<E>> entryIterator = entryIterator();
return entryIterator.hasNext() ? entryIterator.next() : null;
}
@Override
public Entry<E> lastEntry() {
Iterator<Entry<E>> entryIterator = descendingEntryIterator();
return entryIterator.hasNext() ? entryIterator.next() : null;
}
@Override
public Entry<E> pollFirstEntry() {
Iterator<Entry<E>> entryIterator = entryIterator();
if (entryIterator.hasNext()) {
Entry<E> result = entryIterator.next();
result = Multisets.immutableEntry(result.getElement(), result.getCount());
entryIterator.remove();
return result;
}
return null;
}
@Override
public Entry<E> pollLastEntry() {
Iterator<Entry<E>> entryIterator = descendingEntryIterator();
if (entryIterator.hasNext()) {
Entry<E> result = entryIterator.next();
result = Multisets.immutableEntry(result.getElement(), result.getCount());
entryIterator.remove();
return result;
}
return null;
}
@Override
public SortedMultiset<E> subMultiset(@Nullable E fromElement, BoundType fromBoundType,
@Nullable E toElement, BoundType toBoundType) {
// These are checked elsewhere, but NullPointerTester wants them checked eagerly.
checkNotNull(fromBoundType);
checkNotNull(toBoundType);
return tailMultiset(fromElement, fromBoundType).headMultiset(toElement, toBoundType);
}
abstract Iterator<Entry<E>> descendingEntryIterator();
Iterator<E> descendingIterator() {
return Multisets.iteratorImpl(descendingMultiset());
}
private transient SortedMultiset<E> descendingMultiset;
@Override
public SortedMultiset<E> descendingMultiset() {
SortedMultiset<E> result = descendingMultiset;
return (result == null) ? descendingMultiset = createDescendingMultiset() : result;
}
SortedMultiset<E> createDescendingMultiset() {
return new DescendingMultiset<E>() {
@Override
SortedMultiset<E> forwardMultiset() {
return AbstractSortedMultiset.this;
}
@Override
Iterator<Entry<E>> entryIterator() {
return descendingEntryIterator();
}
@Override
public Iterator<E> iterator() {
return descendingIterator();
}
};
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/AbstractSortedMultiset.java | Java | asf20 | 4,289 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.annotation.Nullable;
/**
* GWT emulation of {@link ImmutableSortedSet}.
*
* @author Hayward Chan
*/
public abstract class ImmutableSortedSet<E>
extends ForwardingImmutableSet<E> implements SortedSet<E>, SortedIterable<E> {
// TODO(cpovirk): split into ImmutableSortedSet/ForwardingImmutableSortedSet?
// In the non-emulated source, this is in ImmutableSortedSetFauxverideShim,
// which overrides ImmutableSet & which ImmutableSortedSet extends.
// It is necessary here because otherwise the builder() method
// would be inherited from the emulated ImmutableSet.
// TODO(cpovirk): should we be including other methods from the shim here and
// in ImmutableSortedMap?
@Deprecated public static <E> ImmutableSortedSet.Builder<E> builder() {
throw new UnsupportedOperationException();
}
// TODO: Can we find a way to remove this @SuppressWarnings even for eclipse?
@SuppressWarnings("unchecked")
private static final Comparator NATURAL_ORDER = Ordering.natural();
@SuppressWarnings("unchecked")
private static final ImmutableSortedSet<Object> NATURAL_EMPTY_SET =
new EmptyImmutableSortedSet<Object>(NATURAL_ORDER);
@SuppressWarnings("unchecked")
private static <E> ImmutableSortedSet<E> emptySet() {
return (ImmutableSortedSet<E>) NATURAL_EMPTY_SET;
}
static <E> ImmutableSortedSet<E> emptySet(
Comparator<? super E> comparator) {
checkNotNull(comparator);
if (NATURAL_ORDER.equals(comparator)) {
return emptySet();
} else {
return new EmptyImmutableSortedSet<E>(comparator);
}
}
public static <E> ImmutableSortedSet<E> of() {
return emptySet();
}
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E element) {
return ofInternal(Ordering.natural(), element);
}
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E e1, E e2) {
return ofInternal(Ordering.natural(), e1, e2);
}
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E e1, E e2, E e3) {
return ofInternal(Ordering.natural(), e1, e2, e3);
}
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E e1, E e2, E e3, E e4) {
return ofInternal(Ordering.natural(), e1, e2, e3, e4);
}
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E e1, E e2, E e3, E e4, E e5) {
return ofInternal(Ordering.natural(), e1, e2, e3, e4, e5);
}
@SuppressWarnings("unchecked")
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) {
int size = remaining.length + 6;
List<E> all = new ArrayList<E>(size);
Collections.addAll(all, e1, e2, e3, e4, e5, e6);
Collections.addAll(all, remaining);
// This is messed up. See TODO at top of file.
return ofInternal(Ordering.natural(), (E[]) all.toArray(new Comparable[0]));
}
private static <E> ImmutableSortedSet<E> ofInternal(
Comparator<? super E> comparator, E... elements) {
checkNotNull(elements);
switch (elements.length) {
case 0:
return emptySet(comparator);
default:
SortedSet<E> delegate = new TreeSet<E>(comparator);
for (E element : elements) {
checkNotNull(element);
delegate.add(element);
}
return new RegularImmutableSortedSet<E>(delegate, false);
}
}
public static <E> ImmutableSortedSet<E> copyOf(Collection<? extends E> elements) {
return copyOfInternal((Ordering<E>) Ordering.natural(), (Collection) elements, false);
}
public static <E> ImmutableSortedSet<E> copyOf(Iterable<? extends E> elements) {
return copyOfInternal((Ordering<E>) Ordering.natural(), (Iterable) elements, false);
}
public static <E> ImmutableSortedSet<E> copyOf(Iterator<? extends E> elements) {
return copyOfInternal((Ordering<E>) Ordering.natural(), (Iterator) elements);
}
public static <E extends Comparable<? super E>> ImmutableSortedSet<E> copyOf(
E[] elements) {
return ofInternal(Ordering.natural(), elements);
}
public static <E> ImmutableSortedSet<E> copyOf(
Comparator<? super E> comparator, Iterable<? extends E> elements) {
checkNotNull(comparator);
return copyOfInternal(comparator, elements, false);
}
public static <E> ImmutableSortedSet<E> copyOf(
Comparator<? super E> comparator, Collection<? extends E> elements) {
checkNotNull(comparator);
return copyOfInternal(comparator, elements, false);
}
public static <E> ImmutableSortedSet<E> copyOf(
Comparator<? super E> comparator, Iterator<? extends E> elements) {
checkNotNull(comparator);
return copyOfInternal(comparator, elements);
}
@SuppressWarnings("unchecked")
public static <E> ImmutableSortedSet<E> copyOfSorted(SortedSet<E> sortedSet) {
Comparator<? super E> comparator = sortedSet.comparator();
if (comparator == null) {
comparator = NATURAL_ORDER;
}
return copyOfInternal(comparator, sortedSet.iterator());
}
private static <E> ImmutableSortedSet<E> copyOfInternal(
Comparator<? super E> comparator, Iterable<? extends E> elements,
boolean fromSortedSet) {
checkNotNull(comparator);
boolean hasSameComparator
= fromSortedSet || hasSameComparator(elements, comparator);
if (hasSameComparator && (elements instanceof ImmutableSortedSet)) {
@SuppressWarnings("unchecked")
ImmutableSortedSet<E> result = (ImmutableSortedSet<E>) elements;
boolean isSubset = (result instanceof RegularImmutableSortedSet)
&& ((RegularImmutableSortedSet) result).isSubset;
if (!isSubset) {
// Only return the original copy if this immutable sorted set isn't
// a subset of another, to avoid memory leak.
return result;
}
}
return copyOfInternal(comparator, elements.iterator());
}
private static <E> ImmutableSortedSet<E> copyOfInternal(
Comparator<? super E> comparator, Iterator<? extends E> elements) {
checkNotNull(comparator);
if (!elements.hasNext()) {
return emptySet(comparator);
}
SortedSet<E> delegate = new TreeSet<E>(comparator);
while (elements.hasNext()) {
E element = elements.next();
checkNotNull(element);
delegate.add(element);
}
return new RegularImmutableSortedSet<E>(delegate, false);
}
private static boolean hasSameComparator(
Iterable<?> elements, Comparator<?> comparator) {
if (elements instanceof SortedSet) {
SortedSet<?> sortedSet = (SortedSet<?>) elements;
Comparator<?> comparator2 = sortedSet.comparator();
return (comparator2 == null)
? comparator == Ordering.natural()
: comparator.equals(comparator2);
}
return false;
}
// Assumes that delegate doesn't have null elements and comparator.
static <E> ImmutableSortedSet<E> unsafeDelegateSortedSet(
SortedSet<E> delegate, boolean isSubset) {
return delegate.isEmpty()
? emptySet(delegate.comparator())
: new RegularImmutableSortedSet<E>(delegate, isSubset);
}
// This reference is only used by GWT compiler to infer the elements of the
// set that needs to be serialized.
private Comparator<E> unusedComparatorForSerialization;
private E unusedElementForSerialization;
private transient final SortedSet<E> sortedDelegate;
/**
* Scary constructor for ContiguousSet. This constructor (in this file, the
* GWT emulation of ImmutableSortedSet) creates an empty sortedDelegate,
* which, in a vacuum, sets this object's contents to empty. By contrast,
* the non-GWT constructor with the same signature uses the comparator only
* as a comparator. It does NOT assume empty contents. (It requires an
* implementation of iterator() to define its contents, and methods like
* contains() are implemented in terms of that method (though they will
* likely be overridden by subclasses for performance reasons).) This means
* that a call to this method have can different behavior in GWT and non-GWT
* environments UNLESS subclasses are careful to always override all methods
* implemented in terms of sortedDelegate (except comparator()).
*/
ImmutableSortedSet(Comparator<? super E> comparator) {
this(Sets.newTreeSet(comparator));
}
ImmutableSortedSet(SortedSet<E> sortedDelegate) {
super(sortedDelegate);
this.sortedDelegate = Collections.unmodifiableSortedSet(sortedDelegate);
}
public Comparator<? super E> comparator() {
return sortedDelegate.comparator();
}
@Override // needed to unify SortedIterable and Collection iterator() methods
public UnmodifiableIterator<E> iterator() {
return super.iterator();
}
@Override
public Object[] toArray() {
return ObjectArrays.toArrayImpl(this);
}
@Override
public <T> T[] toArray(T[] other) {
return ObjectArrays.toArrayImpl(this, other);
}
@Override public boolean contains(@Nullable Object object) {
try {
// This set never contains null. We need to explicitly check here
// because some comparator might throw NPE (e.g. the natural ordering).
return object != null && sortedDelegate.contains(object);
} catch (ClassCastException e) {
return false;
}
}
@Override public boolean containsAll(Collection<?> targets) {
for (Object target : targets) {
if (target == null) {
// This set never contains null. We need to explicitly check here
// because some comparator might throw NPE (e.g. the natural ordering).
return false;
}
}
try {
return sortedDelegate.containsAll(targets);
} catch (ClassCastException e) {
return false;
}
}
public E first() {
return sortedDelegate.first();
}
public ImmutableSortedSet<E> headSet(E toElement) {
checkNotNull(toElement);
try {
return unsafeDelegateSortedSet(sortedDelegate.headSet(toElement), true);
} catch (IllegalArgumentException e) {
return emptySet(comparator());
}
}
E higher(E e) {
checkNotNull(e);
Iterator<E> iterator = tailSet(e).iterator();
while (iterator.hasNext()) {
E higher = iterator.next();
if (comparator().compare(e, higher) < 0) {
return higher;
}
}
return null;
}
ImmutableSortedSet<E> headSet(E toElement, boolean inclusive) {
checkNotNull(toElement);
if (inclusive) {
E tmp = higher(toElement);
if (tmp == null) {
return this;
}
toElement = tmp;
}
return headSet(toElement);
}
public E last() {
return sortedDelegate.last();
}
public ImmutableSortedSet<E> subSet(E fromElement, E toElement) {
return subSet(fromElement, true, toElement, false);
}
ImmutableSortedSet<E> subSet(E fromElement, boolean fromInclusive, E toElement,
boolean toInclusive) {
checkNotNull(fromElement);
checkNotNull(toElement);
int cmp = comparator().compare(fromElement, toElement);
checkArgument(cmp <= 0, "fromElement (%s) is less than toElement (%s)", fromElement, toElement);
if (cmp == 0 && !(fromInclusive && toInclusive)) {
return emptySet(comparator());
}
return tailSet(fromElement, fromInclusive).headSet(toElement, toInclusive);
}
public ImmutableSortedSet<E> tailSet(E fromElement) {
checkNotNull(fromElement);
try {
return unsafeDelegateSortedSet(sortedDelegate.tailSet(fromElement), true);
} catch (IllegalArgumentException e) {
return emptySet(comparator());
}
}
ImmutableSortedSet<E> tailSet(E fromElement, boolean inclusive) {
checkNotNull(fromElement);
if (!inclusive) {
E tmp = higher(fromElement);
if (tmp == null) {
return emptySet(comparator());
}
fromElement = tmp;
}
return tailSet(fromElement);
}
public static <E> Builder<E> orderedBy(Comparator<E> comparator) {
return new Builder<E>(comparator);
}
public static <E extends Comparable<?>> Builder<E> reverseOrder() {
return new Builder<E>(Ordering.natural().reverse());
}
public static <E extends Comparable<?>> Builder<E> naturalOrder() {
return new Builder<E>(Ordering.natural());
}
public static final class Builder<E> extends ImmutableSet.Builder<E> {
private final Comparator<? super E> comparator;
public Builder(Comparator<? super E> comparator) {
this.comparator = checkNotNull(comparator);
}
@Override public Builder<E> add(E element) {
super.add(element);
return this;
}
@Override public Builder<E> add(E... elements) {
super.add(elements);
return this;
}
@Override public Builder<E> addAll(Iterable<? extends E> elements) {
super.addAll(elements);
return this;
}
@Override public Builder<E> addAll(Iterator<? extends E> elements) {
super.addAll(elements);
return this;
}
@Override public ImmutableSortedSet<E> build() {
return copyOfInternal(comparator, contents.iterator());
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSortedSet.java | Java | asf20 | 14,244 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.Set;
/**
* GWT emulation of {@link RegularImmutableSet}.
*
* @author Hayward Chan
*/
final class RegularImmutableSet<E> extends ForwardingImmutableSet<E> {
RegularImmutableSet(Set<E> delegate) {
super(delegate);
// Required for GWT deserialization because the server-side implementation
// requires this.
checkArgument(delegate.size() >= 2);
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/RegularImmutableSet.java | Java | asf20 | 1,094 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.GwtCompatible;
import java.util.Comparator;
/**
* List returned by {@code ImmutableSortedSet.asList()} when the set isn't empty.
*
* @author Jared Levy
* @author Louis Wasserman
*/
@GwtCompatible(emulated = true)
@SuppressWarnings("serial")
final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
implements SortedIterable<E> {
ImmutableSortedAsList(
ImmutableSortedSet<E> backingSet, ImmutableList<E> backingList) {
super(backingSet, backingList);
}
@Override
ImmutableSortedSet<E> delegateCollection() {
return (ImmutableSortedSet<E>) super.delegateCollection();
}
@Override public Comparator<? super E> comparator() {
return delegateCollection().comparator();
}
// Override indexOf() and lastIndexOf() to be O(log N) instead of O(N).
@Override
public boolean contains(Object target) {
// Necessary for ISS's with comparators inconsistent with equals.
return indexOf(target) >= 0;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSortedAsList.java | Java | asf20 | 1,635 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Objects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nullable;
/**
* An immutable {@link SetMultimap} with reliable user-specified key and value
* iteration order. Does not permit null keys or values.
*
* <p>Unlike {@link Multimaps#unmodifiableSetMultimap(SetMultimap)}, which is
* a <i>view</i> of a separate multimap which can still change, an instance of
* {@code ImmutableSetMultimap} contains its own data and will <i>never</i>
* change. {@code ImmutableSetMultimap} is convenient for
* {@code public static final} multimaps ("constant multimaps") and also lets
* you easily make a "defensive copy" of a multimap provided to your class by
* a caller.
*
* <p><b>Note:</b> Although this class is not final, it cannot be subclassed as
* it has no public or protected constructors. Thus, instances of this class
* are guaranteed to be immutable.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained">
* immutable collections</a>.
*
* @author Mike Ward
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(serializable = true, emulated = true)
public class ImmutableSetMultimap<K, V>
extends ImmutableMultimap<K, V>
implements SetMultimap<K, V> {
/** Returns the empty multimap. */
// Casting is safe because the multimap will never hold any elements.
@SuppressWarnings("unchecked")
public static <K, V> ImmutableSetMultimap<K, V> of() {
return (ImmutableSetMultimap<K, V>) EmptyImmutableSetMultimap.INSTANCE;
}
/**
* Returns an immutable multimap containing a single entry.
*/
public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1) {
ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
builder.put(k1, v1);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
* Repeated occurrences of an entry (according to {@link Object#equals}) after
* the first are ignored.
*/
public static <K, V> ImmutableSetMultimap<K, V> of(K k1, V v1, K k2, V v2) {
ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
* Repeated occurrences of an entry (according to {@link Object#equals}) after
* the first are ignored.
*/
public static <K, V> ImmutableSetMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3) {
ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
* Repeated occurrences of an entry (according to {@link Object#equals}) after
* the first are ignored.
*/
public static <K, V> ImmutableSetMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
builder.put(k4, v4);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
* Repeated occurrences of an entry (according to {@link Object#equals}) after
* the first are ignored.
*/
public static <K, V> ImmutableSetMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
ImmutableSetMultimap.Builder<K, V> builder = ImmutableSetMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
builder.put(k4, v4);
builder.put(k5, v5);
return builder.build();
}
// looking for of() with > 5 entries? Use the builder instead.
/**
* Returns a new {@link Builder}.
*/
public static <K, V> Builder<K, V> builder() {
return new Builder<K, V>();
}
/**
* Multimap for {@link ImmutableSetMultimap.Builder} that maintains key
* and value orderings and performs better than {@link LinkedHashMultimap}.
*/
private static class BuilderMultimap<K, V> extends AbstractMapBasedMultimap<K, V> {
BuilderMultimap() {
super(new LinkedHashMap<K, Collection<V>>());
}
@Override Collection<V> createCollection() {
return Sets.newLinkedHashSet();
}
private static final long serialVersionUID = 0;
}
/**
* A builder for creating immutable {@code SetMultimap} instances, especially
* {@code public static final} multimaps ("constant multimaps"). Example:
* <pre> {@code
*
* static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP =
* new ImmutableSetMultimap.Builder<String, Integer>()
* .put("one", 1)
* .putAll("several", 1, 2, 3)
* .putAll("many", 1, 2, 3, 4, 5)
* .build();}</pre>
*
* <p>Builder instances can be reused; it is safe to call {@link #build} multiple
* times to build multiple multimaps in series. Each multimap contains the
* key-value mappings in the previously created multimaps.
*
* @since 2.0 (imported from Google Collections Library)
*/
public static final class Builder<K, V>
extends ImmutableMultimap.Builder<K, V> {
/**
* Creates a new builder. The returned builder is equivalent to the builder
* generated by {@link ImmutableSetMultimap#builder}.
*/
public Builder() {
builderMultimap = new BuilderMultimap<K, V>();
}
/**
* Adds a key-value mapping to the built multimap if it is not already
* present.
*/
@Override public Builder<K, V> put(K key, V value) {
builderMultimap.put(checkNotNull(key), checkNotNull(value));
return this;
}
/**
* Adds an entry to the built multimap if it is not already present.
*
* @since 11.0
*/
@Override public Builder<K, V> put(Entry<? extends K, ? extends V> entry) {
builderMultimap.put(
checkNotNull(entry.getKey()), checkNotNull(entry.getValue()));
return this;
}
@Override public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
Collection<V> collection = builderMultimap.get(checkNotNull(key));
for (V value : values) {
collection.add(checkNotNull(value));
}
return this;
}
@Override public Builder<K, V> putAll(K key, V... values) {
return putAll(key, Arrays.asList(values));
}
@Override public Builder<K, V> putAll(
Multimap<? extends K, ? extends V> multimap) {
for (Entry<? extends K, ? extends Collection<? extends V>> entry
: multimap.asMap().entrySet()) {
putAll(entry.getKey(), entry.getValue());
}
return this;
}
/**
* {@inheritDoc}
*
* @since 8.0
*/
@Override
public Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator) {
this.keyComparator = checkNotNull(keyComparator);
return this;
}
/**
* Specifies the ordering of the generated multimap's values for each key.
*
* <p>If this method is called, the sets returned by the {@code get()}
* method of the generated multimap and its {@link Multimap#asMap()} view
* are {@link ImmutableSortedSet} instances. However, serialization does not
* preserve that property, though it does maintain the key and value
* ordering.
*
* @since 8.0
*/
// TODO: Make serialization behavior consistent.
@Override
public Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator) {
super.orderValuesBy(valueComparator);
return this;
}
/**
* Returns a newly-created immutable set multimap.
*/
@Override public ImmutableSetMultimap<K, V> build() {
if (keyComparator != null) {
Multimap<K, V> sortedCopy = new BuilderMultimap<K, V>();
List<Map.Entry<K, Collection<V>>> entries = Lists.newArrayList(
builderMultimap.asMap().entrySet());
Collections.sort(
entries,
Ordering.from(keyComparator).<K>onKeys());
for (Map.Entry<K, Collection<V>> entry : entries) {
sortedCopy.putAll(entry.getKey(), entry.getValue());
}
builderMultimap = sortedCopy;
}
return copyOf(builderMultimap, valueComparator);
}
}
/**
* Returns an immutable set multimap containing the same mappings as
* {@code multimap}. The generated multimap's key and value orderings
* correspond to the iteration ordering of the {@code multimap.asMap()} view.
* Repeated occurrences of an entry in the multimap after the first are
* ignored.
*
* <p>Despite the method name, this method attempts to avoid actually copying
* the data when it is safe to do so. The exact circumstances under which a
* copy will or will not be performed are undocumented and subject to change.
*
* @throws NullPointerException if any key or value in {@code multimap} is
* null
*/
public static <K, V> ImmutableSetMultimap<K, V> copyOf(
Multimap<? extends K, ? extends V> multimap) {
return copyOf(multimap, null);
}
private static <K, V> ImmutableSetMultimap<K, V> copyOf(
Multimap<? extends K, ? extends V> multimap,
Comparator<? super V> valueComparator) {
checkNotNull(multimap); // eager for GWT
if (multimap.isEmpty() && valueComparator == null) {
return of();
}
if (multimap instanceof ImmutableSetMultimap) {
@SuppressWarnings("unchecked") // safe since multimap is not writable
ImmutableSetMultimap<K, V> kvMultimap
= (ImmutableSetMultimap<K, V>) multimap;
if (!kvMultimap.isPartialView()) {
return kvMultimap;
}
}
ImmutableMap.Builder<K, ImmutableSet<V>> builder = ImmutableMap.builder();
int size = 0;
for (Entry<? extends K, ? extends Collection<? extends V>> entry
: multimap.asMap().entrySet()) {
K key = entry.getKey();
Collection<? extends V> values = entry.getValue();
ImmutableSet<V> set = valueSet(valueComparator, values);
if (!set.isEmpty()) {
builder.put(key, set);
size += set.size();
}
}
return new ImmutableSetMultimap<K, V>(
builder.build(), size, valueComparator);
}
/**
* Returned by get() when a missing key is provided. Also holds the
* comparator, if any, used for values.
*/
private final transient ImmutableSet<V> emptySet;
ImmutableSetMultimap(ImmutableMap<K, ImmutableSet<V>> map, int size,
@Nullable Comparator<? super V> valueComparator) {
super(map, size);
this.emptySet = emptySet(valueComparator);
}
// views
/**
* Returns an immutable set of the values for the given key. If no mappings
* in the multimap have the provided key, an empty immutable set is returned.
* The values are in the same order as the parameters used to build this
* multimap.
*/
@Override public ImmutableSet<V> get(@Nullable K key) {
// This cast is safe as its type is known in constructor.
ImmutableSet<V> set = (ImmutableSet<V>) map.get(key);
return firstNonNull(set, emptySet);
}
private transient ImmutableSetMultimap<V, K> inverse;
/**
* {@inheritDoc}
*
* <p>Because an inverse of a set multimap cannot contain multiple pairs with
* the same key and value, this method returns an {@code ImmutableSetMultimap}
* rather than the {@code ImmutableMultimap} specified in the {@code
* ImmutableMultimap} class.
*
* @since 11.0
*/
public ImmutableSetMultimap<V, K> inverse() {
ImmutableSetMultimap<V, K> result = inverse;
return (result == null) ? (inverse = invert()) : result;
}
private ImmutableSetMultimap<V, K> invert() {
Builder<V, K> builder = builder();
for (Entry<K, V> entry : entries()) {
builder.put(entry.getValue(), entry.getKey());
}
ImmutableSetMultimap<V, K> invertedMultimap = builder.build();
invertedMultimap.inverse = this;
return invertedMultimap;
}
/**
* Guaranteed to throw an exception and leave the multimap unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated @Override public ImmutableSet<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
/**
* Guaranteed to throw an exception and leave the multimap unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated @Override public ImmutableSet<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
private transient ImmutableSet<Entry<K, V>> entries;
/**
* Returns an immutable collection of all key-value pairs in the multimap.
* Its iterator traverses the values for the first key, the values for the
* second key, and so on.
*/
@Override public ImmutableSet<Entry<K, V>> entries() {
ImmutableSet<Entry<K, V>> result = entries;
return (result == null)
? (entries = new EntrySet<K, V>(this))
: result;
}
private static final class EntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
private transient final ImmutableSetMultimap<K, V> multimap;
EntrySet(ImmutableSetMultimap<K, V> multimap) {
this.multimap = multimap;
}
@Override
public boolean contains(@Nullable Object object) {
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
return multimap.containsEntry(entry.getKey(), entry.getValue());
}
return false;
}
@Override
public int size() {
return multimap.size();
}
@Override
public UnmodifiableIterator<Entry<K, V>> iterator() {
return multimap.entryIterator();
}
@Override
boolean isPartialView() {
return false;
}
}
private static <V> ImmutableSet<V> valueSet(
@Nullable Comparator<? super V> valueComparator,
Collection<? extends V> values) {
return (valueComparator == null)
? ImmutableSet.copyOf(values)
: ImmutableSortedSet.copyOf(valueComparator, values);
}
private static <V> ImmutableSet<V> emptySet(
@Nullable Comparator<? super V> valueComparator) {
return (valueComparator == null)
? ImmutableSet.<V>of()
: ImmutableSortedSet.<V>emptySet(valueComparator);
}
@Nullable Comparator<? super V> valueComparator() {
return emptySet instanceof ImmutableSortedSet
? ((ImmutableSortedSet<V>) emptySet).comparator()
: null;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSetMultimap.java | Java | asf20 | 15,764 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.util.EnumMap;
import java.util.Map;
/**
* A {@code BiMap} backed by two {@code EnumMap} instances. Null keys and values
* are not permitted. An {@code EnumBiMap} and its inverse are both
* serializable.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#BiMap">
* {@code BiMap}</a>.
*
* @author Mike Bostock
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class EnumBiMap<K extends Enum<K>, V extends Enum<V>>
extends AbstractBiMap<K, V> {
private transient Class<K> keyType;
private transient Class<V> valueType;
/**
* Returns a new, empty {@code EnumBiMap} using the specified key and value
* types.
*
* @param keyType the key type
* @param valueType the value type
*/
public static <K extends Enum<K>, V extends Enum<V>> EnumBiMap<K, V>
create(Class<K> keyType, Class<V> valueType) {
return new EnumBiMap<K, V>(keyType, valueType);
}
/**
* Returns a new bimap with the same mappings as the specified map. If the
* specified map is an {@code EnumBiMap}, the new bimap has the same types as
* the provided map. Otherwise, the specified map must contain at least one
* mapping, in order to determine the key and value types.
*
* @param map the map whose mappings are to be placed in this map
* @throws IllegalArgumentException if map is not an {@code EnumBiMap}
* instance and contains no mappings
*/
public static <K extends Enum<K>, V extends Enum<V>> EnumBiMap<K, V>
create(Map<K, V> map) {
EnumBiMap<K, V> bimap = create(inferKeyType(map), inferValueType(map));
bimap.putAll(map);
return bimap;
}
private EnumBiMap(Class<K> keyType, Class<V> valueType) {
super(WellBehavedMap.wrap(new EnumMap<K, V>(keyType)),
WellBehavedMap.wrap(new EnumMap<V, K>(valueType)));
this.keyType = keyType;
this.valueType = valueType;
}
static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
if (map instanceof EnumBiMap) {
return ((EnumBiMap<K, ?>) map).keyType();
}
if (map instanceof EnumHashBiMap) {
return ((EnumHashBiMap<K, ?>) map).keyType();
}
checkArgument(!map.isEmpty());
return map.keySet().iterator().next().getDeclaringClass();
}
private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
if (map instanceof EnumBiMap) {
return ((EnumBiMap<?, V>) map).valueType;
}
checkArgument(!map.isEmpty());
return map.values().iterator().next().getDeclaringClass();
}
/** Returns the associated key type. */
public Class<K> keyType() {
return keyType;
}
/** Returns the associated value type. */
public Class<V> valueType() {
return valueType;
}
@Override
K checkKey(K key) {
return checkNotNull(key);
}
@Override
V checkValue(V value) {
return checkNotNull(value);
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/EnumBiMap.java | Java | asf20 | 3,803 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2.FilteredCollection;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable;
/**
* Static utility methods pertaining to {@link Set} instances. Also see this
* class's counterparts {@link Lists}, {@link Maps} and {@link Queues}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Sets">
* {@code Sets}</a>.
*
* @author Kevin Bourrillion
* @author Jared Levy
* @author Chris Povirk
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class Sets {
private Sets() {}
/**
* {@link AbstractSet} substitute without the potentially-quadratic
* {@code removeAll} implementation.
*/
abstract static class ImprovedAbstractSet<E> extends AbstractSet<E> {
@Override
public boolean removeAll(Collection<?> c) {
return removeAllImpl(this, c);
}
@Override
public boolean retainAll(Collection<?> c) {
return super.retainAll(checkNotNull(c)); // GWT compatibility
}
}
/**
* Returns an immutable set instance containing the given enum elements.
* Internally, the returned set will be backed by an {@link EnumSet}.
*
* <p>The iteration order of the returned set follows the enum's iteration
* order, not the order in which the elements are provided to the method.
*
* @param anElement one of the elements the set should contain
* @param otherElements the rest of the elements the set should contain
* @return an immutable set containing those elements, minus duplicates
*/
// http://code.google.com/p/google-web-toolkit/issues/detail?id=3028
@GwtCompatible(serializable = true)
public static <E extends Enum<E>> ImmutableSet<E> immutableEnumSet(
E anElement, E... otherElements) {
return ImmutableEnumSet.asImmutable(EnumSet.of(anElement, otherElements));
}
/**
* Returns an immutable set instance containing the given enum elements.
* Internally, the returned set will be backed by an {@link EnumSet}.
*
* <p>The iteration order of the returned set follows the enum's iteration
* order, not the order in which the elements appear in the given collection.
*
* @param elements the elements, all of the same {@code enum} type, that the
* set should contain
* @return an immutable set containing those elements, minus duplicates
*/
// http://code.google.com/p/google-web-toolkit/issues/detail?id=3028
@GwtCompatible(serializable = true)
public static <E extends Enum<E>> ImmutableSet<E> immutableEnumSet(
Iterable<E> elements) {
if (elements instanceof ImmutableEnumSet) {
return (ImmutableEnumSet<E>) elements;
} else if (elements instanceof Collection) {
Collection<E> collection = (Collection<E>) elements;
if (collection.isEmpty()) {
return ImmutableSet.of();
} else {
return ImmutableEnumSet.asImmutable(EnumSet.copyOf(collection));
}
} else {
Iterator<E> itr = elements.iterator();
if (itr.hasNext()) {
EnumSet<E> enumSet = EnumSet.of(itr.next());
Iterators.addAll(enumSet, itr);
return ImmutableEnumSet.asImmutable(enumSet);
} else {
return ImmutableSet.of();
}
}
}
/**
* Returns a new {@code EnumSet} instance containing the given elements.
* Unlike {@link EnumSet#copyOf(Collection)}, this method does not produce an
* exception on an empty collection, and it may be called on any iterable, not
* just a {@code Collection}.
*/
public static <E extends Enum<E>> EnumSet<E> newEnumSet(Iterable<E> iterable,
Class<E> elementType) {
EnumSet<E> set = EnumSet.noneOf(elementType);
Iterables.addAll(set, iterable);
return set;
}
// HashSet
/**
* Creates a <i>mutable</i>, empty {@code HashSet} instance.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSet#of()} instead.
*
* <p><b>Note:</b> if {@code E} is an {@link Enum} type, use {@link
* EnumSet#noneOf} instead.
*
* @return a new, empty {@code HashSet}
*/
public static <E> HashSet<E> newHashSet() {
return new HashSet<E>();
}
/**
* Creates a <i>mutable</i> {@code HashSet} instance containing the given
* elements in unspecified order.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use an overload of {@link ImmutableSet#of()} (for varargs) or
* {@link ImmutableSet#copyOf(Object[])} (for an array) instead.
*
* <p><b>Note:</b> if {@code E} is an {@link Enum} type, use {@link
* EnumSet#of(Enum, Enum[])} instead.
*
* @param elements the elements that the set should contain
* @return a new {@code HashSet} containing those elements (minus duplicates)
*/
public static <E> HashSet<E> newHashSet(E... elements) {
HashSet<E> set = newHashSetWithExpectedSize(elements.length);
Collections.addAll(set, elements);
return set;
}
/**
* Creates a {@code HashSet} instance, with a high enough "initial capacity"
* that it <i>should</i> hold {@code expectedSize} elements without growth.
* This behavior cannot be broadly guaranteed, but it is observed to be true
* for OpenJDK 1.6. It also can't be guaranteed that the method isn't
* inadvertently <i>oversizing</i> the returned set.
*
* @param expectedSize the number of elements you expect to add to the
* returned set
* @return a new, empty {@code HashSet} with enough capacity to hold {@code
* expectedSize} elements without resizing
* @throws IllegalArgumentException if {@code expectedSize} is negative
*/
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize) {
return new HashSet<E>(Maps.capacity(expectedSize));
}
/**
* Creates a <i>mutable</i> {@code HashSet} instance containing the given
* elements in unspecified order.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableSet#copyOf(Iterable)} instead.
*
* <p><b>Note:</b> if {@code E} is an {@link Enum} type, use
* {@link #newEnumSet(Iterable, Class)} instead.
*
* @param elements the elements that the set should contain
* @return a new {@code HashSet} containing those elements (minus duplicates)
*/
public static <E> HashSet<E> newHashSet(Iterable<? extends E> elements) {
return (elements instanceof Collection)
? new HashSet<E>(Collections2.cast(elements))
: newHashSet(elements.iterator());
}
/**
* Creates a <i>mutable</i> {@code HashSet} instance containing the given
* elements in unspecified order.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableSet#copyOf(Iterable)} instead.
*
* <p><b>Note:</b> if {@code E} is an {@link Enum} type, you should create an
* {@link EnumSet} instead.
*
* @param elements the elements that the set should contain
* @return a new {@code HashSet} containing those elements (minus duplicates)
*/
public static <E> HashSet<E> newHashSet(Iterator<? extends E> elements) {
HashSet<E> set = newHashSet();
Iterators.addAll(set, elements);
return set;
}
/**
* Creates a thread-safe set backed by a hash map. The set is backed by a
* {@link ConcurrentHashMap} instance, and thus carries the same concurrency
* guarantees.
*
* <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be
* used as an element. The set is serializable.
*
* @return a new, empty thread-safe {@code Set}
* @since 15.0
*/
public static <E> Set<E> newConcurrentHashSet() {
return newSetFromMap(new ConcurrentHashMap<E, Boolean>());
}
/**
* Creates a thread-safe set backed by a hash map and containing the given
* elements. The set is backed by a {@link ConcurrentHashMap} instance, and
* thus carries the same concurrency guarantees.
*
* <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be
* used as an element. The set is serializable.
*
* @param elements the elements that the set should contain
* @return a new thread-safe set containing those elements (minus duplicates)
* @throws NullPointerException if {@code elements} or any of its contents is
* null
* @since 15.0
*/
public static <E> Set<E> newConcurrentHashSet(
Iterable<? extends E> elements) {
Set<E> set = newConcurrentHashSet();
Iterables.addAll(set, elements);
return set;
}
// LinkedHashSet
/**
* Creates a <i>mutable</i>, empty {@code LinkedHashSet} instance.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSet#of()} instead.
*
* @return a new, empty {@code LinkedHashSet}
*/
public static <E> LinkedHashSet<E> newLinkedHashSet() {
return new LinkedHashSet<E>();
}
/**
* Creates a {@code LinkedHashSet} instance, with a high enough "initial
* capacity" that it <i>should</i> hold {@code expectedSize} elements without
* growth. This behavior cannot be broadly guaranteed, but it is observed to
* be true for OpenJDK 1.6. It also can't be guaranteed that the method isn't
* inadvertently <i>oversizing</i> the returned set.
*
* @param expectedSize the number of elements you expect to add to the
* returned set
* @return a new, empty {@code LinkedHashSet} with enough capacity to hold
* {@code expectedSize} elements without resizing
* @throws IllegalArgumentException if {@code expectedSize} is negative
* @since 11.0
*/
public static <E> LinkedHashSet<E> newLinkedHashSetWithExpectedSize(
int expectedSize) {
return new LinkedHashSet<E>(Maps.capacity(expectedSize));
}
/**
* Creates a <i>mutable</i> {@code LinkedHashSet} instance containing the
* given elements in order.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableSet#copyOf(Iterable)} instead.
*
* @param elements the elements that the set should contain, in order
* @return a new {@code LinkedHashSet} containing those elements (minus
* duplicates)
*/
public static <E> LinkedHashSet<E> newLinkedHashSet(
Iterable<? extends E> elements) {
if (elements instanceof Collection) {
return new LinkedHashSet<E>(Collections2.cast(elements));
}
LinkedHashSet<E> set = newLinkedHashSet();
Iterables.addAll(set, elements);
return set;
}
// TreeSet
/**
* Creates a <i>mutable</i>, empty {@code TreeSet} instance sorted by the
* natural sort ordering of its elements.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSortedSet#of()} instead.
*
* @return a new, empty {@code TreeSet}
*/
public static <E extends Comparable> TreeSet<E> newTreeSet() {
return new TreeSet<E>();
}
/**
* Creates a <i>mutable</i> {@code TreeSet} instance containing the given
* elements sorted by their natural ordering.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSortedSet#copyOf(Iterable)} instead.
*
* <p><b>Note:</b> If {@code elements} is a {@code SortedSet} with an explicit
* comparator, this method has different behavior than
* {@link TreeSet#TreeSet(SortedSet)}, which returns a {@code TreeSet} with
* that comparator.
*
* @param elements the elements that the set should contain
* @return a new {@code TreeSet} containing those elements (minus duplicates)
*/
public static <E extends Comparable> TreeSet<E> newTreeSet(
Iterable<? extends E> elements) {
TreeSet<E> set = newTreeSet();
Iterables.addAll(set, elements);
return set;
}
/**
* Creates a <i>mutable</i>, empty {@code TreeSet} instance with the given
* comparator.
*
* <p><b>Note:</b> if mutability is not required, use {@code
* ImmutableSortedSet.orderedBy(comparator).build()} instead.
*
* @param comparator the comparator to use to sort the set
* @return a new, empty {@code TreeSet}
* @throws NullPointerException if {@code comparator} is null
*/
public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator) {
return new TreeSet<E>(checkNotNull(comparator));
}
/**
* Creates an empty {@code Set} that uses identity to determine equality. It
* compares object references, instead of calling {@code equals}, to
* determine whether a provided object matches an element in the set. For
* example, {@code contains} returns {@code false} when passed an object that
* equals a set member, but isn't the same instance. This behavior is similar
* to the way {@code IdentityHashMap} handles key lookups.
*
* @since 8.0
*/
public static <E> Set<E> newIdentityHashSet() {
return Sets.newSetFromMap(Maps.<E, Boolean>newIdentityHashMap());
}
/**
* Creates an {@code EnumSet} consisting of all enum values that are not in
* the specified collection. If the collection is an {@link EnumSet}, this
* method has the same behavior as {@link EnumSet#complementOf}. Otherwise,
* the specified collection must contain at least one element, in order to
* determine the element type. If the collection could be empty, use
* {@link #complementOf(Collection, Class)} instead of this method.
*
* @param collection the collection whose complement should be stored in the
* enum set
* @return a new, modifiable {@code EnumSet} containing all values of the enum
* that aren't present in the given collection
* @throws IllegalArgumentException if {@code collection} is not an
* {@code EnumSet} instance and contains no elements
*/
public static <E extends Enum<E>> EnumSet<E> complementOf(
Collection<E> collection) {
if (collection instanceof EnumSet) {
return EnumSet.complementOf((EnumSet<E>) collection);
}
checkArgument(!collection.isEmpty(),
"collection is empty; use the other version of this method");
Class<E> type = collection.iterator().next().getDeclaringClass();
return makeComplementByHand(collection, type);
}
/**
* Creates an {@code EnumSet} consisting of all enum values that are not in
* the specified collection. This is equivalent to
* {@link EnumSet#complementOf}, but can act on any input collection, as long
* as the elements are of enum type.
*
* @param collection the collection whose complement should be stored in the
* {@code EnumSet}
* @param type the type of the elements in the set
* @return a new, modifiable {@code EnumSet} initially containing all the
* values of the enum not present in the given collection
*/
public static <E extends Enum<E>> EnumSet<E> complementOf(
Collection<E> collection, Class<E> type) {
checkNotNull(collection);
return (collection instanceof EnumSet)
? EnumSet.complementOf((EnumSet<E>) collection)
: makeComplementByHand(collection, type);
}
private static <E extends Enum<E>> EnumSet<E> makeComplementByHand(
Collection<E> collection, Class<E> type) {
EnumSet<E> result = EnumSet.allOf(type);
result.removeAll(collection);
return result;
}
/**
* Returns a set backed by the specified map. The resulting set displays
* the same ordering, concurrency, and performance characteristics as the
* backing map. In essence, this factory method provides a {@link Set}
* implementation corresponding to any {@link Map} implementation. There is no
* need to use this method on a {@link Map} implementation that already has a
* corresponding {@link Set} implementation (such as {@link java.util.HashMap}
* or {@link java.util.TreeMap}).
*
* <p>Each method invocation on the set returned by this method results in
* exactly one method invocation on the backing map or its {@code keySet}
* view, with one exception. The {@code addAll} method is implemented as a
* sequence of {@code put} invocations on the backing map.
*
* <p>The specified map must be empty at the time this method is invoked,
* and should not be accessed directly after this method returns. These
* conditions are ensured if the map is created empty, passed directly
* to this method, and no reference to the map is retained, as illustrated
* in the following code fragment: <pre> {@code
*
* Set<Object> identityHashSet = Sets.newSetFromMap(
* new IdentityHashMap<Object, Boolean>());}</pre>
*
* <p>This method has the same behavior as the JDK 6 method
* {@code Collections.newSetFromMap()}. The returned set is serializable if
* the backing map is.
*
* @param map the backing map
* @return the set backed by the map
* @throws IllegalArgumentException if {@code map} is not empty
*/
public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) {
return Platform.newSetFromMap(map);
}
/**
* An unmodifiable view of a set which may be backed by other sets; this view
* will change as the backing sets do. Contains methods to copy the data into
* a new set which will then remain stable. There is usually no reason to
* retain a reference of type {@code SetView}; typically, you either use it
* as a plain {@link Set}, or immediately invoke {@link #immutableCopy} or
* {@link #copyInto} and forget the {@code SetView} itself.
*
* @since 2.0 (imported from Google Collections Library)
*/
public abstract static class SetView<E> extends AbstractSet<E> {
private SetView() {} // no subclasses but our own
/**
* Returns an immutable copy of the current contents of this set view.
* Does not support null elements.
*
* <p><b>Warning:</b> this may have unexpected results if a backing set of
* this view uses a nonstandard notion of equivalence, for example if it is
* a {@link TreeSet} using a comparator that is inconsistent with {@link
* Object#equals(Object)}.
*/
public ImmutableSet<E> immutableCopy() {
return ImmutableSet.copyOf(this);
}
/**
* Copies the current contents of this set view into an existing set. This
* method has equivalent behavior to {@code set.addAll(this)}, assuming that
* all the sets involved are based on the same notion of equivalence.
*
* @return a reference to {@code set}, for convenience
*/
// Note: S should logically extend Set<? super E> but can't due to either
// some javac bug or some weirdness in the spec, not sure which.
public <S extends Set<E>> S copyInto(S set) {
set.addAll(this);
return set;
}
}
/**
* Returns an unmodifiable <b>view</b> of the union of two sets. The returned
* set contains all elements that are contained in either backing set.
* Iterating over the returned set iterates first over all the elements of
* {@code set1}, then over each element of {@code set2}, in order, that is not
* contained in {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based on
* different equivalence relations (as {@link HashSet}, {@link TreeSet}, and
* the {@link Map#keySet} of an {@code IdentityHashMap} all are).
*
* <p><b>Note:</b> The returned view performs better when {@code set1} is the
* smaller of the two sets. If you have reason to believe one of your sets
* will generally be smaller than the other, pass it first.
*
* <p>Further, note that the current implementation is not suitable for nested
* {@code union} views, i.e. the following should be avoided when in a loop:
* {@code union = Sets.union(union, anotherSet);}, since iterating over the resulting
* set has a cubic complexity to the depth of the nesting.
*/
public static <E> SetView<E> union(
final Set<? extends E> set1, final Set<? extends E> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Set<? extends E> set2minus1 = difference(set2, set1);
return new SetView<E>() {
@Override public int size() {
return set1.size() + set2minus1.size();
}
@Override public boolean isEmpty() {
return set1.isEmpty() && set2.isEmpty();
}
@Override public Iterator<E> iterator() {
return Iterators.unmodifiableIterator(
Iterators.concat(set1.iterator(), set2minus1.iterator()));
}
@Override public boolean contains(Object object) {
return set1.contains(object) || set2.contains(object);
}
@Override public <S extends Set<E>> S copyInto(S set) {
set.addAll(set1);
set.addAll(set2);
return set;
}
@Override public ImmutableSet<E> immutableCopy() {
return new ImmutableSet.Builder<E>()
.addAll(set1).addAll(set2).build();
}
};
}
/**
* Returns an unmodifiable <b>view</b> of the intersection of two sets. The
* returned set contains all elements that are contained by both backing sets.
* The iteration order of the returned set matches that of {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based
* on different equivalence relations (as {@code HashSet}, {@code TreeSet},
* and the keySet of an {@code IdentityHashMap} all are).
*
* <p><b>Note:</b> The returned view performs slightly better when {@code
* set1} is the smaller of the two sets. If you have reason to believe one of
* your sets will generally be smaller than the other, pass it first.
* Unfortunately, since this method sets the generic type of the returned set
* based on the type of the first set passed, this could in rare cases force
* you to make a cast, for example: <pre> {@code
*
* Set<Object> aFewBadObjects = ...
* Set<String> manyBadStrings = ...
*
* // impossible for a non-String to be in the intersection
* SuppressWarnings("unchecked")
* Set<String> badStrings = (Set) Sets.intersection(
* aFewBadObjects, manyBadStrings);}</pre>
*
* <p>This is unfortunate, but should come up only very rarely.
*/
public static <E> SetView<E> intersection(
final Set<E> set1, final Set<?> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Predicate<Object> inSet2 = Predicates.in(set2);
return new SetView<E>() {
@Override public Iterator<E> iterator() {
return Iterators.filter(set1.iterator(), inSet2);
}
@Override public int size() {
return Iterators.size(iterator());
}
@Override public boolean isEmpty() {
return !iterator().hasNext();
}
@Override public boolean contains(Object object) {
return set1.contains(object) && set2.contains(object);
}
@Override public boolean containsAll(Collection<?> collection) {
return set1.containsAll(collection)
&& set2.containsAll(collection);
}
};
}
/**
* Returns an unmodifiable <b>view</b> of the difference of two sets. The
* returned set contains all elements that are contained by {@code set1} and
* not contained by {@code set2}. {@code set2} may also contain elements not
* present in {@code set1}; these are simply ignored. The iteration order of
* the returned set matches that of {@code set1}.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based
* on different equivalence relations (as {@code HashSet}, {@code TreeSet},
* and the keySet of an {@code IdentityHashMap} all are).
*/
public static <E> SetView<E> difference(
final Set<E> set1, final Set<?> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
final Predicate<Object> notInSet2 = Predicates.not(Predicates.in(set2));
return new SetView<E>() {
@Override public Iterator<E> iterator() {
return Iterators.filter(set1.iterator(), notInSet2);
}
@Override public int size() {
return Iterators.size(iterator());
}
@Override public boolean isEmpty() {
return set2.containsAll(set1);
}
@Override public boolean contains(Object element) {
return set1.contains(element) && !set2.contains(element);
}
};
}
/**
* Returns an unmodifiable <b>view</b> of the symmetric difference of two
* sets. The returned set contains all elements that are contained in either
* {@code set1} or {@code set2} but not in both. The iteration order of the
* returned set is undefined.
*
* <p>Results are undefined if {@code set1} and {@code set2} are sets based
* on different equivalence relations (as {@code HashSet}, {@code TreeSet},
* and the keySet of an {@code IdentityHashMap} all are).
*
* @since 3.0
*/
public static <E> SetView<E> symmetricDifference(
Set<? extends E> set1, Set<? extends E> set2) {
checkNotNull(set1, "set1");
checkNotNull(set2, "set2");
// TODO(kevinb): Replace this with a more efficient implementation
return difference(union(set1, set2), intersection(set1, set2));
}
/**
* Returns the elements of {@code unfiltered} that satisfy a predicate. The
* returned set is a live view of {@code unfiltered}; changes to one affect
* the other.
*
* <p>The resulting set's iterator does not support {@code remove()}, but all
* other set methods are supported. When given an element that doesn't satisfy
* the predicate, the set's {@code add()} and {@code addAll()} methods throw
* an {@link IllegalArgumentException}. When methods such as {@code
* removeAll()} and {@code clear()} are called on the filtered set, only
* elements that satisfy the filter will be removed from the underlying set.
*
* <p>The returned set isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered set's methods, such as {@code size()}, iterate
* across every element in the underlying set and determine which elements
* satisfy the filter. When a live view is <i>not</i> needed, it may be faster
* to copy {@code Iterables.filter(unfiltered, predicate)} and use the copy.
*
* <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such
* as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
* with equals. (See {@link Iterables#filter(Iterable, Class)} for related
* functionality.)
*/
// TODO(kevinb): how to omit that last sentence when building GWT javadoc?
public static <E> Set<E> filter(
Set<E> unfiltered, Predicate<? super E> predicate) {
if (unfiltered instanceof SortedSet) {
return filter((SortedSet<E>) unfiltered, predicate);
}
if (unfiltered instanceof FilteredSet) {
// Support clear(), removeAll(), and retainAll() when filtering a filtered
// collection.
FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
Predicate<E> combinedPredicate
= Predicates.<E>and(filtered.predicate, predicate);
return new FilteredSet<E>(
(Set<E>) filtered.unfiltered, combinedPredicate);
}
return new FilteredSet<E>(
checkNotNull(unfiltered), checkNotNull(predicate));
}
private static class FilteredSet<E> extends FilteredCollection<E>
implements Set<E> {
FilteredSet(Set<E> unfiltered, Predicate<? super E> predicate) {
super(unfiltered, predicate);
}
@Override public boolean equals(@Nullable Object object) {
return equalsImpl(this, object);
}
@Override public int hashCode() {
return hashCodeImpl(this);
}
}
/**
* Returns the elements of a {@code SortedSet}, {@code unfiltered}, that
* satisfy a predicate. The returned set is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting set's iterator does not support {@code remove()}, but all
* other set methods are supported. When given an element that doesn't satisfy
* the predicate, the set's {@code add()} and {@code addAll()} methods throw
* an {@link IllegalArgumentException}. When methods such as
* {@code removeAll()} and {@code clear()} are called on the filtered set,
* only elements that satisfy the filter will be removed from the underlying
* set.
*
* <p>The returned set isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered set's methods, such as {@code size()}, iterate across
* every element in the underlying set and determine which elements satisfy
* the filter. When a live view is <i>not</i> needed, it may be faster to copy
* {@code Iterables.filter(unfiltered, predicate)} and use the copy.
*
* <p><b>Warning:</b> {@code predicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such as
* {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent with
* equals. (See {@link Iterables#filter(Iterable, Class)} for related
* functionality.)
*
* @since 11.0
*/
public static <E> SortedSet<E> filter(
SortedSet<E> unfiltered, Predicate<? super E> predicate) {
return Platform.setsFilterSortedSet(unfiltered, predicate);
}
static <E> SortedSet<E> filterSortedIgnoreNavigable(
SortedSet<E> unfiltered, Predicate<? super E> predicate) {
if (unfiltered instanceof FilteredSet) {
// Support clear(), removeAll(), and retainAll() when filtering a filtered
// collection.
FilteredSet<E> filtered = (FilteredSet<E>) unfiltered;
Predicate<E> combinedPredicate
= Predicates.<E>and(filtered.predicate, predicate);
return new FilteredSortedSet<E>(
(SortedSet<E>) filtered.unfiltered, combinedPredicate);
}
return new FilteredSortedSet<E>(
checkNotNull(unfiltered), checkNotNull(predicate));
}
private static class FilteredSortedSet<E> extends FilteredSet<E>
implements SortedSet<E> {
FilteredSortedSet(SortedSet<E> unfiltered, Predicate<? super E> predicate) {
super(unfiltered, predicate);
}
@Override
public Comparator<? super E> comparator() {
return ((SortedSet<E>) unfiltered).comparator();
}
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).subSet(fromElement, toElement),
predicate);
}
@Override
public SortedSet<E> headSet(E toElement) {
return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).headSet(toElement), predicate);
}
@Override
public SortedSet<E> tailSet(E fromElement) {
return new FilteredSortedSet<E>(((SortedSet<E>) unfiltered).tailSet(fromElement), predicate);
}
@Override
public E first() {
return iterator().next();
}
@Override
public E last() {
SortedSet<E> sortedUnfiltered = (SortedSet<E>) unfiltered;
while (true) {
E element = sortedUnfiltered.last();
if (predicate.apply(element)) {
return element;
}
sortedUnfiltered = sortedUnfiltered.headSet(element);
}
}
}
/**
* Returns every possible list that can be formed by choosing one element
* from each of the given sets in order; the "n-ary
* <a href="http://en.wikipedia.org/wiki/Cartesian_product">Cartesian
* product</a>" of the sets. For example: <pre> {@code
*
* Sets.cartesianProduct(ImmutableList.of(
* ImmutableSet.of(1, 2),
* ImmutableSet.of("A", "B", "C")))}</pre>
*
* <p>returns a set containing six lists:
*
* <ul>
* <li>{@code ImmutableList.of(1, "A")}
* <li>{@code ImmutableList.of(1, "B")}
* <li>{@code ImmutableList.of(1, "C")}
* <li>{@code ImmutableList.of(2, "A")}
* <li>{@code ImmutableList.of(2, "B")}
* <li>{@code ImmutableList.of(2, "C")}
* </ul>
*
* <p>The result is guaranteed to be in the "traditional", lexicographical
* order for Cartesian products that you would get from nesting for loops:
* <pre> {@code
*
* for (B b0 : sets.get(0)) {
* for (B b1 : sets.get(1)) {
* ...
* ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
* // operate on tuple
* }
* }}</pre>
*
* <p>Note that if any input set is empty, the Cartesian product will also be
* empty. If no sets at all are provided (an empty list), the resulting
* Cartesian product has one element, an empty list (counter-intuitive, but
* mathematically consistent).
*
* <p><i>Performance notes:</i> while the cartesian product of sets of size
* {@code m, n, p} is a set of size {@code m x n x p}, its actual memory
* consumption is much smaller. When the cartesian set is constructed, the
* input sets are merely copied. Only as the resulting set is iterated are the
* individual lists created, and these are not retained after iteration.
*
* @param sets the sets to choose elements from, in the order that
* the elements chosen from those sets should appear in the resulting
* lists
* @param <B> any common base class shared by all axes (often just {@link
* Object})
* @return the Cartesian product, as an immutable set containing immutable
* lists
* @throws NullPointerException if {@code sets}, any one of the {@code sets},
* or any element of a provided set is null
* @since 2.0
*/
public static <B> Set<List<B>> cartesianProduct(
List<? extends Set<? extends B>> sets) {
return CartesianSet.create(sets);
}
/**
* Returns every possible list that can be formed by choosing one element
* from each of the given sets in order; the "n-ary
* <a href="http://en.wikipedia.org/wiki/Cartesian_product">Cartesian
* product</a>" of the sets. For example: <pre> {@code
*
* Sets.cartesianProduct(
* ImmutableSet.of(1, 2),
* ImmutableSet.of("A", "B", "C"))}</pre>
*
* <p>returns a set containing six lists:
*
* <ul>
* <li>{@code ImmutableList.of(1, "A")}
* <li>{@code ImmutableList.of(1, "B")}
* <li>{@code ImmutableList.of(1, "C")}
* <li>{@code ImmutableList.of(2, "A")}
* <li>{@code ImmutableList.of(2, "B")}
* <li>{@code ImmutableList.of(2, "C")}
* </ul>
*
* <p>The result is guaranteed to be in the "traditional", lexicographical
* order for Cartesian products that you would get from nesting for loops:
* <pre> {@code
*
* for (B b0 : sets.get(0)) {
* for (B b1 : sets.get(1)) {
* ...
* ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
* // operate on tuple
* }
* }}</pre>
*
* <p>Note that if any input set is empty, the Cartesian product will also be
* empty. If no sets at all are provided (an empty list), the resulting
* Cartesian product has one element, an empty list (counter-intuitive, but
* mathematically consistent).
*
* <p><i>Performance notes:</i> while the cartesian product of sets of size
* {@code m, n, p} is a set of size {@code m x n x p}, its actual memory
* consumption is much smaller. When the cartesian set is constructed, the
* input sets are merely copied. Only as the resulting set is iterated are the
* individual lists created, and these are not retained after iteration.
*
* @param sets the sets to choose elements from, in the order that
* the elements chosen from those sets should appear in the resulting
* lists
* @param <B> any common base class shared by all axes (often just {@link
* Object})
* @return the Cartesian product, as an immutable set containing immutable
* lists
* @throws NullPointerException if {@code sets}, any one of the {@code sets},
* or any element of a provided set is null
* @since 2.0
*/
public static <B> Set<List<B>> cartesianProduct(
Set<? extends B>... sets) {
return cartesianProduct(Arrays.asList(sets));
}
private static final class CartesianSet<E>
extends ForwardingCollection<List<E>> implements Set<List<E>> {
private transient final ImmutableList<ImmutableSet<E>> axes;
private transient final CartesianList<E> delegate;
static <E> Set<List<E>> create(List<? extends Set<? extends E>> sets) {
ImmutableList.Builder<ImmutableSet<E>> axesBuilder =
new ImmutableList.Builder<ImmutableSet<E>>(sets.size());
for (Set<? extends E> set : sets) {
ImmutableSet<E> copy = ImmutableSet.copyOf(set);
if (copy.isEmpty()) {
return ImmutableSet.of();
}
axesBuilder.add(copy);
}
final ImmutableList<ImmutableSet<E>> axes = axesBuilder.build();
ImmutableList<List<E>> listAxes = new ImmutableList<List<E>>() {
@Override
public int size() {
return axes.size();
}
@Override
public List<E> get(int index) {
return axes.get(index).asList();
}
@Override
boolean isPartialView() {
return true;
}
};
return new CartesianSet<E>(axes, new CartesianList<E>(listAxes));
}
private CartesianSet(
ImmutableList<ImmutableSet<E>> axes, CartesianList<E> delegate) {
this.axes = axes;
this.delegate = delegate;
}
@Override
protected Collection<List<E>> delegate() {
return delegate;
}
@Override public boolean equals(@Nullable Object object) {
// Warning: this is broken if size() == 0, so it is critical that we
// substitute an empty ImmutableSet to the user in place of this
if (object instanceof CartesianSet) {
CartesianSet<?> that = (CartesianSet<?>) object;
return this.axes.equals(that.axes);
}
return super.equals(object);
}
@Override
public int hashCode() {
// Warning: this is broken if size() == 0, so it is critical that we
// substitute an empty ImmutableSet to the user in place of this
// It's a weird formula, but tests prove it works.
int adjust = size() - 1;
for (int i = 0; i < axes.size(); i++) {
adjust *= 31;
adjust = ~~adjust;
// in GWT, we have to deal with integer overflow carefully
}
int hash = 1;
for (Set<E> axis : axes) {
hash = 31 * hash + (size() / axis.size() * axis.hashCode());
hash = ~~hash;
}
hash += adjust;
return ~~hash;
}
}
/**
* Returns the set of all possible subsets of {@code set}. For example,
* {@code powerSet(ImmutableSet.of(1, 2))} returns the set {@code {{},
* {1}, {2}, {1, 2}}}.
*
* <p>Elements appear in these subsets in the same iteration order as they
* appeared in the input set. The order in which these subsets appear in the
* outer set is undefined. Note that the power set of the empty set is not the
* empty set, but a one-element set containing the empty set.
*
* <p>The returned set and its constituent sets use {@code equals} to decide
* whether two elements are identical, even if the input set uses a different
* concept of equivalence.
*
* <p><i>Performance notes:</i> while the power set of a set with size {@code
* n} is of size {@code 2^n}, its memory usage is only {@code O(n)}. When the
* power set is constructed, the input set is merely copied. Only as the
* power set is iterated are the individual subsets created, and these subsets
* themselves occupy only a small constant amount of memory.
*
* @param set the set of elements to construct a power set from
* @return the power set, as an immutable set of immutable sets
* @throws IllegalArgumentException if {@code set} has more than 30 unique
* elements (causing the power set size to exceed the {@code int} range)
* @throws NullPointerException if {@code set} is or contains {@code null}
* @see <a href="http://en.wikipedia.org/wiki/Power_set">Power set article at
* Wikipedia</a>
* @since 4.0
*/
@GwtCompatible(serializable = false)
public static <E> Set<Set<E>> powerSet(Set<E> set) {
return new PowerSet<E>(set);
}
private static final class SubSet<E> extends AbstractSet<E> {
private final ImmutableMap<E, Integer> inputSet;
private final int mask;
SubSet(ImmutableMap<E, Integer> inputSet, int mask) {
this.inputSet = inputSet;
this.mask = mask;
}
@Override
public Iterator<E> iterator() {
return new UnmodifiableIterator<E>() {
final ImmutableList<E> elements = inputSet.keySet().asList();
int remainingSetBits = mask;
@Override
public boolean hasNext() {
return remainingSetBits != 0;
}
@Override
public E next() {
int index = Integer.numberOfTrailingZeros(remainingSetBits);
if (index == 32) {
throw new NoSuchElementException();
}
remainingSetBits &= ~(1 << index);
return elements.get(index);
}
};
}
@Override
public int size() {
return Integer.bitCount(mask);
}
@Override
public boolean contains(@Nullable Object o) {
Integer index = inputSet.get(o);
return index != null && (mask & (1 << index)) != 0;
}
}
private static final class PowerSet<E> extends AbstractSet<Set<E>> {
final ImmutableMap<E, Integer> inputSet;
PowerSet(Set<E> input) {
ImmutableMap.Builder<E, Integer> builder = ImmutableMap.builder();
int i = 0;
for (E e : checkNotNull(input)) {
builder.put(e, i++);
}
this.inputSet = builder.build();
checkArgument(inputSet.size() <= 30,
"Too many elements to create power set: %s > 30", inputSet.size());
}
@Override public int size() {
return 1 << inputSet.size();
}
@Override public boolean isEmpty() {
return false;
}
@Override public Iterator<Set<E>> iterator() {
return new AbstractIndexedListIterator<Set<E>>(size()) {
@Override protected Set<E> get(final int setBits) {
return new SubSet<E>(inputSet, setBits);
}
};
}
@Override public boolean contains(@Nullable Object obj) {
if (obj instanceof Set) {
Set<?> set = (Set<?>) obj;
return inputSet.keySet().containsAll(set);
}
return false;
}
@Override public boolean equals(@Nullable Object obj) {
if (obj instanceof PowerSet) {
PowerSet<?> that = (PowerSet<?>) obj;
return inputSet.equals(that.inputSet);
}
return super.equals(obj);
}
@Override public int hashCode() {
/*
* The sum of the sums of the hash codes in each subset is just the sum of
* each input element's hash code times the number of sets that element
* appears in. Each element appears in exactly half of the 2^n sets, so:
*/
return inputSet.keySet().hashCode() << (inputSet.size() - 1);
}
@Override public String toString() {
return "powerSet(" + inputSet + ")";
}
}
/**
* An implementation for {@link Set#hashCode()}.
*/
static int hashCodeImpl(Set<?> s) {
int hashCode = 0;
for (Object o : s) {
hashCode += o != null ? o.hashCode() : 0;
hashCode = ~~hashCode;
// Needed to deal with unusual integer overflow in GWT.
}
return hashCode;
}
/**
* An implementation for {@link Set#equals(Object)}.
*/
static boolean equalsImpl(Set<?> s, @Nullable Object object) {
if (s == object) {
return true;
}
if (object instanceof Set) {
Set<?> o = (Set<?>) object;
try {
return s.size() == o.size() && s.containsAll(o);
} catch (NullPointerException ignored) {
return false;
} catch (ClassCastException ignored) {
return false;
}
}
return false;
}
/**
* Remove each element in an iterable from a set.
*/
static boolean removeAllImpl(Set<?> set, Iterator<?> iterator) {
boolean changed = false;
while (iterator.hasNext()) {
changed |= set.remove(iterator.next());
}
return changed;
}
static boolean removeAllImpl(Set<?> set, Collection<?> collection) {
checkNotNull(collection); // for GWT
if (collection instanceof Multiset) {
collection = ((Multiset<?>) collection).elementSet();
}
/*
* AbstractSet.removeAll(List) has quadratic behavior if the list size
* is just less than the set's size. We augment the test by
* assuming that sets have fast contains() performance, and other
* collections don't. See
* http://code.google.com/p/guava-libraries/issues/detail?id=1013
*/
if (collection instanceof Set && collection.size() > set.size()) {
return Iterators.removeAll(set.iterator(), collection);
} else {
return removeAllImpl(set, collection.iterator());
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/Sets.java | Java | asf20 | 46,475 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.Maps.ImprovedAbstractMap;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.RandomAccess;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import javax.annotation.Nullable;
/**
* Basic implementation of the {@link Multimap} interface. This class represents
* a multimap as a map that associates each key with a collection of values. All
* methods of {@link Multimap} are supported, including those specified as
* optional in the interface.
*
* <p>To implement a multimap, a subclass must define the method {@link
* #createCollection()}, which creates an empty collection of values for a key.
*
* <p>The multimap constructor takes a map that has a single entry for each
* distinct key. When you insert a key-value pair with a key that isn't already
* in the multimap, {@code AbstractMapBasedMultimap} calls {@link #createCollection()}
* to create the collection of values for that key. The subclass should not call
* {@link #createCollection()} directly, and a new instance should be created
* every time the method is called.
*
* <p>For example, the subclass could pass a {@link java.util.TreeMap} during
* construction, and {@link #createCollection()} could return a {@link
* java.util.TreeSet}, in which case the multimap's iterators would propagate
* through the keys and values in sorted order.
*
* <p>Keys and values may be null, as long as the underlying collection classes
* support null elements.
*
* <p>The collections created by {@link #createCollection()} may or may not
* allow duplicates. If the collection, such as a {@link Set}, does not support
* duplicates, an added key-value pair will replace an existing pair with the
* same key and value, if such a pair is present. With collections like {@link
* List} that allow duplicates, the collection will keep the existing key-value
* pairs while adding a new pair.
*
* <p>This class is not threadsafe when any concurrent operations update the
* multimap, even if the underlying map and {@link #createCollection()} method
* return threadsafe classes. Concurrent read operations will work correctly. To
* allow concurrent update operations, wrap your multimap with a call to {@link
* Multimaps#synchronizedMultimap}.
*
* <p>For serialization to work, the subclass must specify explicit
* {@code readObject} and {@code writeObject} methods.
*
* @author Jared Levy
* @author Louis Wasserman
*/
@GwtCompatible(emulated = true)
abstract class AbstractMapBasedMultimap<K, V> extends AbstractMultimap<K, V>
implements Serializable {
/*
* Here's an outline of the overall design.
*
* The map variable contains the collection of values associated with each
* key. When a key-value pair is added to a multimap that didn't previously
* contain any values for that key, a new collection generated by
* createCollection is added to the map. That same collection instance
* remains in the map as long as the multimap has any values for the key. If
* all values for the key are removed, the key and collection are removed
* from the map.
*
* The get method returns a WrappedCollection, which decorates the collection
* in the map (if the key is present) or an empty collection (if the key is
* not present). When the collection delegate in the WrappedCollection is
* empty, the multimap may contain subsequently added values for that key. To
* handle that situation, the WrappedCollection checks whether map contains
* an entry for the provided key, and if so replaces the delegate.
*/
private transient Map<K, Collection<V>> map;
private transient int totalSize;
/**
* Creates a new multimap that uses the provided map.
*
* @param map place to store the mapping from each key to its corresponding
* values
* @throws IllegalArgumentException if {@code map} is not empty
*/
protected AbstractMapBasedMultimap(Map<K, Collection<V>> map) {
checkArgument(map.isEmpty());
this.map = map;
}
/** Used during deserialization only. */
final void setMap(Map<K, Collection<V>> map) {
this.map = map;
totalSize = 0;
for (Collection<V> values : map.values()) {
checkArgument(!values.isEmpty());
totalSize += values.size();
}
}
/**
* Creates an unmodifiable, empty collection of values.
*
* <p>This is used in {@link #removeAll} on an empty key.
*/
Collection<V> createUnmodifiableEmptyCollection() {
return unmodifiableCollectionSubclass(createCollection());
}
/**
* Creates the collection of values for a single key.
*
* <p>Collections with weak, soft, or phantom references are not supported.
* Each call to {@code createCollection} should create a new instance.
*
* <p>The returned collection class determines whether duplicate key-value
* pairs are allowed.
*
* @return an empty collection of values
*/
abstract Collection<V> createCollection();
/**
* Creates the collection of values for an explicitly provided key. By
* default, it simply calls {@link #createCollection()}, which is the correct
* behavior for most implementations. The {@link LinkedHashMultimap} class
* overrides it.
*
* @param key key to associate with values in the collection
* @return an empty collection of values
*/
Collection<V> createCollection(@Nullable K key) {
return createCollection();
}
Map<K, Collection<V>> backingMap() {
return map;
}
// Query Operations
@Override
public int size() {
return totalSize;
}
@Override
public boolean containsKey(@Nullable Object key) {
return map.containsKey(key);
}
// Modification Operations
@Override
public boolean put(@Nullable K key, @Nullable V value) {
Collection<V> collection = map.get(key);
if (collection == null) {
collection = createCollection(key);
if (collection.add(value)) {
totalSize++;
map.put(key, collection);
return true;
} else {
throw new AssertionError("New Collection violated the Collection spec");
}
} else if (collection.add(value)) {
totalSize++;
return true;
} else {
return false;
}
}
private Collection<V> getOrCreateCollection(@Nullable K key) {
Collection<V> collection = map.get(key);
if (collection == null) {
collection = createCollection(key);
map.put(key, collection);
}
return collection;
}
// Bulk Operations
/**
* {@inheritDoc}
*
* <p>The returned collection is immutable.
*/
@Override
public Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values) {
Iterator<? extends V> iterator = values.iterator();
if (!iterator.hasNext()) {
return removeAll(key);
}
// TODO(user): investigate atomic failure?
Collection<V> collection = getOrCreateCollection(key);
Collection<V> oldValues = createCollection();
oldValues.addAll(collection);
totalSize -= collection.size();
collection.clear();
while (iterator.hasNext()) {
if (collection.add(iterator.next())) {
totalSize++;
}
}
return unmodifiableCollectionSubclass(oldValues);
}
/**
* {@inheritDoc}
*
* <p>The returned collection is immutable.
*/
@Override
public Collection<V> removeAll(@Nullable Object key) {
Collection<V> collection = map.remove(key);
if (collection == null) {
return createUnmodifiableEmptyCollection();
}
Collection<V> output = createCollection();
output.addAll(collection);
totalSize -= collection.size();
collection.clear();
return unmodifiableCollectionSubclass(output);
}
Collection<V> unmodifiableCollectionSubclass(Collection<V> collection) {
// We don't deal with NavigableSet here yet for GWT reasons -- instead,
// non-GWT TreeMultimap explicitly overrides this and uses NavigableSet.
if (collection instanceof SortedSet) {
return Collections.unmodifiableSortedSet((SortedSet<V>) collection);
} else if (collection instanceof Set) {
return Collections.unmodifiableSet((Set<V>) collection);
} else if (collection instanceof List) {
return Collections.unmodifiableList((List<V>) collection);
} else {
return Collections.unmodifiableCollection(collection);
}
}
@Override
public void clear() {
// Clear each collection, to make previously returned collections empty.
for (Collection<V> collection : map.values()) {
collection.clear();
}
map.clear();
totalSize = 0;
}
// Views
/**
* {@inheritDoc}
*
* <p>The returned collection is not serializable.
*/
@Override
public Collection<V> get(@Nullable K key) {
Collection<V> collection = map.get(key);
if (collection == null) {
collection = createCollection(key);
}
return wrapCollection(key, collection);
}
/**
* Generates a decorated collection that remains consistent with the values in
* the multimap for the provided key. Changes to the multimap may alter the
* returned collection, and vice versa.
*/
Collection<V> wrapCollection(@Nullable K key, Collection<V> collection) {
// We don't deal with NavigableSet here yet for GWT reasons -- instead,
// non-GWT TreeMultimap explicitly overrides this and uses NavigableSet.
if (collection instanceof SortedSet) {
return new WrappedSortedSet(key, (SortedSet<V>) collection, null);
} else if (collection instanceof Set) {
return new WrappedSet(key, (Set<V>) collection);
} else if (collection instanceof List) {
return wrapList(key, (List<V>) collection, null);
} else {
return new WrappedCollection(key, collection, null);
}
}
private List<V> wrapList(
@Nullable K key, List<V> list, @Nullable WrappedCollection ancestor) {
return (list instanceof RandomAccess)
? new RandomAccessWrappedList(key, list, ancestor)
: new WrappedList(key, list, ancestor);
}
/**
* Collection decorator that stays in sync with the multimap values for a key.
* There are two kinds of wrapped collections: full and subcollections. Both
* have a delegate pointing to the underlying collection class.
*
* <p>Full collections, identified by a null ancestor field, contain all
* multimap values for a given key. Its delegate is a value in {@link
* AbstractMapBasedMultimap#map} whenever the delegate is non-empty. The {@code
* refreshIfEmpty}, {@code removeIfEmpty}, and {@code addToMap} methods ensure
* that the {@code WrappedCollection} and map remain consistent.
*
* <p>A subcollection, such as a sublist, contains some of the values for a
* given key. Its ancestor field points to the full wrapped collection with
* all values for the key. The subcollection {@code refreshIfEmpty}, {@code
* removeIfEmpty}, and {@code addToMap} methods call the corresponding methods
* of the full wrapped collection.
*/
private class WrappedCollection extends AbstractCollection<V> {
final K key;
Collection<V> delegate;
final WrappedCollection ancestor;
final Collection<V> ancestorDelegate;
WrappedCollection(@Nullable K key, Collection<V> delegate,
@Nullable WrappedCollection ancestor) {
this.key = key;
this.delegate = delegate;
this.ancestor = ancestor;
this.ancestorDelegate
= (ancestor == null) ? null : ancestor.getDelegate();
}
/**
* If the delegate collection is empty, but the multimap has values for the
* key, replace the delegate with the new collection for the key.
*
* <p>For a subcollection, refresh its ancestor and validate that the
* ancestor delegate hasn't changed.
*/
void refreshIfEmpty() {
if (ancestor != null) {
ancestor.refreshIfEmpty();
if (ancestor.getDelegate() != ancestorDelegate) {
throw new ConcurrentModificationException();
}
} else if (delegate.isEmpty()) {
Collection<V> newDelegate = map.get(key);
if (newDelegate != null) {
delegate = newDelegate;
}
}
}
/**
* If collection is empty, remove it from {@code AbstractMapBasedMultimap.this.map}.
* For subcollections, check whether the ancestor collection is empty.
*/
void removeIfEmpty() {
if (ancestor != null) {
ancestor.removeIfEmpty();
} else if (delegate.isEmpty()) {
map.remove(key);
}
}
K getKey() {
return key;
}
/**
* Add the delegate to the map. Other {@code WrappedCollection} methods
* should call this method after adding elements to a previously empty
* collection.
*
* <p>Subcollection add the ancestor's delegate instead.
*/
void addToMap() {
if (ancestor != null) {
ancestor.addToMap();
} else {
map.put(key, delegate);
}
}
@Override public int size() {
refreshIfEmpty();
return delegate.size();
}
@Override public boolean equals(@Nullable Object object) {
if (object == this) {
return true;
}
refreshIfEmpty();
return delegate.equals(object);
}
@Override public int hashCode() {
refreshIfEmpty();
return delegate.hashCode();
}
@Override public String toString() {
refreshIfEmpty();
return delegate.toString();
}
Collection<V> getDelegate() {
return delegate;
}
@Override public Iterator<V> iterator() {
refreshIfEmpty();
return new WrappedIterator();
}
/** Collection iterator for {@code WrappedCollection}. */
class WrappedIterator implements Iterator<V> {
final Iterator<V> delegateIterator;
final Collection<V> originalDelegate = delegate;
WrappedIterator() {
delegateIterator = iteratorOrListIterator(delegate);
}
WrappedIterator(Iterator<V> delegateIterator) {
this.delegateIterator = delegateIterator;
}
/**
* If the delegate changed since the iterator was created, the iterator is
* no longer valid.
*/
void validateIterator() {
refreshIfEmpty();
if (delegate != originalDelegate) {
throw new ConcurrentModificationException();
}
}
@Override
public boolean hasNext() {
validateIterator();
return delegateIterator.hasNext();
}
@Override
public V next() {
validateIterator();
return delegateIterator.next();
}
@Override
public void remove() {
delegateIterator.remove();
totalSize--;
removeIfEmpty();
}
Iterator<V> getDelegateIterator() {
validateIterator();
return delegateIterator;
}
}
@Override public boolean add(V value) {
refreshIfEmpty();
boolean wasEmpty = delegate.isEmpty();
boolean changed = delegate.add(value);
if (changed) {
totalSize++;
if (wasEmpty) {
addToMap();
}
}
return changed;
}
WrappedCollection getAncestor() {
return ancestor;
}
// The following methods are provided for better performance.
@Override public boolean addAll(Collection<? extends V> collection) {
if (collection.isEmpty()) {
return false;
}
int oldSize = size(); // calls refreshIfEmpty
boolean changed = delegate.addAll(collection);
if (changed) {
int newSize = delegate.size();
totalSize += (newSize - oldSize);
if (oldSize == 0) {
addToMap();
}
}
return changed;
}
@Override public boolean contains(Object o) {
refreshIfEmpty();
return delegate.contains(o);
}
@Override public boolean containsAll(Collection<?> c) {
refreshIfEmpty();
return delegate.containsAll(c);
}
@Override public void clear() {
int oldSize = size(); // calls refreshIfEmpty
if (oldSize == 0) {
return;
}
delegate.clear();
totalSize -= oldSize;
removeIfEmpty(); // maybe shouldn't be removed if this is a sublist
}
@Override public boolean remove(Object o) {
refreshIfEmpty();
boolean changed = delegate.remove(o);
if (changed) {
totalSize--;
removeIfEmpty();
}
return changed;
}
@Override public boolean removeAll(Collection<?> c) {
if (c.isEmpty()) {
return false;
}
int oldSize = size(); // calls refreshIfEmpty
boolean changed = delegate.removeAll(c);
if (changed) {
int newSize = delegate.size();
totalSize += (newSize - oldSize);
removeIfEmpty();
}
return changed;
}
@Override public boolean retainAll(Collection<?> c) {
checkNotNull(c);
int oldSize = size(); // calls refreshIfEmpty
boolean changed = delegate.retainAll(c);
if (changed) {
int newSize = delegate.size();
totalSize += (newSize - oldSize);
removeIfEmpty();
}
return changed;
}
}
private Iterator<V> iteratorOrListIterator(Collection<V> collection) {
return (collection instanceof List)
? ((List<V>) collection).listIterator()
: collection.iterator();
}
/** Set decorator that stays in sync with the multimap values for a key. */
private class WrappedSet extends WrappedCollection implements Set<V> {
WrappedSet(@Nullable K key, Set<V> delegate) {
super(key, delegate, null);
}
@Override
public boolean removeAll(Collection<?> c) {
if (c.isEmpty()) {
return false;
}
int oldSize = size(); // calls refreshIfEmpty
// Guava issue 1013: AbstractSet and most JDK set implementations are
// susceptible to quadratic removeAll performance on lists;
// use a slightly smarter implementation here
boolean changed = Sets.removeAllImpl((Set<V>) delegate, c);
if (changed) {
int newSize = delegate.size();
totalSize += (newSize - oldSize);
removeIfEmpty();
}
return changed;
}
}
/**
* SortedSet decorator that stays in sync with the multimap values for a key.
*/
private class WrappedSortedSet extends WrappedCollection
implements SortedSet<V> {
WrappedSortedSet(@Nullable K key, SortedSet<V> delegate,
@Nullable WrappedCollection ancestor) {
super(key, delegate, ancestor);
}
SortedSet<V> getSortedSetDelegate() {
return (SortedSet<V>) getDelegate();
}
@Override
public Comparator<? super V> comparator() {
return getSortedSetDelegate().comparator();
}
@Override
public V first() {
refreshIfEmpty();
return getSortedSetDelegate().first();
}
@Override
public V last() {
refreshIfEmpty();
return getSortedSetDelegate().last();
}
@Override
public SortedSet<V> headSet(V toElement) {
refreshIfEmpty();
return new WrappedSortedSet(
getKey(), getSortedSetDelegate().headSet(toElement),
(getAncestor() == null) ? this : getAncestor());
}
@Override
public SortedSet<V> subSet(V fromElement, V toElement) {
refreshIfEmpty();
return new WrappedSortedSet(
getKey(), getSortedSetDelegate().subSet(fromElement, toElement),
(getAncestor() == null) ? this : getAncestor());
}
@Override
public SortedSet<V> tailSet(V fromElement) {
refreshIfEmpty();
return new WrappedSortedSet(
getKey(), getSortedSetDelegate().tailSet(fromElement),
(getAncestor() == null) ? this : getAncestor());
}
}
/** List decorator that stays in sync with the multimap values for a key. */
private class WrappedList extends WrappedCollection implements List<V> {
WrappedList(@Nullable K key, List<V> delegate,
@Nullable WrappedCollection ancestor) {
super(key, delegate, ancestor);
}
List<V> getListDelegate() {
return (List<V>) getDelegate();
}
@Override
public boolean addAll(int index, Collection<? extends V> c) {
if (c.isEmpty()) {
return false;
}
int oldSize = size(); // calls refreshIfEmpty
boolean changed = getListDelegate().addAll(index, c);
if (changed) {
int newSize = getDelegate().size();
totalSize += (newSize - oldSize);
if (oldSize == 0) {
addToMap();
}
}
return changed;
}
@Override
public V get(int index) {
refreshIfEmpty();
return getListDelegate().get(index);
}
@Override
public V set(int index, V element) {
refreshIfEmpty();
return getListDelegate().set(index, element);
}
@Override
public void add(int index, V element) {
refreshIfEmpty();
boolean wasEmpty = getDelegate().isEmpty();
getListDelegate().add(index, element);
totalSize++;
if (wasEmpty) {
addToMap();
}
}
@Override
public V remove(int index) {
refreshIfEmpty();
V value = getListDelegate().remove(index);
totalSize--;
removeIfEmpty();
return value;
}
@Override
public int indexOf(Object o) {
refreshIfEmpty();
return getListDelegate().indexOf(o);
}
@Override
public int lastIndexOf(Object o) {
refreshIfEmpty();
return getListDelegate().lastIndexOf(o);
}
@Override
public ListIterator<V> listIterator() {
refreshIfEmpty();
return new WrappedListIterator();
}
@Override
public ListIterator<V> listIterator(int index) {
refreshIfEmpty();
return new WrappedListIterator(index);
}
@Override
public List<V> subList(int fromIndex, int toIndex) {
refreshIfEmpty();
return wrapList(getKey(),
getListDelegate().subList(fromIndex, toIndex),
(getAncestor() == null) ? this : getAncestor());
}
/** ListIterator decorator. */
private class WrappedListIterator extends WrappedIterator
implements ListIterator<V> {
WrappedListIterator() {}
public WrappedListIterator(int index) {
super(getListDelegate().listIterator(index));
}
private ListIterator<V> getDelegateListIterator() {
return (ListIterator<V>) getDelegateIterator();
}
@Override
public boolean hasPrevious() {
return getDelegateListIterator().hasPrevious();
}
@Override
public V previous() {
return getDelegateListIterator().previous();
}
@Override
public int nextIndex() {
return getDelegateListIterator().nextIndex();
}
@Override
public int previousIndex() {
return getDelegateListIterator().previousIndex();
}
@Override
public void set(V value) {
getDelegateListIterator().set(value);
}
@Override
public void add(V value) {
boolean wasEmpty = isEmpty();
getDelegateListIterator().add(value);
totalSize++;
if (wasEmpty) {
addToMap();
}
}
}
}
/**
* List decorator that stays in sync with the multimap values for a key and
* supports rapid random access.
*/
private class RandomAccessWrappedList extends WrappedList
implements RandomAccess {
RandomAccessWrappedList(@Nullable K key, List<V> delegate,
@Nullable WrappedCollection ancestor) {
super(key, delegate, ancestor);
}
}
@Override
Set<K> createKeySet() {
// TreeMultimap uses NavigableKeySet explicitly, but we don't handle that here for GWT
// compatibility reasons
return (map instanceof SortedMap)
? new SortedKeySet((SortedMap<K, Collection<V>>) map) : new KeySet(map);
}
private class KeySet extends Maps.KeySet<K, Collection<V>> {
KeySet(final Map<K, Collection<V>> subMap) {
super(subMap);
}
@Override public Iterator<K> iterator() {
final Iterator<Map.Entry<K, Collection<V>>> entryIterator
= map().entrySet().iterator();
return new Iterator<K>() {
Map.Entry<K, Collection<V>> entry;
@Override
public boolean hasNext() {
return entryIterator.hasNext();
}
@Override
public K next() {
entry = entryIterator.next();
return entry.getKey();
}
@Override
public void remove() {
checkRemove(entry != null);
Collection<V> collection = entry.getValue();
entryIterator.remove();
totalSize -= collection.size();
collection.clear();
}
};
}
// The following methods are included for better performance.
@Override public boolean remove(Object key) {
int count = 0;
Collection<V> collection = map().remove(key);
if (collection != null) {
count = collection.size();
collection.clear();
totalSize -= count;
}
return count > 0;
}
@Override
public void clear() {
Iterators.clear(iterator());
}
@Override public boolean containsAll(Collection<?> c) {
return map().keySet().containsAll(c);
}
@Override public boolean equals(@Nullable Object object) {
return this == object || this.map().keySet().equals(object);
}
@Override public int hashCode() {
return map().keySet().hashCode();
}
}
private class SortedKeySet extends KeySet implements SortedSet<K> {
SortedKeySet(SortedMap<K, Collection<V>> subMap) {
super(subMap);
}
SortedMap<K, Collection<V>> sortedMap() {
return (SortedMap<K, Collection<V>>) super.map();
}
@Override
public Comparator<? super K> comparator() {
return sortedMap().comparator();
}
@Override
public K first() {
return sortedMap().firstKey();
}
@Override
public SortedSet<K> headSet(K toElement) {
return new SortedKeySet(sortedMap().headMap(toElement));
}
@Override
public K last() {
return sortedMap().lastKey();
}
@Override
public SortedSet<K> subSet(K fromElement, K toElement) {
return new SortedKeySet(sortedMap().subMap(fromElement, toElement));
}
@Override
public SortedSet<K> tailSet(K fromElement) {
return new SortedKeySet(sortedMap().tailMap(fromElement));
}
}
/**
* Removes all values for the provided key. Unlike {@link #removeAll}, it
* returns the number of removed mappings.
*/
private int removeValuesForKey(Object key) {
Collection<V> collection = Maps.safeRemove(map, key);
int count = 0;
if (collection != null) {
count = collection.size();
collection.clear();
totalSize -= count;
}
return count;
}
private abstract class Itr<T> implements Iterator<T> {
final Iterator<Map.Entry<K, Collection<V>>> keyIterator;
K key;
Collection<V> collection;
Iterator<V> valueIterator;
Itr() {
keyIterator = map.entrySet().iterator();
key = null;
collection = null;
valueIterator = Iterators.emptyModifiableIterator();
}
abstract T output(K key, V value);
@Override
public boolean hasNext() {
return keyIterator.hasNext() || valueIterator.hasNext();
}
@Override
public T next() {
if (!valueIterator.hasNext()) {
Map.Entry<K, Collection<V>> mapEntry = keyIterator.next();
key = mapEntry.getKey();
collection = mapEntry.getValue();
valueIterator = collection.iterator();
}
return output(key, valueIterator.next());
}
@Override
public void remove() {
valueIterator.remove();
if (collection.isEmpty()) {
keyIterator.remove();
}
totalSize--;
}
}
/**
* {@inheritDoc}
*
* <p>The iterator generated by the returned collection traverses the values
* for one key, followed by the values of a second key, and so on.
*/
@Override public Collection<V> values() {
return super.values();
}
@Override
Iterator<V> valueIterator() {
return new Itr<V>() {
@Override
V output(K key, V value) {
return value;
}
};
}
/*
* TODO(kevinb): should we copy this javadoc to each concrete class, so that
* classes like LinkedHashMultimap that need to say something different are
* still able to {@inheritDoc} all the way from Multimap?
*/
/**
* {@inheritDoc}
*
* <p>The iterator generated by the returned collection traverses the values
* for one key, followed by the values of a second key, and so on.
*
* <p>Each entry is an immutable snapshot of a key-value mapping in the
* multimap, taken at the time the entry is returned by a method call to the
* collection or its iterator.
*/
@Override
public Collection<Map.Entry<K, V>> entries() {
return super.entries();
}
/**
* Returns an iterator across all key-value map entries, used by {@code
* entries().iterator()} and {@code values().iterator()}. The default
* behavior, which traverses the values for one key, the values for a second
* key, and so on, suffices for most {@code AbstractMapBasedMultimap} implementations.
*
* @return an iterator across map entries
*/
@Override
Iterator<Map.Entry<K, V>> entryIterator() {
return new Itr<Map.Entry<K, V>>() {
@Override
Entry<K, V> output(K key, V value) {
return Maps.immutableEntry(key, value);
}
};
}
@Override
Map<K, Collection<V>> createAsMap() {
// TreeMultimap uses NavigableAsMap explicitly, but we don't handle that here for GWT
// compatibility reasons
return (map instanceof SortedMap)
? new SortedAsMap((SortedMap<K, Collection<V>>) map) : new AsMap(map);
}
private class AsMap extends ImprovedAbstractMap<K, Collection<V>> {
/**
* Usually the same as map, but smaller for the headMap(), tailMap(), or
* subMap() of a SortedAsMap.
*/
final transient Map<K, Collection<V>> submap;
AsMap(Map<K, Collection<V>> submap) {
this.submap = submap;
}
@Override
protected Set<Entry<K, Collection<V>>> createEntrySet() {
return new AsMapEntries();
}
// The following methods are included for performance.
@Override public boolean containsKey(Object key) {
return Maps.safeContainsKey(submap, key);
}
@Override public Collection<V> get(Object key) {
Collection<V> collection = Maps.safeGet(submap, key);
if (collection == null) {
return null;
}
@SuppressWarnings("unchecked")
K k = (K) key;
return wrapCollection(k, collection);
}
@Override public Set<K> keySet() {
return AbstractMapBasedMultimap.this.keySet();
}
@Override
public int size() {
return submap.size();
}
@Override public Collection<V> remove(Object key) {
Collection<V> collection = submap.remove(key);
if (collection == null) {
return null;
}
Collection<V> output = createCollection();
output.addAll(collection);
totalSize -= collection.size();
collection.clear();
return output;
}
@Override public boolean equals(@Nullable Object object) {
return this == object || submap.equals(object);
}
@Override public int hashCode() {
return submap.hashCode();
}
@Override public String toString() {
return submap.toString();
}
@Override
public void clear() {
if (submap == map) {
AbstractMapBasedMultimap.this.clear();
} else {
Iterators.clear(new AsMapIterator());
}
}
Entry<K, Collection<V>> wrapEntry(Entry<K, Collection<V>> entry) {
K key = entry.getKey();
return Maps.immutableEntry(key, wrapCollection(key, entry.getValue()));
}
class AsMapEntries extends Maps.EntrySet<K, Collection<V>> {
@Override
Map<K, Collection<V>> map() {
return AsMap.this;
}
@Override public Iterator<Map.Entry<K, Collection<V>>> iterator() {
return new AsMapIterator();
}
// The following methods are included for performance.
@Override public boolean contains(Object o) {
return Collections2.safeContains(submap.entrySet(), o);
}
@Override public boolean remove(Object o) {
if (!contains(o)) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
removeValuesForKey(entry.getKey());
return true;
}
}
/** Iterator across all keys and value collections. */
class AsMapIterator implements Iterator<Map.Entry<K, Collection<V>>> {
final Iterator<Map.Entry<K, Collection<V>>> delegateIterator
= submap.entrySet().iterator();
Collection<V> collection;
@Override
public boolean hasNext() {
return delegateIterator.hasNext();
}
@Override
public Map.Entry<K, Collection<V>> next() {
Map.Entry<K, Collection<V>> entry = delegateIterator.next();
collection = entry.getValue();
return wrapEntry(entry);
}
@Override
public void remove() {
delegateIterator.remove();
totalSize -= collection.size();
collection.clear();
}
}
}
private class SortedAsMap extends AsMap
implements SortedMap<K, Collection<V>> {
SortedAsMap(SortedMap<K, Collection<V>> submap) {
super(submap);
}
SortedMap<K, Collection<V>> sortedMap() {
return (SortedMap<K, Collection<V>>) submap;
}
@Override
public Comparator<? super K> comparator() {
return sortedMap().comparator();
}
@Override
public K firstKey() {
return sortedMap().firstKey();
}
@Override
public K lastKey() {
return sortedMap().lastKey();
}
@Override
public SortedMap<K, Collection<V>> headMap(K toKey) {
return new SortedAsMap(sortedMap().headMap(toKey));
}
@Override
public SortedMap<K, Collection<V>> subMap(K fromKey, K toKey) {
return new SortedAsMap(sortedMap().subMap(fromKey, toKey));
}
@Override
public SortedMap<K, Collection<V>> tailMap(K fromKey) {
return new SortedAsMap(sortedMap().tailMap(fromKey));
}
SortedSet<K> sortedKeySet;
// returns a SortedSet, even though returning a Set would be sufficient to
// satisfy the SortedMap.keySet() interface
@Override public SortedSet<K> keySet() {
SortedSet<K> result = sortedKeySet;
return (result == null) ? sortedKeySet = createKeySet() : result;
}
@Override
SortedSet<K> createKeySet() {
return new SortedKeySet(sortedMap());
}
}
private static final long serialVersionUID = 2447537837011683357L;
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/AbstractMapBasedMultimap.java | Java | asf20 | 36,194 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.RandomAccess;
import javax.annotation.Nullable;
/**
* GWT emulated version of {@link ImmutableList}.
* TODO(cpovirk): more doc
*
* @author Hayward Chan
*/
@SuppressWarnings("serial") // we're overriding default serialization
public abstract class ImmutableList<E> extends ImmutableCollection<E>
implements List<E>, RandomAccess {
static final ImmutableList<Object> EMPTY =
new RegularImmutableList<Object>(Collections.emptyList());
ImmutableList() {}
// Casting to any type is safe because the list will never hold any elements.
@SuppressWarnings("unchecked")
public static <E> ImmutableList<E> of() {
return (ImmutableList<E>) EMPTY;
}
public static <E> ImmutableList<E> of(E element) {
return new SingletonImmutableList<E>(element);
}
public static <E> ImmutableList<E> of(E e1, E e2) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2));
}
public static <E> ImmutableList<E> of(E e1, E e2, E e3) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3));
}
public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4));
}
public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5));
}
public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7, e8));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9) {
return new RegularImmutableList<E>(
ImmutableList.<E>nullCheckedList(e1, e2, e3, e4, e5, e6, e7, e8, e9));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10) {
return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList(
e1, e2, e3, e4, e5, e6, e7, e8, e9, e10));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11) {
return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList(
e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11));
}
public static <E> ImmutableList<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10, E e11,
E e12, E... others) {
final int paramCount = 12;
Object[] array = new Object[paramCount + others.length];
arrayCopy(array, 0, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12);
arrayCopy(array, paramCount, others);
return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList(array));
}
private static void arrayCopy(Object[] dest, int pos, Object... source) {
System.arraycopy(source, 0, dest, pos, source.length);
}
public static <E> ImmutableList<E> copyOf(Iterable<? extends E> elements) {
checkNotNull(elements); // for GWT
return (elements instanceof Collection)
? copyOf((Collection<? extends E>) elements)
: copyOf(elements.iterator());
}
public static <E> ImmutableList<E> copyOf(Iterator<? extends E> elements) {
return copyFromCollection(Lists.newArrayList(elements));
}
public static <E> ImmutableList<E> copyOf(Collection<? extends E> elements) {
if (elements instanceof ImmutableCollection) {
/*
* TODO: When given an ImmutableList that's a sublist, copy the referenced
* portion of the array into a new array to save space?
*/
@SuppressWarnings("unchecked") // all supported methods are covariant
ImmutableCollection<E> list = (ImmutableCollection<E>) elements;
return list.asList();
}
return copyFromCollection(elements);
}
public static <E> ImmutableList<E> copyOf(E[] elements) {
checkNotNull(elements); // eager for GWT
return copyOf(Arrays.asList(elements));
}
private static <E> ImmutableList<E> copyFromCollection(
Collection<? extends E> collection) {
Object[] elements = collection.toArray();
switch (elements.length) {
case 0:
return of();
case 1:
@SuppressWarnings("unchecked") // collection had only Es in it
ImmutableList<E> list = new SingletonImmutableList<E>((E) elements[0]);
return list;
default:
return new RegularImmutableList<E>(ImmutableList.<E>nullCheckedList(elements));
}
}
// Factory method that skips the null checks. Used only when the elements
// are guaranteed to be non-null.
static <E> ImmutableList<E> unsafeDelegateList(List<? extends E> list) {
switch (list.size()) {
case 0:
return of();
case 1:
return new SingletonImmutableList<E>(list.iterator().next());
default:
@SuppressWarnings("unchecked")
List<E> castedList = (List<E>) list;
return new RegularImmutableList<E>(castedList);
}
}
/**
* Views the array as an immutable list. The array must have only {@code E} elements.
*
* <p>The array must be internally created.
*/
@SuppressWarnings("unchecked") // caller is reponsible for getting this right
static <E> ImmutableList<E> asImmutableList(Object[] elements) {
return unsafeDelegateList((List) Arrays.asList(elements));
}
private static <E> List<E> nullCheckedList(Object... array) {
for (int i = 0, len = array.length; i < len; i++) {
if (array[i] == null) {
throw new NullPointerException("at index " + i);
}
}
@SuppressWarnings("unchecked")
E[] castedArray = (E[]) array;
return Arrays.asList(castedArray);
}
@Override
public int indexOf(@Nullable Object object) {
return (object == null) ? -1 : Lists.indexOfImpl(this, object);
}
@Override
public int lastIndexOf(@Nullable Object object) {
return (object == null) ? -1 : Lists.lastIndexOfImpl(this, object);
}
public final boolean addAll(int index, Collection<? extends E> newElements) {
throw new UnsupportedOperationException();
}
public final E set(int index, E element) {
throw new UnsupportedOperationException();
}
public final void add(int index, E element) {
throw new UnsupportedOperationException();
}
public final E remove(int index) {
throw new UnsupportedOperationException();
}
@Override public UnmodifiableIterator<E> iterator() {
return listIterator();
}
@Override public ImmutableList<E> subList(int fromIndex, int toIndex) {
return unsafeDelegateList(Lists.subListImpl(this, fromIndex, toIndex));
}
@Override public UnmodifiableListIterator<E> listIterator() {
return listIterator(0);
}
@Override public UnmodifiableListIterator<E> listIterator(int index) {
return new AbstractIndexedListIterator<E>(size(), index) {
@Override
protected E get(int index) {
return ImmutableList.this.get(index);
}
};
}
@Override public ImmutableList<E> asList() {
return this;
}
@Override
public boolean equals(@Nullable Object obj) {
return Lists.equalsImpl(this, obj);
}
@Override
public int hashCode() {
return Lists.hashCodeImpl(this);
}
public ImmutableList<E> reverse() {
List<E> list = Lists.newArrayList(this);
Collections.reverse(list);
return unsafeDelegateList(list);
}
public static <E> Builder<E> builder() {
return new Builder<E>();
}
public static final class Builder<E> extends ImmutableCollection.Builder<E> {
private final ArrayList<E> contents;
public Builder() {
contents = Lists.newArrayList();
}
Builder(int capacity) {
contents = Lists.newArrayListWithCapacity(capacity);
}
@Override public Builder<E> add(E element) {
contents.add(checkNotNull(element));
return this;
}
@Override public Builder<E> addAll(Iterable<? extends E> elements) {
super.addAll(elements);
return this;
}
@Override public Builder<E> add(E... elements) {
checkNotNull(elements); // for GWT
super.add(elements);
return this;
}
@Override public Builder<E> addAll(Iterator<? extends E> elements) {
super.addAll(elements);
return this;
}
@Override public ImmutableList<E> build() {
return copyOf(contents);
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableList.java | Java | asf20 | 9,746 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
/**
* GWT emulation of {@link RegularImmutableBiMap}.
*
* @author Jared Levy
* @author Hayward Chan
*/
@SuppressWarnings("serial")
class RegularImmutableBiMap<K, V> extends ImmutableBiMap<K, V> {
// This reference is used both by the GWT compiler to infer the elements
// of the lists that needs to be serialized.
private ImmutableBiMap<V, K> inverse;
RegularImmutableBiMap(ImmutableMap<K, V> delegate) {
super(delegate);
ImmutableMap.Builder<V, K> builder = ImmutableMap.builder();
for (Entry<K, V> entry : delegate.entrySet()) {
builder.put(entry.getValue(), entry.getKey());
}
ImmutableMap<V, K> backwardMap = builder.build();
this.inverse = new RegularImmutableBiMap<V, K>(backwardMap, this);
}
RegularImmutableBiMap(ImmutableMap<K, V> delegate,
ImmutableBiMap<V, K> inverse) {
super(delegate);
this.inverse = inverse;
}
@Override public ImmutableBiMap<V, K> inverse() {
return inverse;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/RegularImmutableBiMap.java | Java | asf20 | 1,609 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.GwtCompatible;
import java.util.Map.Entry;
import javax.annotation.Nullable;
/**
* {@code entrySet()} implementation for {@link ImmutableMap}.
*
* @author Jesse Wilson
* @author Kevin Bourrillion
*/
@GwtCompatible(emulated = true)
abstract class ImmutableMapEntrySet<K, V> extends ImmutableSet<Entry<K, V>> {
ImmutableMapEntrySet() {}
abstract ImmutableMap<K, V> map();
@Override
public int size() {
return map().size();
}
@Override
public boolean contains(@Nullable Object object) {
if (object instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) object;
V value = map().get(entry.getKey());
return value != null && value.equals(entry.getValue());
}
return false;
}
@Override
boolean isPartialView() {
return map().isPartialView();
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableMapEntrySet.java | Java | asf20 | 1,486 |
/*
* Copyright (C) 2011 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.Beta;
import java.util.Comparator;
import java.util.SortedSet;
/**
* GWT emulation of {@code SortedMultiset}, with {@code elementSet} reduced
* to returning a {@code SortedSet} for GWT compatibility.
*
* @author Louis Wasserman
* @since 11.0
*/
@Beta
public interface SortedMultiset<E> extends Multiset<E>, SortedIterable<E> {
Comparator<? super E> comparator();
Entry<E> firstEntry();
Entry<E> lastEntry();
Entry<E> pollFirstEntry();
Entry<E> pollLastEntry();
/**
* Returns a {@link SortedSet} view of the distinct elements in this multiset.
* (Outside GWT, this returns a {@code NavigableSet}.)
*/
@Override SortedSet<E> elementSet();
SortedMultiset<E> descendingMultiset();
SortedMultiset<E> headMultiset(E upperBound, BoundType boundType);
SortedMultiset<E> subMultiset(E lowerBound, BoundType lowerBoundType,
E upperBound, BoundType upperBoundType);
SortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType);
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/SortedMultiset.java | Java | asf20 | 1,659 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndex;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.math.IntMath;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.math.RoundingMode;
import java.util.AbstractList;
import java.util.AbstractSequentialList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import javax.annotation.Nullable;
/**
* Static utility methods pertaining to {@link List} instances. Also see this
* class's counterparts {@link Sets}, {@link Maps} and {@link Queues}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Lists">
* {@code Lists}</a>.
*
* @author Kevin Bourrillion
* @author Mike Bostock
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class Lists {
private Lists() {}
// ArrayList
/**
* Creates a <i>mutable</i>, empty {@code ArrayList} instance.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableList#of()} instead.
*
* @return a new, empty {@code ArrayList}
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList() {
return new ArrayList<E>();
}
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use an overload of {@link ImmutableList#of()} (for varargs) or
* {@link ImmutableList#copyOf(Object[])} (for an array) instead.
*
* @param elements the elements that the list should contain, in order
* @return a new {@code ArrayList} containing those elements
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList(E... elements) {
checkNotNull(elements); // for GWT
// Avoid integer overflow when a large array is passed in
int capacity = computeArrayListCapacity(elements.length);
ArrayList<E> list = new ArrayList<E>(capacity);
Collections.addAll(list, elements);
return list;
}
@VisibleForTesting static int computeArrayListCapacity(int arraySize) {
checkNonnegative(arraySize, "arraySize");
// TODO(kevinb): Figure out the right behavior, and document it
return Ints.saturatedCast(5L + arraySize + (arraySize / 10));
}
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableList#copyOf(Iterator)} instead.
*
* @param elements the elements that the list should contain, in order
* @return a new {@code ArrayList} containing those elements
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList(Iterable<? extends E> elements) {
checkNotNull(elements); // for GWT
// Let ArrayList's sizing logic work, if possible
return (elements instanceof Collection)
? new ArrayList<E>(Collections2.cast(elements))
: newArrayList(elements.iterator());
}
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableList#copyOf(Iterator)} instead.
*
* @param elements the elements that the list should contain, in order
* @return a new {@code ArrayList} containing those elements
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements) {
ArrayList<E> list = newArrayList();
Iterators.addAll(list, elements);
return list;
}
/**
* Creates an {@code ArrayList} instance backed by an array of the
* <i>exact</i> size specified; equivalent to
* {@link ArrayList#ArrayList(int)}.
*
* <p><b>Note:</b> if you know the exact size your list will be, consider
* using a fixed-size list ({@link Arrays#asList(Object[])}) or an {@link
* ImmutableList} instead of a growable {@link ArrayList}.
*
* <p><b>Note:</b> If you have only an <i>estimate</i> of the eventual size of
* the list, consider padding this estimate by a suitable amount, or simply
* use {@link #newArrayListWithExpectedSize(int)} instead.
*
* @param initialArraySize the exact size of the initial backing array for
* the returned array list ({@code ArrayList} documentation calls this
* value the "capacity")
* @return a new, empty {@code ArrayList} which is guaranteed not to resize
* itself unless its size reaches {@code initialArraySize + 1}
* @throws IllegalArgumentException if {@code initialArraySize} is negative
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithCapacity(
int initialArraySize) {
checkNonnegative(initialArraySize, "initialArraySize"); // for GWT.
return new ArrayList<E>(initialArraySize);
}
/**
* Creates an {@code ArrayList} instance sized appropriately to hold an
* <i>estimated</i> number of elements without resizing. A small amount of
* padding is added in case the estimate is low.
*
* <p><b>Note:</b> If you know the <i>exact</i> number of elements the list
* will hold, or prefer to calculate your own amount of padding, refer to
* {@link #newArrayListWithCapacity(int)}.
*
* @param estimatedSize an estimate of the eventual {@link List#size()} of
* the new list
* @return a new, empty {@code ArrayList}, sized appropriately to hold the
* estimated number of elements
* @throws IllegalArgumentException if {@code estimatedSize} is negative
*/
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(
int estimatedSize) {
return new ArrayList<E>(computeArrayListCapacity(estimatedSize));
}
// LinkedList
/**
* Creates an empty {@code LinkedList} instance.
*
* <p><b>Note:</b> if you need an immutable empty {@link List}, use
* {@link ImmutableList#of()} instead.
*
* @return a new, empty {@code LinkedList}
*/
@GwtCompatible(serializable = true)
public static <E> LinkedList<E> newLinkedList() {
return new LinkedList<E>();
}
/**
* Creates a {@code LinkedList} instance containing the given elements.
*
* @param elements the elements that the list should contain, in order
* @return a new {@code LinkedList} containing those elements
*/
@GwtCompatible(serializable = true)
public static <E> LinkedList<E> newLinkedList(
Iterable<? extends E> elements) {
LinkedList<E> list = newLinkedList();
Iterables.addAll(list, elements);
return list;
}
/**
* Returns an unmodifiable list containing the specified first element and
* backed by the specified array of additional elements. Changes to the {@code
* rest} array will be reflected in the returned list. Unlike {@link
* Arrays#asList}, the returned list is unmodifiable.
*
* <p>This is useful when a varargs method needs to use a signature such as
* {@code (Foo firstFoo, Foo... moreFoos)}, in order to avoid overload
* ambiguity or to enforce a minimum argument count.
*
* <p>The returned list is serializable and implements {@link RandomAccess}.
*
* @param first the first element
* @param rest an array of additional elements, possibly empty
* @return an unmodifiable list containing the specified elements
*/
public static <E> List<E> asList(@Nullable E first, E[] rest) {
return new OnePlusArrayList<E>(first, rest);
}
/** @see Lists#asList(Object, Object[]) */
private static class OnePlusArrayList<E> extends AbstractList<E>
implements Serializable, RandomAccess {
final E first;
final E[] rest;
OnePlusArrayList(@Nullable E first, E[] rest) {
this.first = first;
this.rest = checkNotNull(rest);
}
@Override public int size() {
return rest.length + 1;
}
@Override public E get(int index) {
// check explicitly so the IOOBE will have the right message
checkElementIndex(index, size());
return (index == 0) ? first : rest[index - 1];
}
private static final long serialVersionUID = 0;
}
/**
* Returns an unmodifiable list containing the specified first and second
* element, and backed by the specified array of additional elements. Changes
* to the {@code rest} array will be reflected in the returned list. Unlike
* {@link Arrays#asList}, the returned list is unmodifiable.
*
* <p>This is useful when a varargs method needs to use a signature such as
* {@code (Foo firstFoo, Foo secondFoo, Foo... moreFoos)}, in order to avoid
* overload ambiguity or to enforce a minimum argument count.
*
* <p>The returned list is serializable and implements {@link RandomAccess}.
*
* @param first the first element
* @param second the second element
* @param rest an array of additional elements, possibly empty
* @return an unmodifiable list containing the specified elements
*/
public static <E> List<E> asList(
@Nullable E first, @Nullable E second, E[] rest) {
return new TwoPlusArrayList<E>(first, second, rest);
}
/** @see Lists#asList(Object, Object, Object[]) */
private static class TwoPlusArrayList<E> extends AbstractList<E>
implements Serializable, RandomAccess {
final E first;
final E second;
final E[] rest;
TwoPlusArrayList(@Nullable E first, @Nullable E second, E[] rest) {
this.first = first;
this.second = second;
this.rest = checkNotNull(rest);
}
@Override public int size() {
return rest.length + 2;
}
@Override public E get(int index) {
switch (index) {
case 0:
return first;
case 1:
return second;
default:
// check explicitly so the IOOBE will have the right message
checkElementIndex(index, size());
return rest[index - 2];
}
}
private static final long serialVersionUID = 0;
}
/**
* Returns every possible list that can be formed by choosing one element
* from each of the given lists in order; the "n-ary
* <a href="http://en.wikipedia.org/wiki/Cartesian_product">Cartesian
* product</a>" of the lists. For example: <pre> {@code
*
* Lists.cartesianProduct(ImmutableList.of(
* ImmutableList.of(1, 2),
* ImmutableList.of("A", "B", "C")))}</pre>
*
* <p>returns a list containing six lists in the following order:
*
* <ul>
* <li>{@code ImmutableList.of(1, "A")}
* <li>{@code ImmutableList.of(1, "B")}
* <li>{@code ImmutableList.of(1, "C")}
* <li>{@code ImmutableList.of(2, "A")}
* <li>{@code ImmutableList.of(2, "B")}
* <li>{@code ImmutableList.of(2, "C")}
* </ul>
*
* <p>The result is guaranteed to be in the "traditional", lexicographical
* order for Cartesian products that you would get from nesting for loops:
* <pre> {@code
*
* for (B b0 : lists.get(0)) {
* for (B b1 : lists.get(1)) {
* ...
* ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
* // operate on tuple
* }
* }}</pre>
*
* <p>Note that if any input list is empty, the Cartesian product will also be
* empty. If no lists at all are provided (an empty list), the resulting
* Cartesian product has one element, an empty list (counter-intuitive, but
* mathematically consistent).
*
* <p><i>Performance notes:</i> while the cartesian product of lists of size
* {@code m, n, p} is a list of size {@code m x n x p}, its actual memory
* consumption is much smaller. When the cartesian product is constructed, the
* input lists are merely copied. Only as the resulting list is iterated are
* the individual lists created, and these are not retained after iteration.
*
* @param lists the lists to choose elements from, in the order that
* the elements chosen from those lists should appear in the resulting
* lists
* @param <B> any common base class shared by all axes (often just {@link
* Object})
* @return the Cartesian product, as an immutable list containing immutable
* lists
* @throws IllegalArgumentException if the size of the cartesian product would
* be greater than {@link Integer#MAX_VALUE}
* @throws NullPointerException if {@code lists}, any one of the {@code lists},
* or any element of a provided list is null
*/ static <B> List<List<B>>
cartesianProduct(List<? extends List<? extends B>> lists) {
return CartesianList.create(lists);
}
/**
* Returns every possible list that can be formed by choosing one element
* from each of the given lists in order; the "n-ary
* <a href="http://en.wikipedia.org/wiki/Cartesian_product">Cartesian
* product</a>" of the lists. For example: <pre> {@code
*
* Lists.cartesianProduct(ImmutableList.of(
* ImmutableList.of(1, 2),
* ImmutableList.of("A", "B", "C")))}</pre>
*
* <p>returns a list containing six lists in the following order:
*
* <ul>
* <li>{@code ImmutableList.of(1, "A")}
* <li>{@code ImmutableList.of(1, "B")}
* <li>{@code ImmutableList.of(1, "C")}
* <li>{@code ImmutableList.of(2, "A")}
* <li>{@code ImmutableList.of(2, "B")}
* <li>{@code ImmutableList.of(2, "C")}
* </ul>
*
* <p>The result is guaranteed to be in the "traditional", lexicographical
* order for Cartesian products that you would get from nesting for loops:
* <pre> {@code
*
* for (B b0 : lists.get(0)) {
* for (B b1 : lists.get(1)) {
* ...
* ImmutableList<B> tuple = ImmutableList.of(b0, b1, ...);
* // operate on tuple
* }
* }}</pre>
*
* <p>Note that if any input list is empty, the Cartesian product will also be
* empty. If no lists at all are provided (an empty list), the resulting
* Cartesian product has one element, an empty list (counter-intuitive, but
* mathematically consistent).
*
* <p><i>Performance notes:</i> while the cartesian product of lists of size
* {@code m, n, p} is a list of size {@code m x n x p}, its actual memory
* consumption is much smaller. When the cartesian product is constructed, the
* input lists are merely copied. Only as the resulting list is iterated are
* the individual lists created, and these are not retained after iteration.
*
* @param lists the lists to choose elements from, in the order that
* the elements chosen from those lists should appear in the resulting
* lists
* @param <B> any common base class shared by all axes (often just {@link
* Object})
* @return the Cartesian product, as an immutable list containing immutable
* lists
* @throws IllegalArgumentException if the size of the cartesian product would
* be greater than {@link Integer#MAX_VALUE}
* @throws NullPointerException if {@code lists}, any one of the
* {@code lists}, or any element of a provided list is null
*/ static <B> List<List<B>>
cartesianProduct(List<? extends B>... lists) {
return cartesianProduct(Arrays.asList(lists));
}
/**
* Returns a list that applies {@code function} to each element of {@code
* fromList}. The returned list is a transformed view of {@code fromList};
* changes to {@code fromList} will be reflected in the returned list and vice
* versa.
*
* <p>Since functions are not reversible, the transform is one-way and new
* items cannot be stored in the returned list. The {@code add},
* {@code addAll} and {@code set} methods are unsupported in the returned
* list.
*
* <p>The function is applied lazily, invoked when needed. This is necessary
* for the returned list to be a view, but it means that the function will be
* applied many times for bulk operations like {@link List#contains} and
* {@link List#hashCode}. For this to perform well, {@code function} should be
* fast. To avoid lazy evaluation when the returned list doesn't need to be a
* view, copy the returned list into a new list of your choosing.
*
* <p>If {@code fromList} implements {@link RandomAccess}, so will the
* returned list. The returned list is threadsafe if the supplied list and
* function are.
*
* <p>If only a {@code Collection} or {@code Iterable} input is available, use
* {@link Collections2#transform} or {@link Iterables#transform}.
*
* <p><b>Note:</b> serializing the returned list is implemented by serializing
* {@code fromList}, its contents, and {@code function} -- <i>not</i> by
* serializing the transformed values. This can lead to surprising behavior,
* so serializing the returned list is <b>not recommended</b>. Instead,
* copy the list using {@link ImmutableList#copyOf(Collection)} (for example),
* then serialize the copy. Other methods similar to this do not implement
* serialization at all for this reason.
*/
public static <F, T> List<T> transform(
List<F> fromList, Function<? super F, ? extends T> function) {
return (fromList instanceof RandomAccess)
? new TransformingRandomAccessList<F, T>(fromList, function)
: new TransformingSequentialList<F, T>(fromList, function);
}
/**
* Implementation of a sequential transforming list.
*
* @see Lists#transform
*/
private static class TransformingSequentialList<F, T>
extends AbstractSequentialList<T> implements Serializable {
final List<F> fromList;
final Function<? super F, ? extends T> function;
TransformingSequentialList(
List<F> fromList, Function<? super F, ? extends T> function) {
this.fromList = checkNotNull(fromList);
this.function = checkNotNull(function);
}
/**
* The default implementation inherited is based on iteration and removal of
* each element which can be overkill. That's why we forward this call
* directly to the backing list.
*/
@Override public void clear() {
fromList.clear();
}
@Override public int size() {
return fromList.size();
}
@Override public ListIterator<T> listIterator(final int index) {
return new TransformedListIterator<F, T>(fromList.listIterator(index)) {
@Override
T transform(F from) {
return function.apply(from);
}
};
}
private static final long serialVersionUID = 0;
}
/**
* Implementation of a transforming random access list. We try to make as many
* of these methods pass-through to the source list as possible so that the
* performance characteristics of the source list and transformed list are
* similar.
*
* @see Lists#transform
*/
private static class TransformingRandomAccessList<F, T>
extends AbstractList<T> implements RandomAccess, Serializable {
final List<F> fromList;
final Function<? super F, ? extends T> function;
TransformingRandomAccessList(
List<F> fromList, Function<? super F, ? extends T> function) {
this.fromList = checkNotNull(fromList);
this.function = checkNotNull(function);
}
@Override public void clear() {
fromList.clear();
}
@Override public T get(int index) {
return function.apply(fromList.get(index));
}
@Override public Iterator<T> iterator() {
return listIterator();
}
@Override public ListIterator<T> listIterator(int index) {
return new TransformedListIterator<F, T>(fromList.listIterator(index)) {
@Override
T transform(F from) {
return function.apply(from);
}
};
}
@Override public boolean isEmpty() {
return fromList.isEmpty();
}
@Override public T remove(int index) {
return function.apply(fromList.remove(index));
}
@Override public int size() {
return fromList.size();
}
private static final long serialVersionUID = 0;
}
/**
* Returns consecutive {@linkplain List#subList(int, int) sublists} of a list,
* each of the same size (the final list may be smaller). For example,
* partitioning a list containing {@code [a, b, c, d, e]} with a partition
* size of 3 yields {@code [[a, b, c], [d, e]]} -- an outer list containing
* two inner lists of three and two elements, all in the original order.
*
* <p>The outer list is unmodifiable, but reflects the latest state of the
* source list. The inner lists are sublist views of the original list,
* produced on demand using {@link List#subList(int, int)}, and are subject
* to all the usual caveats about modification as explained in that API.
*
* @param list the list to return consecutive sublists of
* @param size the desired size of each sublist (the last may be
* smaller)
* @return a list of consecutive sublists
* @throws IllegalArgumentException if {@code partitionSize} is nonpositive
*/
public static <T> List<List<T>> partition(List<T> list, int size) {
checkNotNull(list);
checkArgument(size > 0);
return (list instanceof RandomAccess)
? new RandomAccessPartition<T>(list, size)
: new Partition<T>(list, size);
}
private static class Partition<T> extends AbstractList<List<T>> {
final List<T> list;
final int size;
Partition(List<T> list, int size) {
this.list = list;
this.size = size;
}
@Override public List<T> get(int index) {
checkElementIndex(index, size());
int start = index * size;
int end = Math.min(start + size, list.size());
return list.subList(start, end);
}
@Override public int size() {
return IntMath.divide(list.size(), size, RoundingMode.CEILING);
}
@Override public boolean isEmpty() {
return list.isEmpty();
}
}
private static class RandomAccessPartition<T> extends Partition<T>
implements RandomAccess {
RandomAccessPartition(List<T> list, int size) {
super(list, size);
}
}
/**
* Returns a view of the specified string as an immutable list of {@code
* Character} values.
*
* @since 7.0
*/
@Beta public static ImmutableList<Character> charactersOf(String string) {
return new StringAsImmutableList(checkNotNull(string));
}
@SuppressWarnings("serial") // serialized using ImmutableList serialization
private static final class StringAsImmutableList
extends ImmutableList<Character> {
private final String string;
StringAsImmutableList(String string) {
this.string = string;
}
@Override public int indexOf(@Nullable Object object) {
return (object instanceof Character)
? string.indexOf((Character) object) : -1;
}
@Override public int lastIndexOf(@Nullable Object object) {
return (object instanceof Character)
? string.lastIndexOf((Character) object) : -1;
}
@Override public ImmutableList<Character> subList(
int fromIndex, int toIndex) {
checkPositionIndexes(fromIndex, toIndex, size()); // for GWT
return charactersOf(string.substring(fromIndex, toIndex));
}
@Override boolean isPartialView() {
return false;
}
@Override public Character get(int index) {
checkElementIndex(index, size()); // for GWT
return string.charAt(index);
}
@Override public int size() {
return string.length();
}
}
/**
* Returns a view of the specified {@code CharSequence} as a {@code
* List<Character>}, viewing {@code sequence} as a sequence of Unicode code
* units. The view does not support any modification operations, but reflects
* any changes to the underlying character sequence.
*
* @param sequence the character sequence to view as a {@code List} of
* characters
* @return an {@code List<Character>} view of the character sequence
* @since 7.0
*/
@Beta public static List<Character> charactersOf(CharSequence sequence) {
return new CharSequenceAsList(checkNotNull(sequence));
}
private static final class CharSequenceAsList
extends AbstractList<Character> {
private final CharSequence sequence;
CharSequenceAsList(CharSequence sequence) {
this.sequence = sequence;
}
@Override public Character get(int index) {
checkElementIndex(index, size()); // for GWT
return sequence.charAt(index);
}
@Override public int size() {
return sequence.length();
}
}
/**
* Returns a reversed view of the specified list. For example, {@code
* Lists.reverse(Arrays.asList(1, 2, 3))} returns a list containing {@code 3,
* 2, 1}. The returned list is backed by this list, so changes in the returned
* list are reflected in this list, and vice-versa. The returned list supports
* all of the optional list operations supported by this list.
*
* <p>The returned list is random-access if the specified list is random
* access.
*
* @since 7.0
*/
public static <T> List<T> reverse(List<T> list) {
if (list instanceof ImmutableList) {
return ((ImmutableList<T>) list).reverse();
} else if (list instanceof ReverseList) {
return ((ReverseList<T>) list).getForwardList();
} else if (list instanceof RandomAccess) {
return new RandomAccessReverseList<T>(list);
} else {
return new ReverseList<T>(list);
}
}
private static class ReverseList<T> extends AbstractList<T> {
private final List<T> forwardList;
ReverseList(List<T> forwardList) {
this.forwardList = checkNotNull(forwardList);
}
List<T> getForwardList() {
return forwardList;
}
private int reverseIndex(int index) {
int size = size();
checkElementIndex(index, size);
return (size - 1) - index;
}
private int reversePosition(int index) {
int size = size();
checkPositionIndex(index, size);
return size - index;
}
@Override public void add(int index, @Nullable T element) {
forwardList.add(reversePosition(index), element);
}
@Override public void clear() {
forwardList.clear();
}
@Override public T remove(int index) {
return forwardList.remove(reverseIndex(index));
}
@Override protected void removeRange(int fromIndex, int toIndex) {
subList(fromIndex, toIndex).clear();
}
@Override public T set(int index, @Nullable T element) {
return forwardList.set(reverseIndex(index), element);
}
@Override public T get(int index) {
return forwardList.get(reverseIndex(index));
}
@Override public int size() {
return forwardList.size();
}
@Override public List<T> subList(int fromIndex, int toIndex) {
checkPositionIndexes(fromIndex, toIndex, size());
return reverse(forwardList.subList(
reversePosition(toIndex), reversePosition(fromIndex)));
}
@Override public Iterator<T> iterator() {
return listIterator();
}
@Override public ListIterator<T> listIterator(int index) {
int start = reversePosition(index);
final ListIterator<T> forwardIterator = forwardList.listIterator(start);
return new ListIterator<T>() {
boolean canRemoveOrSet;
@Override public void add(T e) {
forwardIterator.add(e);
forwardIterator.previous();
canRemoveOrSet = false;
}
@Override public boolean hasNext() {
return forwardIterator.hasPrevious();
}
@Override public boolean hasPrevious() {
return forwardIterator.hasNext();
}
@Override public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
canRemoveOrSet = true;
return forwardIterator.previous();
}
@Override public int nextIndex() {
return reversePosition(forwardIterator.nextIndex());
}
@Override public T previous() {
if (!hasPrevious()) {
throw new NoSuchElementException();
}
canRemoveOrSet = true;
return forwardIterator.next();
}
@Override public int previousIndex() {
return nextIndex() - 1;
}
@Override public void remove() {
checkRemove(canRemoveOrSet);
forwardIterator.remove();
canRemoveOrSet = false;
}
@Override public void set(T e) {
checkState(canRemoveOrSet);
forwardIterator.set(e);
}
};
}
}
private static class RandomAccessReverseList<T> extends ReverseList<T>
implements RandomAccess {
RandomAccessReverseList(List<T> forwardList) {
super(forwardList);
}
}
/**
* An implementation of {@link List#hashCode()}.
*/
static int hashCodeImpl(List<?> list) {
// TODO(user): worth optimizing for RandomAccess?
int hashCode = 1;
for (Object o : list) {
hashCode = 31 * hashCode + (o == null ? 0 : o.hashCode());
hashCode = ~~hashCode;
// needed to deal with GWT integer overflow
}
return hashCode;
}
/**
* An implementation of {@link List#equals(Object)}.
*/
static boolean equalsImpl(List<?> list, @Nullable Object object) {
if (object == checkNotNull(list)) {
return true;
}
if (!(object instanceof List)) {
return false;
}
List<?> o = (List<?>) object;
return list.size() == o.size()
&& Iterators.elementsEqual(list.iterator(), o.iterator());
}
/**
* An implementation of {@link List#addAll(int, Collection)}.
*/
static <E> boolean addAllImpl(
List<E> list, int index, Iterable<? extends E> elements) {
boolean changed = false;
ListIterator<E> listIterator = list.listIterator(index);
for (E e : elements) {
listIterator.add(e);
changed = true;
}
return changed;
}
/**
* An implementation of {@link List#indexOf(Object)}.
*/
static int indexOfImpl(List<?> list, @Nullable Object element) {
ListIterator<?> listIterator = list.listIterator();
while (listIterator.hasNext()) {
if (Objects.equal(element, listIterator.next())) {
return listIterator.previousIndex();
}
}
return -1;
}
/**
* An implementation of {@link List#lastIndexOf(Object)}.
*/
static int lastIndexOfImpl(List<?> list, @Nullable Object element) {
ListIterator<?> listIterator = list.listIterator(list.size());
while (listIterator.hasPrevious()) {
if (Objects.equal(element, listIterator.previous())) {
return listIterator.nextIndex();
}
}
return -1;
}
/**
* Returns an implementation of {@link List#listIterator(int)}.
*/
static <E> ListIterator<E> listIteratorImpl(List<E> list, int index) {
return new AbstractListWrapper<E>(list).listIterator(index);
}
/**
* An implementation of {@link List#subList(int, int)}.
*/
static <E> List<E> subListImpl(
final List<E> list, int fromIndex, int toIndex) {
List<E> wrapper;
if (list instanceof RandomAccess) {
wrapper = new RandomAccessListWrapper<E>(list) {
@Override public ListIterator<E> listIterator(int index) {
return backingList.listIterator(index);
}
private static final long serialVersionUID = 0;
};
} else {
wrapper = new AbstractListWrapper<E>(list) {
@Override public ListIterator<E> listIterator(int index) {
return backingList.listIterator(index);
}
private static final long serialVersionUID = 0;
};
}
return wrapper.subList(fromIndex, toIndex);
}
private static class AbstractListWrapper<E> extends AbstractList<E> {
final List<E> backingList;
AbstractListWrapper(List<E> backingList) {
this.backingList = checkNotNull(backingList);
}
@Override public void add(int index, E element) {
backingList.add(index, element);
}
@Override public boolean addAll(int index, Collection<? extends E> c) {
return backingList.addAll(index, c);
}
@Override public E get(int index) {
return backingList.get(index);
}
@Override public E remove(int index) {
return backingList.remove(index);
}
@Override public E set(int index, E element) {
return backingList.set(index, element);
}
@Override public boolean contains(Object o) {
return backingList.contains(o);
}
@Override public int size() {
return backingList.size();
}
}
private static class RandomAccessListWrapper<E>
extends AbstractListWrapper<E> implements RandomAccess {
RandomAccessListWrapper(List<E> backingList) {
super(backingList);
}
}
/**
* Used to avoid http://bugs.sun.com/view_bug.do?bug_id=6558557
*/
static <T> List<T> cast(Iterable<T> iterable) {
return (List<T>) iterable;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/Lists.java | Java | asf20 | 34,648 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.GwtCompatible;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map.Entry;
import javax.annotation.Nullable;
/**
* An immutable {@link ListMultimap} with reliable user-specified key and value
* iteration order. Does not permit null keys or values.
*
* <p>Unlike {@link Multimaps#unmodifiableListMultimap(ListMultimap)}, which is
* a <i>view</i> of a separate multimap which can still change, an instance of
* {@code ImmutableListMultimap} contains its own data and will <i>never</i>
* change. {@code ImmutableListMultimap} is convenient for
* {@code public static final} multimaps ("constant multimaps") and also lets
* you easily make a "defensive copy" of a multimap provided to your class by
* a caller.
*
* <p><b>Note:</b> Although this class is not final, it cannot be subclassed as
* it has no public or protected constructors. Thus, instances of this class
* are guaranteed to be immutable.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained">
* immutable collections</a>.
*
* @author Jared Levy
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(serializable = true, emulated = true)
public class ImmutableListMultimap<K, V>
extends ImmutableMultimap<K, V>
implements ListMultimap<K, V> {
/** Returns the empty multimap. */
// Casting is safe because the multimap will never hold any elements.
@SuppressWarnings("unchecked")
public static <K, V> ImmutableListMultimap<K, V> of() {
return (ImmutableListMultimap<K, V>) EmptyImmutableListMultimap.INSTANCE;
}
/**
* Returns an immutable multimap containing a single entry.
*/
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1) {
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
builder.put(k1, v1);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
*/
public static <K, V> ImmutableListMultimap<K, V> of(K k1, V v1, K k2, V v2) {
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
*/
public static <K, V> ImmutableListMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3) {
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
*/
public static <K, V> ImmutableListMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
builder.put(k4, v4);
return builder.build();
}
/**
* Returns an immutable multimap containing the given entries, in order.
*/
public static <K, V> ImmutableListMultimap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
builder.put(k1, v1);
builder.put(k2, v2);
builder.put(k3, v3);
builder.put(k4, v4);
builder.put(k5, v5);
return builder.build();
}
// looking for of() with > 5 entries? Use the builder instead.
/**
* Returns a new builder. The generated builder is equivalent to the builder
* created by the {@link Builder} constructor.
*/
public static <K, V> Builder<K, V> builder() {
return new Builder<K, V>();
}
/**
* A builder for creating immutable {@code ListMultimap} instances, especially
* {@code public static final} multimaps ("constant multimaps"). Example:
* <pre> {@code
*
* static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP =
* new ImmutableListMultimap.Builder<String, Integer>()
* .put("one", 1)
* .putAll("several", 1, 2, 3)
* .putAll("many", 1, 2, 3, 4, 5)
* .build();}</pre>
*
* <p>Builder instances can be reused; it is safe to call {@link #build} multiple
* times to build multiple multimaps in series. Each multimap contains the
* key-value mappings in the previously created multimaps.
*
* @since 2.0 (imported from Google Collections Library)
*/
public static final class Builder<K, V>
extends ImmutableMultimap.Builder<K, V> {
/**
* Creates a new builder. The returned builder is equivalent to the builder
* generated by {@link ImmutableListMultimap#builder}.
*/
public Builder() {}
@Override public Builder<K, V> put(K key, V value) {
super.put(key, value);
return this;
}
/**
* {@inheritDoc}
*
* @since 11.0
*/
@Override public Builder<K, V> put(
Entry<? extends K, ? extends V> entry) {
super.put(entry);
return this;
}
@Override public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
super.putAll(key, values);
return this;
}
@Override public Builder<K, V> putAll(K key, V... values) {
super.putAll(key, values);
return this;
}
@Override public Builder<K, V> putAll(
Multimap<? extends K, ? extends V> multimap) {
super.putAll(multimap);
return this;
}
/**
* {@inheritDoc}
*
* @since 8.0
*/
@Override
public Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator) {
super.orderKeysBy(keyComparator);
return this;
}
/**
* {@inheritDoc}
*
* @since 8.0
*/
@Override
public Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator) {
super.orderValuesBy(valueComparator);
return this;
}
/**
* Returns a newly-created immutable list multimap.
*/
@Override public ImmutableListMultimap<K, V> build() {
return (ImmutableListMultimap<K, V>) super.build();
}
}
/**
* Returns an immutable multimap containing the same mappings as {@code
* multimap}. The generated multimap's key and value orderings correspond to
* the iteration ordering of the {@code multimap.asMap()} view.
*
* <p>Despite the method name, this method attempts to avoid actually copying
* the data when it is safe to do so. The exact circumstances under which a
* copy will or will not be performed are undocumented and subject to change.
*
* @throws NullPointerException if any key or value in {@code multimap} is
* null
*/
public static <K, V> ImmutableListMultimap<K, V> copyOf(
Multimap<? extends K, ? extends V> multimap) {
if (multimap.isEmpty()) {
return of();
}
// TODO(user): copy ImmutableSetMultimap by using asList() on the sets
if (multimap instanceof ImmutableListMultimap) {
@SuppressWarnings("unchecked") // safe since multimap is not writable
ImmutableListMultimap<K, V> kvMultimap
= (ImmutableListMultimap<K, V>) multimap;
if (!kvMultimap.isPartialView()) {
return kvMultimap;
}
}
ImmutableMap.Builder<K, ImmutableList<V>> builder = ImmutableMap.builder();
int size = 0;
for (Entry<? extends K, ? extends Collection<? extends V>> entry
: multimap.asMap().entrySet()) {
ImmutableList<V> list = ImmutableList.copyOf(entry.getValue());
if (!list.isEmpty()) {
builder.put(entry.getKey(), list);
size += list.size();
}
}
return new ImmutableListMultimap<K, V>(builder.build(), size);
}
ImmutableListMultimap(ImmutableMap<K, ImmutableList<V>> map, int size) {
super(map, size);
}
// views
/**
* Returns an immutable list of the values for the given key. If no mappings
* in the multimap have the provided key, an empty immutable list is
* returned. The values are in the same order as the parameters used to build
* this multimap.
*/
@Override public ImmutableList<V> get(@Nullable K key) {
// This cast is safe as its type is known in constructor.
ImmutableList<V> list = (ImmutableList<V>) map.get(key);
return (list == null) ? ImmutableList.<V>of() : list;
}
private transient ImmutableListMultimap<V, K> inverse;
/**
* {@inheritDoc}
*
* <p>Because an inverse of a list multimap can contain multiple pairs with
* the same key and value, this method returns an {@code
* ImmutableListMultimap} rather than the {@code ImmutableMultimap} specified
* in the {@code ImmutableMultimap} class.
*
* @since 11.0
*/
@Override
public ImmutableListMultimap<V, K> inverse() {
ImmutableListMultimap<V, K> result = inverse;
return (result == null) ? (inverse = invert()) : result;
}
private ImmutableListMultimap<V, K> invert() {
Builder<V, K> builder = builder();
for (Entry<K, V> entry : entries()) {
builder.put(entry.getValue(), entry.getKey());
}
ImmutableListMultimap<V, K> invertedMultimap = builder.build();
invertedMultimap.inverse = this;
return invertedMultimap;
}
/**
* Guaranteed to throw an exception and leave the multimap unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated @Override public ImmutableList<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
/**
* Guaranteed to throw an exception and leave the multimap unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated @Override public ImmutableList<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableListMultimap.java | Java | asf20 | 10,671 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nullable;
/**
* A {@code BiMap} backed by an {@code EnumMap} instance for keys-to-values, and
* a {@code HashMap} instance for values-to-keys. Null keys are not permitted,
* but null values are. An {@code EnumHashBiMap} and its inverse are both
* serializable.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#BiMap">
* {@code BiMap}</a>.
*
* @author Mike Bostock
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class EnumHashBiMap<K extends Enum<K>, V>
extends AbstractBiMap<K, V> {
private transient Class<K> keyType;
/**
* Returns a new, empty {@code EnumHashBiMap} using the specified key type.
*
* @param keyType the key type
*/
public static <K extends Enum<K>, V> EnumHashBiMap<K, V>
create(Class<K> keyType) {
return new EnumHashBiMap<K, V>(keyType);
}
/**
* Constructs a new bimap with the same mappings as the specified map. If the
* specified map is an {@code EnumHashBiMap} or an {@link EnumBiMap}, the new
* bimap has the same key type as the input bimap. Otherwise, the specified
* map must contain at least one mapping, in order to determine the key type.
*
* @param map the map whose mappings are to be placed in this map
* @throws IllegalArgumentException if map is not an {@code EnumBiMap} or an
* {@code EnumHashBiMap} instance and contains no mappings
*/
public static <K extends Enum<K>, V> EnumHashBiMap<K, V>
create(Map<K, ? extends V> map) {
EnumHashBiMap<K, V> bimap = create(EnumBiMap.inferKeyType(map));
bimap.putAll(map);
return bimap;
}
private EnumHashBiMap(Class<K> keyType) {
super(WellBehavedMap.wrap(
new EnumMap<K, V>(keyType)),
Maps.<V, K>newHashMapWithExpectedSize(
keyType.getEnumConstants().length));
this.keyType = keyType;
}
// Overriding these 3 methods to show that values may be null (but not keys)
@Override
K checkKey(K key) {
return checkNotNull(key);
}
@Override public V put(K key, @Nullable V value) {
return super.put(key, value);
}
@Override public V forcePut(K key, @Nullable V value) {
return super.forcePut(key, value);
}
/** Returns the associated key type. */
public Class<K> keyType() {
return keyType;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/EnumHashBiMap.java | Java | asf20 | 3,221 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.GwtCompatible;
import com.google.gwt.core.client.GwtScriptOnly;
import com.google.gwt.lang.Array;
/**
* Version of {@link GwtPlatform} used in web-mode. It includes methods in
* {@link Platform} that requires different implementions in web mode and
* hosted mode. It is factored out from {@link Platform} because <code>
* {@literal @}GwtScriptOnly</code> only supports public classes and methods.
*
* @author Hayward Chan
*/
@GwtCompatible
@GwtScriptOnly
public final class GwtPlatform {
private GwtPlatform() {}
public static <T> T[] newArray(T[] reference, int length) {
return Array.createFrom(reference, length);
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GwtPlatform.java | Java | asf20 | 1,318 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* A GWT-only class only used by GWT emulations. It is used to consolidate the
* definitions of method delegation to save code size.
*
* @author Hayward Chan
*/
// TODO: Make this class GWT serializable.
class ForwardingImmutableCollection<E> extends ImmutableCollection<E> {
transient final Collection<E> delegate;
ForwardingImmutableCollection(Collection<E> delegate) {
this.delegate = delegate;
}
@Override public UnmodifiableIterator<E> iterator() {
return Iterators.unmodifiableIterator(delegate.iterator());
}
@Override public boolean contains(@Nullable Object object) {
return object != null && delegate.contains(object);
}
@Override public boolean containsAll(Collection<?> targets) {
return delegate.containsAll(targets);
}
public int size() {
return delegate.size();
}
@Override public boolean isEmpty() {
return delegate.isEmpty();
}
@Override public Object[] toArray() {
return delegate.toArray();
}
@Override public <T> T[] toArray(T[] other) {
return delegate.toArray(other);
}
@Override public String toString() {
return delegate.toString();
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ForwardingImmutableCollection.java | Java | asf20 | 1,857 |
/*
* Copyright (C) 2008 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.GwtCompatible;
import com.google.common.collect.Multiset.Entry;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import javax.annotation.Nullable;
/**
* An immutable hash-based multiset. Does not permit null elements.
*
* <p>Its iterator orders elements according to the first appearance of the
* element among the items passed to the factory method or builder. When the
* multiset contains multiple instances of an element, those instances are
* consecutive in the iteration order.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/ImmutableCollectionsExplained">
* immutable collections</a>.
*
* @author Jared Levy
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
// TODO(user): write an efficient asList() implementation
public abstract class ImmutableMultiset<E> extends ImmutableCollection<E>
implements Multiset<E> {
private static final ImmutableMultiset<Object> EMPTY =
new RegularImmutableMultiset<Object>(ImmutableMap.<Object, Integer>of(), 0);
/**
* Returns the empty immutable multiset.
*/
@SuppressWarnings("unchecked") // all supported methods are covariant
public static <E> ImmutableMultiset<E> of() {
return (ImmutableMultiset<E>) EMPTY;
}
/**
* Returns an immutable multiset containing a single element.
*
* @throws NullPointerException if {@code element} is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") // generic array created but never written
public static <E> ImmutableMultiset<E> of(E element) {
return copyOfInternal(element);
}
/**
* Returns an immutable multiset containing the given elements, in order.
*
* @throws NullPointerException if any element is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") //
public static <E> ImmutableMultiset<E> of(E e1, E e2) {
return copyOfInternal(e1, e2);
}
/**
* Returns an immutable multiset containing the given elements, in order.
*
* @throws NullPointerException if any element is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") //
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3) {
return copyOfInternal(e1, e2, e3);
}
/**
* Returns an immutable multiset containing the given elements, in order.
*
* @throws NullPointerException if any element is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") //
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3, E e4) {
return copyOfInternal(e1, e2, e3, e4);
}
/**
* Returns an immutable multiset containing the given elements, in order.
*
* @throws NullPointerException if any element is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") //
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3, E e4, E e5) {
return copyOfInternal(e1, e2, e3, e4, e5);
}
/**
* Returns an immutable multiset containing the given elements, in order.
*
* @throws NullPointerException if any element is null
* @since 6.0 (source-compatible since 2.0)
*/
@SuppressWarnings("unchecked") //
public static <E> ImmutableMultiset<E> of(
E e1, E e2, E e3, E e4, E e5, E e6, E... others) {
return new Builder<E>()
.add(e1)
.add(e2)
.add(e3)
.add(e4)
.add(e5)
.add(e6)
.add(others)
.build();
}
/**
* Returns an immutable multiset containing the given elements.
*
* <p>The multiset is ordered by the first occurrence of each element. For
* example, {@code ImmutableMultiset.copyOf([2, 3, 1, 3])} yields a multiset
* with elements in the order {@code 2, 3, 3, 1}.
*
* @throws NullPointerException if any of {@code elements} is null
* @since 6.0
*/
public static <E> ImmutableMultiset<E> copyOf(E[] elements) {
return copyOf(Arrays.asList(elements));
}
/**
* Returns an immutable multiset containing the given elements.
*
* <p>The multiset is ordered by the first occurrence of each element. For
* example, {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3))} yields
* a multiset with elements in the order {@code 2, 3, 3, 1}.
*
* <p>Despite the method name, this method attempts to avoid actually copying
* the data when it is safe to do so. The exact circumstances under which a
* copy will or will not be performed are undocumented and subject to change.
*
* <p><b>Note:</b> Despite what the method name suggests, if {@code elements}
* is an {@code ImmutableMultiset}, no copy will actually be performed, and
* the given multiset itself will be returned.
*
* @throws NullPointerException if any of {@code elements} is null
*/
public static <E> ImmutableMultiset<E> copyOf(
Iterable<? extends E> elements) {
if (elements instanceof ImmutableMultiset) {
@SuppressWarnings("unchecked") // all supported methods are covariant
ImmutableMultiset<E> result = (ImmutableMultiset<E>) elements;
if (!result.isPartialView()) {
return result;
}
}
Multiset<? extends E> multiset = (elements instanceof Multiset)
? Multisets.cast(elements)
: LinkedHashMultiset.create(elements);
return copyOfInternal(multiset);
}
private static <E> ImmutableMultiset<E> copyOfInternal(E... elements) {
return copyOf(Arrays.asList(elements));
}
private static <E> ImmutableMultiset<E> copyOfInternal(
Multiset<? extends E> multiset) {
return copyFromEntries(multiset.entrySet());
}
static <E> ImmutableMultiset<E> copyFromEntries(
Collection<? extends Entry<? extends E>> entries) {
long size = 0;
ImmutableMap.Builder<E, Integer> builder = ImmutableMap.builder();
for (Entry<? extends E> entry : entries) {
int count = entry.getCount();
if (count > 0) {
// Since ImmutableMap.Builder throws an NPE if an element is null, no
// other null checks are needed.
builder.put(entry.getElement(), count);
size += count;
}
}
if (size == 0) {
return of();
}
return new RegularImmutableMultiset<E>(
builder.build(), Ints.saturatedCast(size));
}
/**
* Returns an immutable multiset containing the given elements.
*
* <p>The multiset is ordered by the first occurrence of each element. For
* example,
* {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3).iterator())}
* yields a multiset with elements in the order {@code 2, 3, 3, 1}.
*
* @throws NullPointerException if any of {@code elements} is null
*/
public static <E> ImmutableMultiset<E> copyOf(
Iterator<? extends E> elements) {
Multiset<E> multiset = LinkedHashMultiset.create();
Iterators.addAll(multiset, elements);
return copyOfInternal(multiset);
}
ImmutableMultiset() {}
@Override public UnmodifiableIterator<E> iterator() {
final Iterator<Entry<E>> entryIterator = entrySet().iterator();
return new UnmodifiableIterator<E>() {
int remaining;
E element;
@Override
public boolean hasNext() {
return (remaining > 0) || entryIterator.hasNext();
}
@Override
public E next() {
if (remaining <= 0) {
Entry<E> entry = entryIterator.next();
element = entry.getElement();
remaining = entry.getCount();
}
remaining--;
return element;
}
};
}
@Override
public boolean contains(@Nullable Object object) {
return count(object) > 0;
}
@Override
public boolean containsAll(Collection<?> targets) {
return elementSet().containsAll(targets);
}
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated
@Override
public final int add(E element, int occurrences) {
throw new UnsupportedOperationException();
}
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated
@Override
public final int remove(Object element, int occurrences) {
throw new UnsupportedOperationException();
}
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated
@Override
public final int setCount(E element, int count) {
throw new UnsupportedOperationException();
}
/**
* Guaranteed to throw an exception and leave the collection unmodified.
*
* @throws UnsupportedOperationException always
* @deprecated Unsupported operation.
*/
@Deprecated
@Override
public final boolean setCount(E element, int oldCount, int newCount) {
throw new UnsupportedOperationException();
}
@Override public boolean equals(@Nullable Object object) {
return Multisets.equalsImpl(this, object);
}
@Override public int hashCode() {
return Sets.hashCodeImpl(entrySet());
}
@Override public String toString() {
return entrySet().toString();
}
private transient ImmutableSet<Entry<E>> entrySet;
@Override
public ImmutableSet<Entry<E>> entrySet() {
ImmutableSet<Entry<E>> es = entrySet;
return (es == null) ? (entrySet = createEntrySet()) : es;
}
private final ImmutableSet<Entry<E>> createEntrySet() {
return isEmpty() ? ImmutableSet.<Entry<E>>of() : new EntrySet();
}
abstract Entry<E> getEntry(int index);
private final class EntrySet extends ImmutableSet<Entry<E>> {
@Override
boolean isPartialView() {
return ImmutableMultiset.this.isPartialView();
}
@Override
public UnmodifiableIterator<Entry<E>> iterator() {
return asList().iterator();
}
@Override
ImmutableList<Entry<E>> createAsList() {
return new ImmutableAsList<Entry<E>>() {
@Override
public Entry<E> get(int index) {
return getEntry(index);
}
@Override
ImmutableCollection<Entry<E>> delegateCollection() {
return EntrySet.this;
}
};
}
@Override
public int size() {
return elementSet().size();
}
@Override
public boolean contains(Object o) {
if (o instanceof Entry) {
Entry<?> entry = (Entry<?>) o;
if (entry.getCount() <= 0) {
return false;
}
int count = count(entry.getElement());
return count == entry.getCount();
}
return false;
}
@Override
public int hashCode() {
return ImmutableMultiset.this.hashCode();
}
// We can't label this with @Override, because it doesn't override anything
// in the GWT emulated version.
// TODO(cpovirk): try making all copies of this method @GwtIncompatible instead
Object writeReplace() {
return new EntrySetSerializedForm<E>(ImmutableMultiset.this);
}
private static final long serialVersionUID = 0;
}
static class EntrySetSerializedForm<E> implements Serializable {
final ImmutableMultiset<E> multiset;
EntrySetSerializedForm(ImmutableMultiset<E> multiset) {
this.multiset = multiset;
}
Object readResolve() {
return multiset.entrySet();
}
}
private static class SerializedForm implements Serializable {
final Object[] elements;
final int[] counts;
SerializedForm(Multiset<?> multiset) {
int distinct = multiset.entrySet().size();
elements = new Object[distinct];
counts = new int[distinct];
int i = 0;
for (Entry<?> entry : multiset.entrySet()) {
elements[i] = entry.getElement();
counts[i] = entry.getCount();
i++;
}
}
Object readResolve() {
LinkedHashMultiset<Object> multiset =
LinkedHashMultiset.create(elements.length);
for (int i = 0; i < elements.length; i++) {
multiset.add(elements[i], counts[i]);
}
return ImmutableMultiset.copyOf(multiset);
}
private static final long serialVersionUID = 0;
}
// We can't label this with @Override, because it doesn't override anything
// in the GWT emulated version.
Object writeReplace() {
return new SerializedForm(this);
}
/**
* Returns a new builder. The generated builder is equivalent to the builder
* created by the {@link Builder} constructor.
*/
public static <E> Builder<E> builder() {
return new Builder<E>();
}
/**
* A builder for creating immutable multiset instances, especially {@code
* public static final} multisets ("constant multisets"). Example:
* <pre> {@code
*
* public static final ImmutableMultiset<Bean> BEANS =
* new ImmutableMultiset.Builder<Bean>()
* .addCopies(Bean.COCOA, 4)
* .addCopies(Bean.GARDEN, 6)
* .addCopies(Bean.RED, 8)
* .addCopies(Bean.BLACK_EYED, 10)
* .build();}</pre>
*
* <p>Builder instances can be reused; it is safe to call {@link #build} multiple
* times to build multiple multisets in series.
*
* @since 2.0 (imported from Google Collections Library)
*/
public static class Builder<E> extends ImmutableCollection.Builder<E> {
final Multiset<E> contents;
/**
* Creates a new builder. The returned builder is equivalent to the builder
* generated by {@link ImmutableMultiset#builder}.
*/
public Builder() {
this(LinkedHashMultiset.<E>create());
}
Builder(Multiset<E> contents) {
this.contents = contents;
}
/**
* Adds {@code element} to the {@code ImmutableMultiset}.
*
* @param element the element to add
* @return this {@code Builder} object
* @throws NullPointerException if {@code element} is null
*/
@Override public Builder<E> add(E element) {
contents.add(checkNotNull(element));
return this;
}
/**
* Adds a number of occurrences of an element to this {@code
* ImmutableMultiset}.
*
* @param element the element to add
* @param occurrences the number of occurrences of the element to add. May
* be zero, in which case no change will be made.
* @return this {@code Builder} object
* @throws NullPointerException if {@code element} is null
* @throws IllegalArgumentException if {@code occurrences} is negative, or
* if this operation would result in more than {@link Integer#MAX_VALUE}
* occurrences of the element
*/
public Builder<E> addCopies(E element, int occurrences) {
contents.add(checkNotNull(element), occurrences);
return this;
}
/**
* Adds or removes the necessary occurrences of an element such that the
* element attains the desired count.
*
* @param element the element to add or remove occurrences of
* @param count the desired count of the element in this multiset
* @return this {@code Builder} object
* @throws NullPointerException if {@code element} is null
* @throws IllegalArgumentException if {@code count} is negative
*/
public Builder<E> setCount(E element, int count) {
contents.setCount(checkNotNull(element), count);
return this;
}
/**
* Adds each element of {@code elements} to the {@code ImmutableMultiset}.
*
* @param elements the elements to add
* @return this {@code Builder} object
* @throws NullPointerException if {@code elements} is null or contains a
* null element
*/
@Override public Builder<E> add(E... elements) {
super.add(elements);
return this;
}
/**
* Adds each element of {@code elements} to the {@code ImmutableMultiset}.
*
* @param elements the {@code Iterable} to add to the {@code
* ImmutableMultiset}
* @return this {@code Builder} object
* @throws NullPointerException if {@code elements} is null or contains a
* null element
*/
@Override public Builder<E> addAll(Iterable<? extends E> elements) {
if (elements instanceof Multiset) {
Multiset<? extends E> multiset = Multisets.cast(elements);
for (Entry<? extends E> entry : multiset.entrySet()) {
addCopies(entry.getElement(), entry.getCount());
}
} else {
super.addAll(elements);
}
return this;
}
/**
* Adds each element of {@code elements} to the {@code ImmutableMultiset}.
*
* @param elements the elements to add to the {@code ImmutableMultiset}
* @return this {@code Builder} object
* @throws NullPointerException if {@code elements} is null or contains a
* null element
*/
@Override public Builder<E> addAll(Iterator<? extends E> elements) {
super.addAll(elements);
return this;
}
/**
* Returns a newly-created {@code ImmutableMultiset} based on the contents
* of the {@code Builder}.
*/
@Override public ImmutableMultiset<E> build() {
return copyOf(contents);
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableMultiset.java | Java | asf20 | 18,276 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.compose;
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Converter;
import com.google.common.base.Equivalence;
import com.google.common.base.Function;
import com.google.common.base.Joiner.MapJoiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nullable;
/**
* Static utility methods pertaining to {@link Map} instances (including instances of
* {@link SortedMap}, {@link BiMap}, etc.). Also see this class's counterparts
* {@link Lists}, {@link Sets} and {@link Queues}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Maps">
* {@code Maps}</a>.
*
* @author Kevin Bourrillion
* @author Mike Bostock
* @author Isaac Shum
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class Maps {
private Maps() {}
private enum EntryFunction implements Function<Entry<?, ?>, Object> {
KEY {
@Override
@Nullable
public Object apply(Entry<?, ?> entry) {
return entry.getKey();
}
},
VALUE {
@Override
@Nullable
public Object apply(Entry<?, ?> entry) {
return entry.getValue();
}
};
}
@SuppressWarnings("unchecked")
static <K> Function<Entry<K, ?>, K> keyFunction() {
return (Function) EntryFunction.KEY;
}
@SuppressWarnings("unchecked")
static <V> Function<Entry<?, V>, V> valueFunction() {
return (Function) EntryFunction.VALUE;
}
static <K, V> Iterator<K> keyIterator(Iterator<Entry<K, V>> entryIterator) {
return Iterators.transform(entryIterator, Maps.<K>keyFunction());
}
static <K, V> Iterator<V> valueIterator(Iterator<Entry<K, V>> entryIterator) {
return Iterators.transform(entryIterator, Maps.<V>valueFunction());
}
static <K, V> UnmodifiableIterator<V> valueIterator(
final UnmodifiableIterator<Entry<K, V>> entryIterator) {
return new UnmodifiableIterator<V>() {
@Override
public boolean hasNext() {
return entryIterator.hasNext();
}
@Override
public V next() {
return entryIterator.next().getValue();
}
};
}
/**
* Returns an immutable map instance containing the given entries.
* Internally, the returned map will be backed by an {@link EnumMap}.
*
* <p>The iteration order of the returned map follows the enum's iteration
* order, not the order in which the elements appear in the given map.
*
* @param map the map to make an immutable copy of
* @return an immutable map containing those entries
* @since 14.0
*/
@GwtCompatible(serializable = true)
@Beta
public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
Map<K, ? extends V> map) {
if (map instanceof ImmutableEnumMap) {
@SuppressWarnings("unchecked") // safe covariant cast
ImmutableEnumMap<K, V> result = (ImmutableEnumMap<K, V>) map;
return result;
} else if (map.isEmpty()) {
return ImmutableMap.of();
} else {
for (Map.Entry<K, ? extends V> entry : map.entrySet()) {
checkNotNull(entry.getKey());
checkNotNull(entry.getValue());
}
return ImmutableEnumMap.asImmutable(new EnumMap<K, V>(map));
}
}
/**
* Creates a <i>mutable</i>, empty {@code HashMap} instance.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableMap#of()} instead.
*
* <p><b>Note:</b> if {@code K} is an {@code enum} type, use {@link
* #newEnumMap} instead.
*
* @return a new, empty {@code HashMap}
*/
public static <K, V> HashMap<K, V> newHashMap() {
return new HashMap<K, V>();
}
/**
* Creates a {@code HashMap} instance, with a high enough "initial capacity"
* that it <i>should</i> hold {@code expectedSize} elements without growth.
* This behavior cannot be broadly guaranteed, but it is observed to be true
* for OpenJDK 1.6. It also can't be guaranteed that the method isn't
* inadvertently <i>oversizing</i> the returned map.
*
* @param expectedSize the number of elements you expect to add to the
* returned map
* @return a new, empty {@code HashMap} with enough capacity to hold {@code
* expectedSize} elements without resizing
* @throws IllegalArgumentException if {@code expectedSize} is negative
*/
public static <K, V> HashMap<K, V> newHashMapWithExpectedSize(
int expectedSize) {
return new HashMap<K, V>(capacity(expectedSize));
}
/**
* Returns a capacity that is sufficient to keep the map from being resized as
* long as it grows no larger than expectedSize and the load factor is >= its
* default (0.75).
*/
static int capacity(int expectedSize) {
if (expectedSize < 3) {
checkNonnegative(expectedSize, "expectedSize");
return expectedSize + 1;
}
if (expectedSize < Ints.MAX_POWER_OF_TWO) {
return expectedSize + expectedSize / 3;
}
return Integer.MAX_VALUE; // any large value
}
/**
* Creates a <i>mutable</i> {@code HashMap} instance with the same mappings as
* the specified map.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableMap#copyOf(Map)} instead.
*
* <p><b>Note:</b> if {@code K} is an {@link Enum} type, use {@link
* #newEnumMap} instead.
*
* @param map the mappings to be placed in the new map
* @return a new {@code HashMap} initialized with the mappings from {@code
* map}
*/
public static <K, V> HashMap<K, V> newHashMap(
Map<? extends K, ? extends V> map) {
return new HashMap<K, V>(map);
}
/**
* Creates a <i>mutable</i>, empty, insertion-ordered {@code LinkedHashMap}
* instance.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableMap#of()} instead.
*
* @return a new, empty {@code LinkedHashMap}
*/
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap() {
return new LinkedHashMap<K, V>();
}
/**
* Creates a <i>mutable</i>, insertion-ordered {@code LinkedHashMap} instance
* with the same mappings as the specified map.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableMap#copyOf(Map)} instead.
*
* @param map the mappings to be placed in the new map
* @return a new, {@code LinkedHashMap} initialized with the mappings from
* {@code map}
*/
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(
Map<? extends K, ? extends V> map) {
return new LinkedHashMap<K, V>(map);
}
/**
* Returns a general-purpose instance of {@code ConcurrentMap}, which supports
* all optional operations of the ConcurrentMap interface. It does not permit
* null keys or values. It is serializable.
*
* <p>This is currently accomplished by calling {@link MapMaker#makeMap()}.
*
* <p>It is preferable to use {@code MapMaker} directly (rather than through
* this method), as it presents numerous useful configuration options,
* such as the concurrency level, load factor, key/value reference types,
* and value computation.
*
* @return a new, empty {@code ConcurrentMap}
* @since 3.0
*/
public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
return new MapMaker().<K, V>makeMap();
}
/**
* Creates a <i>mutable</i>, empty {@code TreeMap} instance using the natural
* ordering of its elements.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSortedMap#of()} instead.
*
* @return a new, empty {@code TreeMap}
*/
public static <K extends Comparable, V> TreeMap<K, V> newTreeMap() {
return new TreeMap<K, V>();
}
/**
* Creates a <i>mutable</i> {@code TreeMap} instance with the same mappings as
* the specified map and using the same ordering as the specified map.
*
* <p><b>Note:</b> if mutability is not required, use {@link
* ImmutableSortedMap#copyOfSorted(SortedMap)} instead.
*
* @param map the sorted map whose mappings are to be placed in the new map
* and whose comparator is to be used to sort the new map
* @return a new {@code TreeMap} initialized with the mappings from {@code
* map} and using the comparator of {@code map}
*/
public static <K, V> TreeMap<K, V> newTreeMap(SortedMap<K, ? extends V> map) {
return new TreeMap<K, V>(map);
}
/**
* Creates a <i>mutable</i>, empty {@code TreeMap} instance using the given
* comparator.
*
* <p><b>Note:</b> if mutability is not required, use {@code
* ImmutableSortedMap.orderedBy(comparator).build()} instead.
*
* @param comparator the comparator to sort the keys with
* @return a new, empty {@code TreeMap}
*/
public static <C, K extends C, V> TreeMap<K, V> newTreeMap(
@Nullable Comparator<C> comparator) {
// Ideally, the extra type parameter "C" shouldn't be necessary. It is a
// work-around of a compiler type inference quirk that prevents the
// following code from being compiled:
// Comparator<Class<?>> comparator = null;
// Map<Class<? extends Throwable>, String> map = newTreeMap(comparator);
return new TreeMap<K, V>(comparator);
}
/**
* Creates an {@code EnumMap} instance.
*
* @param type the key type for this map
* @return a new, empty {@code EnumMap}
*/
public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(Class<K> type) {
return new EnumMap<K, V>(checkNotNull(type));
}
/**
* Creates an {@code EnumMap} with the same mappings as the specified map.
*
* @param map the map from which to initialize this {@code EnumMap}
* @return a new {@code EnumMap} initialized with the mappings from {@code
* map}
* @throws IllegalArgumentException if {@code m} is not an {@code EnumMap}
* instance and contains no mappings
*/
public static <K extends Enum<K>, V> EnumMap<K, V> newEnumMap(
Map<K, ? extends V> map) {
return new EnumMap<K, V>(map);
}
/**
* Creates an {@code IdentityHashMap} instance.
*
* @return a new, empty {@code IdentityHashMap}
*/
public static <K, V> IdentityHashMap<K, V> newIdentityHashMap() {
return new IdentityHashMap<K, V>();
}
/**
* Computes the difference between two maps. This difference is an immutable
* snapshot of the state of the maps at the time this method is called. It
* will never change, even if the maps change at a later time.
*
* <p>Since this method uses {@code HashMap} instances internally, the keys of
* the supplied maps must be well-behaved with respect to
* {@link Object#equals} and {@link Object#hashCode}.
*
* <p><b>Note:</b>If you only need to know whether two maps have the same
* mappings, call {@code left.equals(right)} instead of this method.
*
* @param left the map to treat as the "left" map for purposes of comparison
* @param right the map to treat as the "right" map for purposes of comparison
* @return the difference between the two maps
*/
@SuppressWarnings("unchecked")
public static <K, V> MapDifference<K, V> difference(
Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right) {
if (left instanceof SortedMap) {
SortedMap<K, ? extends V> sortedLeft = (SortedMap<K, ? extends V>) left;
SortedMapDifference<K, V> result = difference(sortedLeft, right);
return result;
}
return difference(left, right, Equivalence.equals());
}
/**
* Computes the difference between two maps. This difference is an immutable
* snapshot of the state of the maps at the time this method is called. It
* will never change, even if the maps change at a later time.
*
* <p>Values are compared using a provided equivalence, in the case of
* equality, the value on the 'left' is returned in the difference.
*
* <p>Since this method uses {@code HashMap} instances internally, the keys of
* the supplied maps must be well-behaved with respect to
* {@link Object#equals} and {@link Object#hashCode}.
*
* @param left the map to treat as the "left" map for purposes of comparison
* @param right the map to treat as the "right" map for purposes of comparison
* @param valueEquivalence the equivalence relationship to use to compare
* values
* @return the difference between the two maps
* @since 10.0
*/
@Beta
public static <K, V> MapDifference<K, V> difference(
Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right,
Equivalence<? super V> valueEquivalence) {
Preconditions.checkNotNull(valueEquivalence);
Map<K, V> onlyOnLeft = newHashMap();
Map<K, V> onlyOnRight = new HashMap<K, V>(right); // will whittle it down
Map<K, V> onBoth = newHashMap();
Map<K, MapDifference.ValueDifference<V>> differences = newHashMap();
doDifference(left, right, valueEquivalence, onlyOnLeft, onlyOnRight, onBoth, differences);
return new MapDifferenceImpl<K, V>(onlyOnLeft, onlyOnRight, onBoth, differences);
}
private static <K, V> void doDifference(
Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right,
Equivalence<? super V> valueEquivalence,
Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth,
Map<K, MapDifference.ValueDifference<V>> differences) {
for (Entry<? extends K, ? extends V> entry : left.entrySet()) {
K leftKey = entry.getKey();
V leftValue = entry.getValue();
if (right.containsKey(leftKey)) {
V rightValue = onlyOnRight.remove(leftKey);
if (valueEquivalence.equivalent(leftValue, rightValue)) {
onBoth.put(leftKey, leftValue);
} else {
differences.put(
leftKey, ValueDifferenceImpl.create(leftValue, rightValue));
}
} else {
onlyOnLeft.put(leftKey, leftValue);
}
}
}
private static <K, V> Map<K, V> unmodifiableMap(Map<K, V> map) {
if (map instanceof SortedMap) {
return Collections.unmodifiableSortedMap((SortedMap<K, ? extends V>) map);
} else {
return Collections.unmodifiableMap(map);
}
}
static class MapDifferenceImpl<K, V> implements MapDifference<K, V> {
final Map<K, V> onlyOnLeft;
final Map<K, V> onlyOnRight;
final Map<K, V> onBoth;
final Map<K, ValueDifference<V>> differences;
MapDifferenceImpl(Map<K, V> onlyOnLeft,
Map<K, V> onlyOnRight, Map<K, V> onBoth,
Map<K, ValueDifference<V>> differences) {
this.onlyOnLeft = unmodifiableMap(onlyOnLeft);
this.onlyOnRight = unmodifiableMap(onlyOnRight);
this.onBoth = unmodifiableMap(onBoth);
this.differences = unmodifiableMap(differences);
}
@Override
public boolean areEqual() {
return onlyOnLeft.isEmpty() && onlyOnRight.isEmpty() && differences.isEmpty();
}
@Override
public Map<K, V> entriesOnlyOnLeft() {
return onlyOnLeft;
}
@Override
public Map<K, V> entriesOnlyOnRight() {
return onlyOnRight;
}
@Override
public Map<K, V> entriesInCommon() {
return onBoth;
}
@Override
public Map<K, ValueDifference<V>> entriesDiffering() {
return differences;
}
@Override public boolean equals(Object object) {
if (object == this) {
return true;
}
if (object instanceof MapDifference) {
MapDifference<?, ?> other = (MapDifference<?, ?>) object;
return entriesOnlyOnLeft().equals(other.entriesOnlyOnLeft())
&& entriesOnlyOnRight().equals(other.entriesOnlyOnRight())
&& entriesInCommon().equals(other.entriesInCommon())
&& entriesDiffering().equals(other.entriesDiffering());
}
return false;
}
@Override public int hashCode() {
return Objects.hashCode(entriesOnlyOnLeft(), entriesOnlyOnRight(),
entriesInCommon(), entriesDiffering());
}
@Override public String toString() {
if (areEqual()) {
return "equal";
}
StringBuilder result = new StringBuilder("not equal");
if (!onlyOnLeft.isEmpty()) {
result.append(": only on left=").append(onlyOnLeft);
}
if (!onlyOnRight.isEmpty()) {
result.append(": only on right=").append(onlyOnRight);
}
if (!differences.isEmpty()) {
result.append(": value differences=").append(differences);
}
return result.toString();
}
}
static class ValueDifferenceImpl<V>
implements MapDifference.ValueDifference<V> {
private final V left;
private final V right;
static <V> ValueDifference<V> create(@Nullable V left, @Nullable V right) {
return new ValueDifferenceImpl<V>(left, right);
}
private ValueDifferenceImpl(@Nullable V left, @Nullable V right) {
this.left = left;
this.right = right;
}
@Override
public V leftValue() {
return left;
}
@Override
public V rightValue() {
return right;
}
@Override public boolean equals(@Nullable Object object) {
if (object instanceof MapDifference.ValueDifference) {
MapDifference.ValueDifference<?> that =
(MapDifference.ValueDifference<?>) object;
return Objects.equal(this.left, that.leftValue())
&& Objects.equal(this.right, that.rightValue());
}
return false;
}
@Override public int hashCode() {
return Objects.hashCode(left, right);
}
@Override public String toString() {
return "(" + left + ", " + right + ")";
}
}
/**
* Computes the difference between two sorted maps, using the comparator of
* the left map, or {@code Ordering.natural()} if the left map uses the
* natural ordering of its elements. This difference is an immutable snapshot
* of the state of the maps at the time this method is called. It will never
* change, even if the maps change at a later time.
*
* <p>Since this method uses {@code TreeMap} instances internally, the keys of
* the right map must all compare as distinct according to the comparator
* of the left map.
*
* <p><b>Note:</b>If you only need to know whether two sorted maps have the
* same mappings, call {@code left.equals(right)} instead of this method.
*
* @param left the map to treat as the "left" map for purposes of comparison
* @param right the map to treat as the "right" map for purposes of comparison
* @return the difference between the two maps
* @since 11.0
*/
public static <K, V> SortedMapDifference<K, V> difference(
SortedMap<K, ? extends V> left, Map<? extends K, ? extends V> right) {
checkNotNull(left);
checkNotNull(right);
Comparator<? super K> comparator = orNaturalOrder(left.comparator());
SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
SortedMap<K, V> onlyOnRight = Maps.newTreeMap(comparator);
onlyOnRight.putAll(right); // will whittle it down
SortedMap<K, V> onBoth = Maps.newTreeMap(comparator);
SortedMap<K, MapDifference.ValueDifference<V>> differences =
Maps.newTreeMap(comparator);
doDifference(left, right, Equivalence.equals(), onlyOnLeft, onlyOnRight, onBoth, differences);
return new SortedMapDifferenceImpl<K, V>(onlyOnLeft, onlyOnRight, onBoth, differences);
}
static class SortedMapDifferenceImpl<K, V> extends MapDifferenceImpl<K, V>
implements SortedMapDifference<K, V> {
SortedMapDifferenceImpl(SortedMap<K, V> onlyOnLeft,
SortedMap<K, V> onlyOnRight, SortedMap<K, V> onBoth,
SortedMap<K, ValueDifference<V>> differences) {
super(onlyOnLeft, onlyOnRight, onBoth, differences);
}
@Override public SortedMap<K, ValueDifference<V>> entriesDiffering() {
return (SortedMap<K, ValueDifference<V>>) super.entriesDiffering();
}
@Override public SortedMap<K, V> entriesInCommon() {
return (SortedMap<K, V>) super.entriesInCommon();
}
@Override public SortedMap<K, V> entriesOnlyOnLeft() {
return (SortedMap<K, V>) super.entriesOnlyOnLeft();
}
@Override public SortedMap<K, V> entriesOnlyOnRight() {
return (SortedMap<K, V>) super.entriesOnlyOnRight();
}
}
/**
* Returns the specified comparator if not null; otherwise returns {@code
* Ordering.natural()}. This method is an abomination of generics; the only
* purpose of this method is to contain the ugly type-casting in one place.
*/
@SuppressWarnings("unchecked")
static <E> Comparator<? super E> orNaturalOrder(
@Nullable Comparator<? super E> comparator) {
if (comparator != null) { // can't use ? : because of javac bug 5080917
return comparator;
}
return (Comparator<E>) Ordering.natural();
}
/**
* Returns a live {@link Map} view whose keys are the contents of {@code set}
* and whose values are computed on demand using {@code function}. To get an
* immutable <i>copy</i> instead, use {@link #toMap(Iterable, Function)}.
*
* <p>Specifically, for each {@code k} in the backing set, the returned map
* has an entry mapping {@code k} to {@code function.apply(k)}. The {@code
* keySet}, {@code values}, and {@code entrySet} views of the returned map
* iterate in the same order as the backing set.
*
* <p>Modifications to the backing set are read through to the returned map.
* The returned map supports removal operations if the backing set does.
* Removal operations write through to the backing set. The returned map
* does not support put operations.
*
* <p><b>Warning</b>: If the function rejects {@code null}, caution is
* required to make sure the set does not contain {@code null}, because the
* view cannot stop {@code null} from being added to the set.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* key type {@code K}, {@code k.equals(k2)} implies that {@code k2} is also
* of type {@code K}. Using a key type for which this may not hold, such as
* {@code ArrayList}, may risk a {@code ClassCastException} when calling
* methods on the resulting map view.
*
* @since 14.0
*/
@Beta
public static <K, V> Map<K, V> asMap(
Set<K> set, Function<? super K, V> function) {
if (set instanceof SortedSet) {
return asMap((SortedSet<K>) set, function);
} else {
return new AsMapView<K, V>(set, function);
}
}
/**
* Returns a view of the sorted set as a map, mapping keys from the set
* according to the specified function.
*
* <p>Specifically, for each {@code k} in the backing set, the returned map
* has an entry mapping {@code k} to {@code function.apply(k)}. The {@code
* keySet}, {@code values}, and {@code entrySet} views of the returned map
* iterate in the same order as the backing set.
*
* <p>Modifications to the backing set are read through to the returned map.
* The returned map supports removal operations if the backing set does.
* Removal operations write through to the backing set. The returned map does
* not support put operations.
*
* <p><b>Warning</b>: If the function rejects {@code null}, caution is
* required to make sure the set does not contain {@code null}, because the
* view cannot stop {@code null} from being added to the set.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* key type {@code K}, {@code k.equals(k2)} implies that {@code k2} is also of
* type {@code K}. Using a key type for which this may not hold, such as
* {@code ArrayList}, may risk a {@code ClassCastException} when calling
* methods on the resulting map view.
*
* @since 14.0
*/
@Beta
public static <K, V> SortedMap<K, V> asMap(
SortedSet<K> set, Function<? super K, V> function) {
return Platform.mapsAsMapSortedSet(set, function);
}
static <K, V> SortedMap<K, V> asMapSortedIgnoreNavigable(SortedSet<K> set,
Function<? super K, V> function) {
return new SortedAsMapView<K, V>(set, function);
}
private static class AsMapView<K, V> extends ImprovedAbstractMap<K, V> {
private final Set<K> set;
final Function<? super K, V> function;
Set<K> backingSet() {
return set;
}
AsMapView(Set<K> set, Function<? super K, V> function) {
this.set = checkNotNull(set);
this.function = checkNotNull(function);
}
@Override
public Set<K> createKeySet() {
return removeOnlySet(backingSet());
}
@Override
Collection<V> createValues() {
return Collections2.transform(set, function);
}
@Override
public int size() {
return backingSet().size();
}
@Override
public boolean containsKey(@Nullable Object key) {
return backingSet().contains(key);
}
@Override
public V get(@Nullable Object key) {
if (Collections2.safeContains(backingSet(), key)) {
@SuppressWarnings("unchecked") // unsafe, but Javadoc warns about it
K k = (K) key;
return function.apply(k);
} else {
return null;
}
}
@Override
public V remove(@Nullable Object key) {
if (backingSet().remove(key)) {
@SuppressWarnings("unchecked") // unsafe, but Javadoc warns about it
K k = (K) key;
return function.apply(k);
} else {
return null;
}
}
@Override
public void clear() {
backingSet().clear();
}
@Override
protected Set<Entry<K, V>> createEntrySet() {
return new EntrySet<K, V>() {
@Override
Map<K, V> map() {
return AsMapView.this;
}
@Override
public Iterator<Entry<K, V>> iterator() {
return asMapEntryIterator(backingSet(), function);
}
};
}
}
static <K, V> Iterator<Entry<K, V>> asMapEntryIterator(
Set<K> set, final Function<? super K, V> function) {
return new TransformedIterator<K, Entry<K,V>>(set.iterator()) {
@Override
Entry<K, V> transform(final K key) {
return immutableEntry(key, function.apply(key));
}
};
}
private static class SortedAsMapView<K, V> extends AsMapView<K, V>
implements SortedMap<K, V> {
SortedAsMapView(SortedSet<K> set, Function<? super K, V> function) {
super(set, function);
}
@Override
SortedSet<K> backingSet() {
return (SortedSet<K>) super.backingSet();
}
@Override
public Comparator<? super K> comparator() {
return backingSet().comparator();
}
@Override
public Set<K> keySet() {
return removeOnlySortedSet(backingSet());
}
@Override
public SortedMap<K, V> subMap(K fromKey, K toKey) {
return asMap(backingSet().subSet(fromKey, toKey), function);
}
@Override
public SortedMap<K, V> headMap(K toKey) {
return asMap(backingSet().headSet(toKey), function);
}
@Override
public SortedMap<K, V> tailMap(K fromKey) {
return asMap(backingSet().tailSet(fromKey), function);
}
@Override
public K firstKey() {
return backingSet().first();
}
@Override
public K lastKey() {
return backingSet().last();
}
}
private static <E> Set<E> removeOnlySet(final Set<E> set) {
return new ForwardingSet<E>() {
@Override
protected Set<E> delegate() {
return set;
}
@Override
public boolean add(E element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> es) {
throw new UnsupportedOperationException();
}
};
}
private static <E> SortedSet<E> removeOnlySortedSet(final SortedSet<E> set) {
return new ForwardingSortedSet<E>() {
@Override
protected SortedSet<E> delegate() {
return set;
}
@Override
public boolean add(E element) {
throw new UnsupportedOperationException();
}
@Override
public boolean addAll(Collection<? extends E> es) {
throw new UnsupportedOperationException();
}
@Override
public SortedSet<E> headSet(E toElement) {
return removeOnlySortedSet(super.headSet(toElement));
}
@Override
public SortedSet<E> subSet(E fromElement, E toElement) {
return removeOnlySortedSet(super.subSet(fromElement, toElement));
}
@Override
public SortedSet<E> tailSet(E fromElement) {
return removeOnlySortedSet(super.tailSet(fromElement));
}
};
}
/**
* Returns an immutable map whose keys are the distinct elements of {@code
* keys} and whose value for each key was computed by {@code valueFunction}.
* The map's iteration order is the order of the first appearance of each key
* in {@code keys}.
*
* <p>If {@code keys} is a {@link Set}, a live view can be obtained instead of
* a copy using {@link Maps#asMap(Set, Function)}.
*
* @throws NullPointerException if any element of {@code keys} is
* {@code null}, or if {@code valueFunction} produces {@code null}
* for any key
* @since 14.0
*/
@Beta
public static <K, V> ImmutableMap<K, V> toMap(Iterable<K> keys,
Function<? super K, V> valueFunction) {
return toMap(keys.iterator(), valueFunction);
}
/**
* Returns an immutable map whose keys are the distinct elements of {@code
* keys} and whose value for each key was computed by {@code valueFunction}.
* The map's iteration order is the order of the first appearance of each key
* in {@code keys}.
*
* @throws NullPointerException if any element of {@code keys} is
* {@code null}, or if {@code valueFunction} produces {@code null}
* for any key
* @since 14.0
*/
@Beta
public static <K, V> ImmutableMap<K, V> toMap(Iterator<K> keys,
Function<? super K, V> valueFunction) {
checkNotNull(valueFunction);
// Using LHM instead of a builder so as not to fail on duplicate keys
Map<K, V> builder = newLinkedHashMap();
while (keys.hasNext()) {
K key = keys.next();
builder.put(key, valueFunction.apply(key));
}
return ImmutableMap.copyOf(builder);
}
/**
* Returns an immutable map for which the {@link Map#values} are the given
* elements in the given order, and each key is the product of invoking a
* supplied function on its corresponding value.
*
* @param values the values to use when constructing the {@code Map}
* @param keyFunction the function used to produce the key for each value
* @return a map mapping the result of evaluating the function {@code
* keyFunction} on each value in the input collection to that value
* @throws IllegalArgumentException if {@code keyFunction} produces the same
* key for more than one value in the input collection
* @throws NullPointerException if any elements of {@code values} is null, or
* if {@code keyFunction} produces {@code null} for any value
*/
public static <K, V> ImmutableMap<K, V> uniqueIndex(
Iterable<V> values, Function<? super V, K> keyFunction) {
return uniqueIndex(values.iterator(), keyFunction);
}
/**
* Returns an immutable map for which the {@link Map#values} are the given
* elements in the given order, and each key is the product of invoking a
* supplied function on its corresponding value.
*
* @param values the values to use when constructing the {@code Map}
* @param keyFunction the function used to produce the key for each value
* @return a map mapping the result of evaluating the function {@code
* keyFunction} on each value in the input collection to that value
* @throws IllegalArgumentException if {@code keyFunction} produces the same
* key for more than one value in the input collection
* @throws NullPointerException if any elements of {@code values} is null, or
* if {@code keyFunction} produces {@code null} for any value
* @since 10.0
*/
public static <K, V> ImmutableMap<K, V> uniqueIndex(
Iterator<V> values, Function<? super V, K> keyFunction) {
checkNotNull(keyFunction);
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
while (values.hasNext()) {
V value = values.next();
builder.put(keyFunction.apply(value), value);
}
return builder.build();
}
/**
* Returns an immutable map entry with the specified key and value. The {@link
* Entry#setValue} operation throws an {@link UnsupportedOperationException}.
*
* <p>The returned entry is serializable.
*
* @param key the key to be associated with the returned entry
* @param value the value to be associated with the returned entry
*/
@GwtCompatible(serializable = true)
public static <K, V> Entry<K, V> immutableEntry(
@Nullable K key, @Nullable V value) {
return new ImmutableEntry<K, V>(key, value);
}
/**
* Returns an unmodifiable view of the specified set of entries. The {@link
* Entry#setValue} operation throws an {@link UnsupportedOperationException},
* as do any operations that would modify the returned set.
*
* @param entrySet the entries for which to return an unmodifiable view
* @return an unmodifiable view of the entries
*/
static <K, V> Set<Entry<K, V>> unmodifiableEntrySet(
Set<Entry<K, V>> entrySet) {
return new UnmodifiableEntrySet<K, V>(
Collections.unmodifiableSet(entrySet));
}
/**
* Returns an unmodifiable view of the specified map entry. The {@link
* Entry#setValue} operation throws an {@link UnsupportedOperationException}.
* This also has the side-effect of redefining {@code equals} to comply with
* the Entry contract, to avoid a possible nefarious implementation of equals.
*
* @param entry the entry for which to return an unmodifiable view
* @return an unmodifiable view of the entry
*/
static <K, V> Entry<K, V> unmodifiableEntry(final Entry<? extends K, ? extends V> entry) {
checkNotNull(entry);
return new AbstractMapEntry<K, V>() {
@Override public K getKey() {
return entry.getKey();
}
@Override public V getValue() {
return entry.getValue();
}
};
}
/** @see Multimaps#unmodifiableEntries */
static class UnmodifiableEntries<K, V>
extends ForwardingCollection<Entry<K, V>> {
private final Collection<Entry<K, V>> entries;
UnmodifiableEntries(Collection<Entry<K, V>> entries) {
this.entries = entries;
}
@Override protected Collection<Entry<K, V>> delegate() {
return entries;
}
@Override public Iterator<Entry<K, V>> iterator() {
final Iterator<Entry<K, V>> delegate = super.iterator();
return new UnmodifiableIterator<Entry<K, V>>() {
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@Override public Entry<K, V> next() {
return unmodifiableEntry(delegate.next());
}
};
}
// See java.util.Collections.UnmodifiableEntrySet for details on attacks.
@Override public Object[] toArray() {
return standardToArray();
}
@Override public <T> T[] toArray(T[] array) {
return standardToArray(array);
}
}
/** @see Maps#unmodifiableEntrySet(Set) */
static class UnmodifiableEntrySet<K, V>
extends UnmodifiableEntries<K, V> implements Set<Entry<K, V>> {
UnmodifiableEntrySet(Set<Entry<K, V>> entries) {
super(entries);
}
// See java.util.Collections.UnmodifiableEntrySet for details on attacks.
@Override public boolean equals(@Nullable Object object) {
return Sets.equalsImpl(this, object);
}
@Override public int hashCode() {
return Sets.hashCodeImpl(this);
}
}
/**
* Returns a {@link Converter} that converts values using {@link BiMap#get bimap.get()},
* and whose inverse view converts values using
* {@link BiMap#inverse bimap.inverse()}{@code .get()}.
*
* <p>To use a plain {@link Map} as a {@link Function}, see
* {@link com.google.common.base.Functions#forMap(Map)} or
* {@link com.google.common.base.Functions#forMap(Map, Object)}.
*
* @since 16.0
*/
@Beta
public static <A, B> Converter<A, B> asConverter(final BiMap<A, B> bimap) {
return new BiMapConverter<A, B>(bimap);
}
private static final class BiMapConverter<A, B> extends Converter<A, B> implements Serializable {
private final BiMap<A, B> bimap;
BiMapConverter(BiMap<A, B> bimap) {
this.bimap = checkNotNull(bimap);
}
@Override
protected B doForward(A a) {
return convert(bimap, a);
}
@Override
protected A doBackward(B b) {
return convert(bimap.inverse(), b);
}
private static <X, Y> Y convert(BiMap<X, Y> bimap, X input) {
Y output = bimap.get(input);
checkArgument(output != null, "No non-null mapping present for input: %s", input);
return output;
}
@Override
public boolean equals(@Nullable Object object) {
if (object instanceof BiMapConverter) {
BiMapConverter<?, ?> that = (BiMapConverter<?, ?>) object;
return this.bimap.equals(that.bimap);
}
return false;
}
@Override
public int hashCode() {
return bimap.hashCode();
}
// There's really no good way to implement toString() without printing the entire BiMap, right?
@Override
public String toString() {
return "Maps.asConverter(" + bimap + ")";
}
private static final long serialVersionUID = 0L;
}
/**
* Returns a synchronized (thread-safe) bimap backed by the specified bimap.
* In order to guarantee serial access, it is critical that <b>all</b> access
* to the backing bimap is accomplished through the returned bimap.
*
* <p>It is imperative that the user manually synchronize on the returned map
* when accessing any of its collection views: <pre> {@code
*
* BiMap<Long, String> map = Maps.synchronizedBiMap(
* HashBiMap.<Long, String>create());
* ...
* Set<Long> set = map.keySet(); // Needn't be in synchronized block
* ...
* synchronized (map) { // Synchronizing on map, not set!
* Iterator<Long> it = set.iterator(); // Must be in synchronized block
* while (it.hasNext()) {
* foo(it.next());
* }
* }}</pre>
*
* <p>Failure to follow this advice may result in non-deterministic behavior.
*
* <p>The returned bimap will be serializable if the specified bimap is
* serializable.
*
* @param bimap the bimap to be wrapped in a synchronized view
* @return a sychronized view of the specified bimap
*/
public static <K, V> BiMap<K, V> synchronizedBiMap(BiMap<K, V> bimap) {
return Synchronized.biMap(bimap, null);
}
/**
* Returns an unmodifiable view of the specified bimap. This method allows
* modules to provide users with "read-only" access to internal bimaps. Query
* operations on the returned bimap "read through" to the specified bimap, and
* attempts to modify the returned map, whether direct or via its collection
* views, result in an {@code UnsupportedOperationException}.
*
* <p>The returned bimap will be serializable if the specified bimap is
* serializable.
*
* @param bimap the bimap for which an unmodifiable view is to be returned
* @return an unmodifiable view of the specified bimap
*/
public static <K, V> BiMap<K, V> unmodifiableBiMap(
BiMap<? extends K, ? extends V> bimap) {
return new UnmodifiableBiMap<K, V>(bimap, null);
}
/** @see Maps#unmodifiableBiMap(BiMap) */
private static class UnmodifiableBiMap<K, V>
extends ForwardingMap<K, V> implements BiMap<K, V>, Serializable {
final Map<K, V> unmodifiableMap;
final BiMap<? extends K, ? extends V> delegate;
BiMap<V, K> inverse;
transient Set<V> values;
UnmodifiableBiMap(BiMap<? extends K, ? extends V> delegate,
@Nullable BiMap<V, K> inverse) {
unmodifiableMap = Collections.unmodifiableMap(delegate);
this.delegate = delegate;
this.inverse = inverse;
}
@Override protected Map<K, V> delegate() {
return unmodifiableMap;
}
@Override
public V forcePut(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public BiMap<V, K> inverse() {
BiMap<V, K> result = inverse;
return (result == null)
? inverse = new UnmodifiableBiMap<V, K>(delegate.inverse(), this)
: result;
}
@Override public Set<V> values() {
Set<V> result = values;
return (result == null)
? values = Collections.unmodifiableSet(delegate.values())
: result;
}
private static final long serialVersionUID = 0;
}
/**
* Returns a view of a map where each value is transformed by a function. All
* other properties of the map, such as iteration order, are left intact. For
* example, the code: <pre> {@code
*
* Map<String, Integer> map = ImmutableMap.of("a", 4, "b", 9);
* Function<Integer, Double> sqrt =
* new Function<Integer, Double>() {
* public Double apply(Integer in) {
* return Math.sqrt((int) in);
* }
* };
* Map<String, Double> transformed = Maps.transformValues(map, sqrt);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {a=2.0, b=3.0}}.
*
* <p>Changes in the underlying map are reflected in this view. Conversely,
* this view supports removal operations, and these are reflected in the
* underlying map.
*
* <p>It's acceptable for the underlying map to contain null keys, and even
* null values provided that the function is capable of accepting null input.
* The transformed map might contain null values, if the function sometimes
* gives a null result.
*
* <p>The returned map is not thread-safe or serializable, even if the
* underlying map is.
*
* <p>The function is applied lazily, invoked when needed. This is necessary
* for the returned map to be a view, but it means that the function will be
* applied many times for bulk operations like {@link Map#containsValue} and
* {@code Map.toString()}. For this to perform well, {@code function} should
* be fast. To avoid lazy evaluation when the returned map doesn't need to be
* a view, copy the returned map into a new map of your choosing.
*/
public static <K, V1, V2> Map<K, V2> transformValues(
Map<K, V1> fromMap, Function<? super V1, V2> function) {
return transformEntries(fromMap, asEntryTransformer(function));
}
/**
* Returns a view of a sorted map where each value is transformed by a
* function. All other properties of the map, such as iteration order, are
* left intact. For example, the code: <pre> {@code
*
* SortedMap<String, Integer> map = ImmutableSortedMap.of("a", 4, "b", 9);
* Function<Integer, Double> sqrt =
* new Function<Integer, Double>() {
* public Double apply(Integer in) {
* return Math.sqrt((int) in);
* }
* };
* SortedMap<String, Double> transformed =
* Maps.transformValues(map, sqrt);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {a=2.0, b=3.0}}.
*
* <p>Changes in the underlying map are reflected in this view. Conversely,
* this view supports removal operations, and these are reflected in the
* underlying map.
*
* <p>It's acceptable for the underlying map to contain null keys, and even
* null values provided that the function is capable of accepting null input.
* The transformed map might contain null values, if the function sometimes
* gives a null result.
*
* <p>The returned map is not thread-safe or serializable, even if the
* underlying map is.
*
* <p>The function is applied lazily, invoked when needed. This is necessary
* for the returned map to be a view, but it means that the function will be
* applied many times for bulk operations like {@link Map#containsValue} and
* {@code Map.toString()}. For this to perform well, {@code function} should
* be fast. To avoid lazy evaluation when the returned map doesn't need to be
* a view, copy the returned map into a new map of your choosing.
*
* @since 11.0
*/
public static <K, V1, V2> SortedMap<K, V2> transformValues(
SortedMap<K, V1> fromMap, Function<? super V1, V2> function) {
return transformEntries(fromMap, asEntryTransformer(function));
}
/**
* Returns a view of a map whose values are derived from the original map's
* entries. In contrast to {@link #transformValues}, this method's
* entry-transformation logic may depend on the key as well as the value.
*
* <p>All other properties of the transformed map, such as iteration order,
* are left intact. For example, the code: <pre> {@code
*
* Map<String, Boolean> options =
* ImmutableMap.of("verbose", true, "sort", false);
* EntryTransformer<String, Boolean, String> flagPrefixer =
* new EntryTransformer<String, Boolean, String>() {
* public String transformEntry(String key, Boolean value) {
* return value ? key : "no" + key;
* }
* };
* Map<String, String> transformed =
* Maps.transformEntries(options, flagPrefixer);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {verbose=verbose, sort=nosort}}.
*
* <p>Changes in the underlying map are reflected in this view. Conversely,
* this view supports removal operations, and these are reflected in the
* underlying map.
*
* <p>It's acceptable for the underlying map to contain null keys and null
* values provided that the transformer is capable of accepting null inputs.
* The transformed map might contain null values if the transformer sometimes
* gives a null result.
*
* <p>The returned map is not thread-safe or serializable, even if the
* underlying map is.
*
* <p>The transformer is applied lazily, invoked when needed. This is
* necessary for the returned map to be a view, but it means that the
* transformer will be applied many times for bulk operations like {@link
* Map#containsValue} and {@link Object#toString}. For this to perform well,
* {@code transformer} should be fast. To avoid lazy evaluation when the
* returned map doesn't need to be a view, copy the returned map into a new
* map of your choosing.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* {@code EntryTransformer} key type {@code K}, {@code k.equals(k2)} implies
* that {@code k2} is also of type {@code K}. Using an {@code
* EntryTransformer} key type for which this may not hold, such as {@code
* ArrayList}, may risk a {@code ClassCastException} when calling methods on
* the transformed map.
*
* @since 7.0
*/
public static <K, V1, V2> Map<K, V2> transformEntries(
Map<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
if (fromMap instanceof SortedMap) {
return transformEntries((SortedMap<K, V1>) fromMap, transformer);
}
return new TransformedEntriesMap<K, V1, V2>(fromMap, transformer);
}
/**
* Returns a view of a sorted map whose values are derived from the original
* sorted map's entries. In contrast to {@link #transformValues}, this
* method's entry-transformation logic may depend on the key as well as the
* value.
*
* <p>All other properties of the transformed map, such as iteration order,
* are left intact. For example, the code: <pre> {@code
*
* Map<String, Boolean> options =
* ImmutableSortedMap.of("verbose", true, "sort", false);
* EntryTransformer<String, Boolean, String> flagPrefixer =
* new EntryTransformer<String, Boolean, String>() {
* public String transformEntry(String key, Boolean value) {
* return value ? key : "yes" + key;
* }
* };
* SortedMap<String, String> transformed =
* Maps.transformEntries(options, flagPrefixer);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {sort=yessort, verbose=verbose}}.
*
* <p>Changes in the underlying map are reflected in this view. Conversely,
* this view supports removal operations, and these are reflected in the
* underlying map.
*
* <p>It's acceptable for the underlying map to contain null keys and null
* values provided that the transformer is capable of accepting null inputs.
* The transformed map might contain null values if the transformer sometimes
* gives a null result.
*
* <p>The returned map is not thread-safe or serializable, even if the
* underlying map is.
*
* <p>The transformer is applied lazily, invoked when needed. This is
* necessary for the returned map to be a view, but it means that the
* transformer will be applied many times for bulk operations like {@link
* Map#containsValue} and {@link Object#toString}. For this to perform well,
* {@code transformer} should be fast. To avoid lazy evaluation when the
* returned map doesn't need to be a view, copy the returned map into a new
* map of your choosing.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* {@code EntryTransformer} key type {@code K}, {@code k.equals(k2)} implies
* that {@code k2} is also of type {@code K}. Using an {@code
* EntryTransformer} key type for which this may not hold, such as {@code
* ArrayList}, may risk a {@code ClassCastException} when calling methods on
* the transformed map.
*
* @since 11.0
*/
public static <K, V1, V2> SortedMap<K, V2> transformEntries(
SortedMap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
return Platform.mapsTransformEntriesSortedMap(fromMap, transformer);
}
static <K, V1, V2> SortedMap<K, V2> transformEntriesIgnoreNavigable(
SortedMap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
return new TransformedEntriesSortedMap<K, V1, V2>(fromMap, transformer);
}
/**
* A transformation of the value of a key-value pair, using both key and value
* as inputs. To apply the transformation to a map, use
* {@link Maps#transformEntries(Map, EntryTransformer)}.
*
* @param <K> the key type of the input and output entries
* @param <V1> the value type of the input entry
* @param <V2> the value type of the output entry
* @since 7.0
*/
public interface EntryTransformer<K, V1, V2> {
/**
* Determines an output value based on a key-value pair. This method is
* <i>generally expected</i>, but not absolutely required, to have the
* following properties:
*
* <ul>
* <li>Its execution does not cause any observable side effects.
* <li>The computation is <i>consistent with equals</i>; that is,
* {@link Objects#equal Objects.equal}{@code (k1, k2) &&}
* {@link Objects#equal}{@code (v1, v2)} implies that {@code
* Objects.equal(transformer.transform(k1, v1),
* transformer.transform(k2, v2))}.
* </ul>
*
* @throws NullPointerException if the key or value is null and this
* transformer does not accept null arguments
*/
V2 transformEntry(@Nullable K key, @Nullable V1 value);
}
/**
* Views a function as an entry transformer that ignores the entry key.
*/
static <K, V1, V2> EntryTransformer<K, V1, V2>
asEntryTransformer(final Function<? super V1, V2> function) {
checkNotNull(function);
return new EntryTransformer<K, V1, V2>() {
@Override
public V2 transformEntry(K key, V1 value) {
return function.apply(value);
}
};
}
static <K, V1, V2> Function<V1, V2> asValueToValueFunction(
final EntryTransformer<? super K, V1, V2> transformer, final K key) {
checkNotNull(transformer);
return new Function<V1, V2>() {
@Override
public V2 apply(@Nullable V1 v1) {
return transformer.transformEntry(key, v1);
}
};
}
/**
* Views an entry transformer as a function from {@code Entry} to values.
*/
static <K, V1, V2> Function<Entry<K, V1>, V2> asEntryToValueFunction(
final EntryTransformer<? super K, ? super V1, V2> transformer) {
checkNotNull(transformer);
return new Function<Entry<K, V1>, V2>() {
@Override
public V2 apply(Entry<K, V1> entry) {
return transformer.transformEntry(entry.getKey(), entry.getValue());
}
};
}
/**
* Returns a view of an entry transformed by the specified transformer.
*/
static <V2, K, V1> Entry<K, V2> transformEntry(
final EntryTransformer<? super K, ? super V1, V2> transformer, final Entry<K, V1> entry) {
checkNotNull(transformer);
checkNotNull(entry);
return new AbstractMapEntry<K, V2>() {
@Override
public K getKey() {
return entry.getKey();
}
@Override
public V2 getValue() {
return transformer.transformEntry(entry.getKey(), entry.getValue());
}
};
}
/**
* Views an entry transformer as a function from entries to entries.
*/
static <K, V1, V2> Function<Entry<K, V1>, Entry<K, V2>> asEntryToEntryFunction(
final EntryTransformer<? super K, ? super V1, V2> transformer) {
checkNotNull(transformer);
return new Function<Entry<K, V1>, Entry<K, V2>>() {
@Override
public Entry<K, V2> apply(final Entry<K, V1> entry) {
return transformEntry(transformer, entry);
}
};
}
static class TransformedEntriesMap<K, V1, V2>
extends ImprovedAbstractMap<K, V2> {
final Map<K, V1> fromMap;
final EntryTransformer<? super K, ? super V1, V2> transformer;
TransformedEntriesMap(
Map<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
this.fromMap = checkNotNull(fromMap);
this.transformer = checkNotNull(transformer);
}
@Override public int size() {
return fromMap.size();
}
@Override public boolean containsKey(Object key) {
return fromMap.containsKey(key);
}
// safe as long as the user followed the <b>Warning</b> in the javadoc
@SuppressWarnings("unchecked")
@Override public V2 get(Object key) {
V1 value = fromMap.get(key);
return (value != null || fromMap.containsKey(key))
? transformer.transformEntry((K) key, value)
: null;
}
// safe as long as the user followed the <b>Warning</b> in the javadoc
@SuppressWarnings("unchecked")
@Override public V2 remove(Object key) {
return fromMap.containsKey(key)
? transformer.transformEntry((K) key, fromMap.remove(key))
: null;
}
@Override public void clear() {
fromMap.clear();
}
@Override public Set<K> keySet() {
return fromMap.keySet();
}
@Override
protected Set<Entry<K, V2>> createEntrySet() {
return new EntrySet<K, V2>() {
@Override Map<K, V2> map() {
return TransformedEntriesMap.this;
}
@Override public Iterator<Entry<K, V2>> iterator() {
return Iterators.transform(fromMap.entrySet().iterator(),
Maps.<K, V1, V2>asEntryToEntryFunction(transformer));
}
};
}
}
static class TransformedEntriesSortedMap<K, V1, V2>
extends TransformedEntriesMap<K, V1, V2> implements SortedMap<K, V2> {
protected SortedMap<K, V1> fromMap() {
return (SortedMap<K, V1>) fromMap;
}
TransformedEntriesSortedMap(SortedMap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
super(fromMap, transformer);
}
@Override public Comparator<? super K> comparator() {
return fromMap().comparator();
}
@Override public K firstKey() {
return fromMap().firstKey();
}
@Override public SortedMap<K, V2> headMap(K toKey) {
return transformEntries(fromMap().headMap(toKey), transformer);
}
@Override public K lastKey() {
return fromMap().lastKey();
}
@Override public SortedMap<K, V2> subMap(K fromKey, K toKey) {
return transformEntries(
fromMap().subMap(fromKey, toKey), transformer);
}
@Override public SortedMap<K, V2> tailMap(K fromKey) {
return transformEntries(fromMap().tailMap(fromKey), transformer);
}
}
static <K> Predicate<Entry<K, ?>> keyPredicateOnEntries(Predicate<? super K> keyPredicate) {
return compose(keyPredicate, Maps.<K>keyFunction());
}
static <V> Predicate<Entry<?, V>> valuePredicateOnEntries(Predicate<? super V> valuePredicate) {
return compose(valuePredicate, Maps.<V>valueFunction());
}
/**
* Returns a map containing the mappings in {@code unfiltered} whose keys
* satisfy a predicate. The returned map is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a key that
* doesn't satisfy the predicate, the map's {@code put()} and {@code putAll()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*/
public static <K, V> Map<K, V> filterKeys(
Map<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
if (unfiltered instanceof SortedMap) {
return filterKeys((SortedMap<K, V>) unfiltered, keyPredicate);
} else if (unfiltered instanceof BiMap) {
return filterKeys((BiMap<K, V>) unfiltered, keyPredicate);
}
checkNotNull(keyPredicate);
Predicate<Entry<K, ?>> entryPredicate = keyPredicateOnEntries(keyPredicate);
return (unfiltered instanceof AbstractFilteredMap)
? filterFiltered((AbstractFilteredMap<K, V>) unfiltered, entryPredicate)
: new FilteredKeyMap<K, V>(
checkNotNull(unfiltered), keyPredicate, entryPredicate);
}
/**
* Returns a sorted map containing the mappings in {@code unfiltered} whose
* keys satisfy a predicate. The returned map is a live view of {@code
* unfiltered}; changes to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a key that
* doesn't satisfy the predicate, the map's {@code put()} and {@code putAll()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*
* @since 11.0
*/
public static <K, V> SortedMap<K, V> filterKeys(
SortedMap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
// TODO(user): Return a subclass of Maps.FilteredKeyMap for slightly better
// performance.
return filterEntries(unfiltered, Maps.<K>keyPredicateOnEntries(keyPredicate));
}
/**
* Returns a bimap containing the mappings in {@code unfiltered} whose keys satisfy a predicate.
* The returned bimap is a live view of {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting bimap's {@code keySet()}, {@code entrySet()}, and {@code values()} views have
* iterators that don't support {@code remove()}, but all other methods are supported by the
* bimap and its views. When given a key that doesn't satisfy the predicate, the bimap's {@code
* put()}, {@code forcePut()} and {@code putAll()} methods throw an {@link
* IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on the filtered
* bimap or its views, only mappings that satisfy the filter will be removed from the underlying
* bimap.
*
* <p>The returned bimap isn't threadsafe or serializable, even if {@code unfiltered} is.
*
* <p>Many of the filtered bimap's methods, such as {@code size()}, iterate across every key in
* the underlying bimap and determine which satisfy the filter. When a live view is <i>not</i>
* needed, it may be faster to copy the filtered bimap and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with equals </i>, as
* documented at {@link Predicate#apply}.
*
* @since 14.0
*/
public static <K, V> BiMap<K, V> filterKeys(
BiMap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
checkNotNull(keyPredicate);
return filterEntries(unfiltered, Maps.<K>keyPredicateOnEntries(keyPredicate));
}
/**
* Returns a map containing the mappings in {@code unfiltered} whose values
* satisfy a predicate. The returned map is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a value
* that doesn't satisfy the predicate, the map's {@code put()}, {@code
* putAll()}, and {@link Entry#setValue} methods throw an {@link
* IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings whose values satisfy the
* filter will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code valuePredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*/
public static <K, V> Map<K, V> filterValues(
Map<K, V> unfiltered, final Predicate<? super V> valuePredicate) {
if (unfiltered instanceof SortedMap) {
return filterValues((SortedMap<K, V>) unfiltered, valuePredicate);
} else if (unfiltered instanceof BiMap) {
return filterValues((BiMap<K, V>) unfiltered, valuePredicate);
}
return filterEntries(unfiltered, Maps.<V>valuePredicateOnEntries(valuePredicate));
}
/**
* Returns a sorted map containing the mappings in {@code unfiltered} whose
* values satisfy a predicate. The returned map is a live view of {@code
* unfiltered}; changes to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a value
* that doesn't satisfy the predicate, the map's {@code put()}, {@code
* putAll()}, and {@link Entry#setValue} methods throw an {@link
* IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings whose values satisfy the
* filter will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code valuePredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*
* @since 11.0
*/
public static <K, V> SortedMap<K, V> filterValues(
SortedMap<K, V> unfiltered, final Predicate<? super V> valuePredicate) {
return filterEntries(unfiltered, Maps.<V>valuePredicateOnEntries(valuePredicate));
}
/**
* Returns a bimap containing the mappings in {@code unfiltered} whose values satisfy a
* predicate. The returned bimap is a live view of {@code unfiltered}; changes to one affect the
* other.
*
* <p>The resulting bimap's {@code keySet()}, {@code entrySet()}, and {@code values()} views have
* iterators that don't support {@code remove()}, but all other methods are supported by the
* bimap and its views. When given a value that doesn't satisfy the predicate, the bimap's
* {@code put()}, {@code forcePut()} and {@code putAll()} methods throw an {@link
* IllegalArgumentException}. Similarly, the map's entries have a {@link Entry#setValue} method
* that throws an {@link IllegalArgumentException} when the provided value doesn't satisfy the
* predicate.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on the filtered
* bimap or its views, only mappings that satisfy the filter will be removed from the underlying
* bimap.
*
* <p>The returned bimap isn't threadsafe or serializable, even if {@code unfiltered} is.
*
* <p>Many of the filtered bimap's methods, such as {@code size()}, iterate across every value in
* the underlying bimap and determine which satisfy the filter. When a live view is <i>not</i>
* needed, it may be faster to copy the filtered bimap and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with equals </i>, as
* documented at {@link Predicate#apply}.
*
* @since 14.0
*/
public static <K, V> BiMap<K, V> filterValues(
BiMap<K, V> unfiltered, final Predicate<? super V> valuePredicate) {
return filterEntries(unfiltered, Maps.<V>valuePredicateOnEntries(valuePredicate));
}
/**
* Returns a map containing the mappings in {@code unfiltered} that satisfy a
* predicate. The returned map is a live view of {@code unfiltered}; changes
* to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a
* key/value pair that doesn't satisfy the predicate, the map's {@code put()}
* and {@code putAll()} methods throw an {@link IllegalArgumentException}.
* Similarly, the map's entries have a {@link Entry#setValue} method that
* throws an {@link IllegalArgumentException} when the existing key and the
* provided value don't satisfy the predicate.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings that satisfy the filter
* will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}.
*/
public static <K, V> Map<K, V> filterEntries(
Map<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate) {
if (unfiltered instanceof SortedMap) {
return filterEntries((SortedMap<K, V>) unfiltered, entryPredicate);
} else if (unfiltered instanceof BiMap) {
return filterEntries((BiMap<K, V>) unfiltered, entryPredicate);
}
checkNotNull(entryPredicate);
return (unfiltered instanceof AbstractFilteredMap)
? filterFiltered((AbstractFilteredMap<K, V>) unfiltered, entryPredicate)
: new FilteredEntryMap<K, V>(checkNotNull(unfiltered), entryPredicate);
}
/**
* Returns a sorted map containing the mappings in {@code unfiltered} that
* satisfy a predicate. The returned map is a live view of {@code unfiltered};
* changes to one affect the other.
*
* <p>The resulting map's {@code keySet()}, {@code entrySet()}, and {@code
* values()} views have iterators that don't support {@code remove()}, but all
* other methods are supported by the map and its views. When given a
* key/value pair that doesn't satisfy the predicate, the map's {@code put()}
* and {@code putAll()} methods throw an {@link IllegalArgumentException}.
* Similarly, the map's entries have a {@link Entry#setValue} method that
* throws an {@link IllegalArgumentException} when the existing key and the
* provided value don't satisfy the predicate.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called
* on the filtered map or its views, only mappings that satisfy the filter
* will be removed from the underlying map.
*
* <p>The returned map isn't threadsafe or serializable, even if {@code
* unfiltered} is.
*
* <p>Many of the filtered map's methods, such as {@code size()},
* iterate across every key/value mapping in the underlying map and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered map and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}.
*
* @since 11.0
*/
public static <K, V> SortedMap<K, V> filterEntries(
SortedMap<K, V> unfiltered,
Predicate<? super Entry<K, V>> entryPredicate) {
return Platform.mapsFilterSortedMap(unfiltered, entryPredicate);
}
static <K, V> SortedMap<K, V> filterSortedIgnoreNavigable(
SortedMap<K, V> unfiltered,
Predicate<? super Entry<K, V>> entryPredicate) {
checkNotNull(entryPredicate);
return (unfiltered instanceof FilteredEntrySortedMap)
? filterFiltered((FilteredEntrySortedMap<K, V>) unfiltered, entryPredicate)
: new FilteredEntrySortedMap<K, V>(checkNotNull(unfiltered), entryPredicate);
}
/**
* Returns a bimap containing the mappings in {@code unfiltered} that satisfy a predicate. The
* returned bimap is a live view of {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting bimap's {@code keySet()}, {@code entrySet()}, and {@code values()} views have
* iterators that don't support {@code remove()}, but all other methods are supported by the bimap
* and its views. When given a key/value pair that doesn't satisfy the predicate, the bimap's
* {@code put()}, {@code forcePut()} and {@code putAll()} methods throw an
* {@link IllegalArgumentException}. Similarly, the map's entries have an {@link Entry#setValue}
* method that throws an {@link IllegalArgumentException} when the existing key and the provided
* value don't satisfy the predicate.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on the filtered
* bimap or its views, only mappings that satisfy the filter will be removed from the underlying
* bimap.
*
* <p>The returned bimap isn't threadsafe or serializable, even if {@code unfiltered} is.
*
* <p>Many of the filtered bimap's methods, such as {@code size()}, iterate across every
* key/value mapping in the underlying bimap and determine which satisfy the filter. When a live
* view is <i>not</i> needed, it may be faster to copy the filtered bimap and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with equals </i>, as
* documented at {@link Predicate#apply}.
*
* @since 14.0
*/
public static <K, V> BiMap<K, V> filterEntries(
BiMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate) {
checkNotNull(unfiltered);
checkNotNull(entryPredicate);
return (unfiltered instanceof FilteredEntryBiMap)
? filterFiltered((FilteredEntryBiMap<K, V>) unfiltered, entryPredicate)
: new FilteredEntryBiMap<K, V>(unfiltered, entryPredicate);
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered map.
*/
private static <K, V> Map<K, V> filterFiltered(AbstractFilteredMap<K, V> map,
Predicate<? super Entry<K, V>> entryPredicate) {
return new FilteredEntryMap<K, V>(map.unfiltered,
Predicates.<Entry<K, V>>and(map.predicate, entryPredicate));
}
private abstract static class AbstractFilteredMap<K, V>
extends ImprovedAbstractMap<K, V> {
final Map<K, V> unfiltered;
final Predicate<? super Entry<K, V>> predicate;
AbstractFilteredMap(
Map<K, V> unfiltered, Predicate<? super Entry<K, V>> predicate) {
this.unfiltered = unfiltered;
this.predicate = predicate;
}
boolean apply(@Nullable Object key, @Nullable V value) {
// This method is called only when the key is in the map, implying that
// key is a K.
@SuppressWarnings("unchecked")
K k = (K) key;
return predicate.apply(Maps.immutableEntry(k, value));
}
@Override public V put(K key, V value) {
checkArgument(apply(key, value));
return unfiltered.put(key, value);
}
@Override public void putAll(Map<? extends K, ? extends V> map) {
for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
checkArgument(apply(entry.getKey(), entry.getValue()));
}
unfiltered.putAll(map);
}
@Override public boolean containsKey(Object key) {
return unfiltered.containsKey(key) && apply(key, unfiltered.get(key));
}
@Override public V get(Object key) {
V value = unfiltered.get(key);
return ((value != null) && apply(key, value)) ? value : null;
}
@Override public boolean isEmpty() {
return entrySet().isEmpty();
}
@Override public V remove(Object key) {
return containsKey(key) ? unfiltered.remove(key) : null;
}
@Override
Collection<V> createValues() {
return new FilteredMapValues<K, V>(this, unfiltered, predicate);
}
}
private static final class FilteredMapValues<K, V> extends Maps.Values<K, V> {
Map<K, V> unfiltered;
Predicate<? super Entry<K, V>> predicate;
FilteredMapValues(Map<K, V> filteredMap, Map<K, V> unfiltered,
Predicate<? super Entry<K, V>> predicate) {
super(filteredMap);
this.unfiltered = unfiltered;
this.predicate = predicate;
}
@Override public boolean remove(Object o) {
return Iterables.removeFirstMatching(unfiltered.entrySet(),
Predicates.<Entry<K, V>>and(predicate, Maps.<V>valuePredicateOnEntries(equalTo(o))))
!= null;
}
private boolean removeIf(Predicate<? super V> valuePredicate) {
return Iterables.removeIf(unfiltered.entrySet(), Predicates.<Entry<K, V>>and(
predicate, Maps.<V>valuePredicateOnEntries(valuePredicate)));
}
@Override public boolean removeAll(Collection<?> collection) {
return removeIf(in(collection));
}
@Override public boolean retainAll(Collection<?> collection) {
return removeIf(not(in(collection)));
}
@Override public Object[] toArray() {
// creating an ArrayList so filtering happens once
return Lists.newArrayList(iterator()).toArray();
}
@Override public <T> T[] toArray(T[] array) {
return Lists.newArrayList(iterator()).toArray(array);
}
}
private static class FilteredKeyMap<K, V> extends AbstractFilteredMap<K, V> {
Predicate<? super K> keyPredicate;
FilteredKeyMap(Map<K, V> unfiltered, Predicate<? super K> keyPredicate,
Predicate<? super Entry<K, V>> entryPredicate) {
super(unfiltered, entryPredicate);
this.keyPredicate = keyPredicate;
}
@Override
protected Set<Entry<K, V>> createEntrySet() {
return Sets.filter(unfiltered.entrySet(), predicate);
}
@Override
Set<K> createKeySet() {
return Sets.filter(unfiltered.keySet(), keyPredicate);
}
// The cast is called only when the key is in the unfiltered map, implying
// that key is a K.
@Override
@SuppressWarnings("unchecked")
public boolean containsKey(Object key) {
return unfiltered.containsKey(key) && keyPredicate.apply((K) key);
}
}
static class FilteredEntryMap<K, V> extends AbstractFilteredMap<K, V> {
/**
* Entries in this set satisfy the predicate, but they don't validate the
* input to {@code Entry.setValue()}.
*/
final Set<Entry<K, V>> filteredEntrySet;
FilteredEntryMap(
Map<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate) {
super(unfiltered, entryPredicate);
filteredEntrySet = Sets.filter(unfiltered.entrySet(), predicate);
}
@Override
protected Set<Entry<K, V>> createEntrySet() {
return new EntrySet();
}
private class EntrySet extends ForwardingSet<Entry<K, V>> {
@Override protected Set<Entry<K, V>> delegate() {
return filteredEntrySet;
}
@Override public Iterator<Entry<K, V>> iterator() {
return new TransformedIterator<Entry<K, V>, Entry<K, V>>(filteredEntrySet.iterator()) {
@Override
Entry<K, V> transform(final Entry<K, V> entry) {
return new ForwardingMapEntry<K, V>() {
@Override
protected Entry<K, V> delegate() {
return entry;
}
@Override
public V setValue(V newValue) {
checkArgument(apply(getKey(), newValue));
return super.setValue(newValue);
}
};
}
};
}
}
@Override
Set<K> createKeySet() {
return new KeySet();
}
class KeySet extends Maps.KeySet<K, V> {
KeySet() {
super(FilteredEntryMap.this);
}
@Override public boolean remove(Object o) {
if (containsKey(o)) {
unfiltered.remove(o);
return true;
}
return false;
}
private boolean removeIf(Predicate<? super K> keyPredicate) {
return Iterables.removeIf(unfiltered.entrySet(), Predicates.<Entry<K, V>>and(
predicate, Maps.<K>keyPredicateOnEntries(keyPredicate)));
}
@Override
public boolean removeAll(Collection<?> c) {
return removeIf(in(c));
}
@Override
public boolean retainAll(Collection<?> c) {
return removeIf(not(in(c)));
}
@Override public Object[] toArray() {
// creating an ArrayList so filtering happens once
return Lists.newArrayList(iterator()).toArray();
}
@Override public <T> T[] toArray(T[] array) {
return Lists.newArrayList(iterator()).toArray(array);
}
}
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered sorted map.
*/
private static <K, V> SortedMap<K, V> filterFiltered(
FilteredEntrySortedMap<K, V> map,
Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate
= Predicates.and(map.predicate, entryPredicate);
return new FilteredEntrySortedMap<K, V>(map.sortedMap(), predicate);
}
private static class FilteredEntrySortedMap<K, V>
extends FilteredEntryMap<K, V> implements SortedMap<K, V> {
FilteredEntrySortedMap(SortedMap<K, V> unfiltered,
Predicate<? super Entry<K, V>> entryPredicate) {
super(unfiltered, entryPredicate);
}
SortedMap<K, V> sortedMap() {
return (SortedMap<K, V>) unfiltered;
}
@Override public SortedSet<K> keySet() {
return (SortedSet<K>) super.keySet();
}
@Override
SortedSet<K> createKeySet() {
return new SortedKeySet();
}
class SortedKeySet extends KeySet implements SortedSet<K> {
@Override
public Comparator<? super K> comparator() {
return sortedMap().comparator();
}
@Override
public SortedSet<K> subSet(K fromElement, K toElement) {
return (SortedSet<K>) subMap(fromElement, toElement).keySet();
}
@Override
public SortedSet<K> headSet(K toElement) {
return (SortedSet<K>) headMap(toElement).keySet();
}
@Override
public SortedSet<K> tailSet(K fromElement) {
return (SortedSet<K>) tailMap(fromElement).keySet();
}
@Override
public K first() {
return firstKey();
}
@Override
public K last() {
return lastKey();
}
}
@Override public Comparator<? super K> comparator() {
return sortedMap().comparator();
}
@Override public K firstKey() {
// correctly throws NoSuchElementException when filtered map is empty.
return keySet().iterator().next();
}
@Override public K lastKey() {
SortedMap<K, V> headMap = sortedMap();
while (true) {
// correctly throws NoSuchElementException when filtered map is empty.
K key = headMap.lastKey();
if (apply(key, unfiltered.get(key))) {
return key;
}
headMap = sortedMap().headMap(key);
}
}
@Override public SortedMap<K, V> headMap(K toKey) {
return new FilteredEntrySortedMap<K, V>(sortedMap().headMap(toKey), predicate);
}
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) {
return new FilteredEntrySortedMap<K, V>(
sortedMap().subMap(fromKey, toKey), predicate);
}
@Override public SortedMap<K, V> tailMap(K fromKey) {
return new FilteredEntrySortedMap<K, V>(
sortedMap().tailMap(fromKey), predicate);
}
}
/**
* Support {@code clear()}, {@code removeAll()}, and {@code retainAll()} when
* filtering a filtered map.
*/
private static <K, V> BiMap<K, V> filterFiltered(
FilteredEntryBiMap<K, V> map, Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate = Predicates.and(map.predicate, entryPredicate);
return new FilteredEntryBiMap<K, V>(map.unfiltered(), predicate);
}
static final class FilteredEntryBiMap<K, V> extends FilteredEntryMap<K, V>
implements BiMap<K, V> {
private final BiMap<V, K> inverse;
private static <K, V> Predicate<Entry<V, K>> inversePredicate(
final Predicate<? super Entry<K, V>> forwardPredicate) {
return new Predicate<Entry<V, K>>() {
@Override
public boolean apply(Entry<V, K> input) {
return forwardPredicate.apply(
Maps.immutableEntry(input.getValue(), input.getKey()));
}
};
}
FilteredEntryBiMap(BiMap<K, V> delegate,
Predicate<? super Entry<K, V>> predicate) {
super(delegate, predicate);
this.inverse = new FilteredEntryBiMap<V, K>(
delegate.inverse(), inversePredicate(predicate), this);
}
private FilteredEntryBiMap(
BiMap<K, V> delegate, Predicate<? super Entry<K, V>> predicate,
BiMap<V, K> inverse) {
super(delegate, predicate);
this.inverse = inverse;
}
BiMap<K, V> unfiltered() {
return (BiMap<K, V>) unfiltered;
}
@Override
public V forcePut(@Nullable K key, @Nullable V value) {
checkArgument(apply(key, value));
return unfiltered().forcePut(key, value);
}
@Override
public BiMap<V, K> inverse() {
return inverse;
}
@Override
public Set<V> values() {
return inverse.keySet();
}
}
@Nullable private static <K, V> Entry<K, V> unmodifiableOrNull(@Nullable Entry<K, V> entry) {
return (entry == null) ? null : Maps.unmodifiableEntry(entry);
}
/**
* {@code AbstractMap} extension that implements {@link #isEmpty()} as {@code
* entrySet().isEmpty()} instead of {@code size() == 0} to speed up
* implementations where {@code size()} is O(n), and it delegates the {@code
* isEmpty()} methods of its key set and value collection to this
* implementation.
*/
@GwtCompatible
abstract static class ImprovedAbstractMap<K, V> extends AbstractMap<K, V> {
/**
* Creates the entry set to be returned by {@link #entrySet()}. This method
* is invoked at most once on a given map, at the time when {@code entrySet}
* is first called.
*/
abstract Set<Entry<K, V>> createEntrySet();
private transient Set<Entry<K, V>> entrySet;
@Override public Set<Entry<K, V>> entrySet() {
Set<Entry<K, V>> result = entrySet;
return (result == null) ? entrySet = createEntrySet() : result;
}
private transient Set<K> keySet;
@Override public Set<K> keySet() {
Set<K> result = keySet;
return (result == null) ? keySet = createKeySet() : result;
}
Set<K> createKeySet() {
return new KeySet<K, V>(this);
}
private transient Collection<V> values;
@Override public Collection<V> values() {
Collection<V> result = values;
return (result == null) ? values = createValues() : result;
}
Collection<V> createValues() {
return new Values<K, V>(this);
}
}
/**
* Delegates to {@link Map#get}. Returns {@code null} on {@code
* ClassCastException} and {@code NullPointerException}.
*/
static <V> V safeGet(Map<?, V> map, @Nullable Object key) {
checkNotNull(map);
try {
return map.get(key);
} catch (ClassCastException e) {
return null;
} catch (NullPointerException e) {
return null;
}
}
/**
* Delegates to {@link Map#containsKey}. Returns {@code false} on {@code
* ClassCastException} and {@code NullPointerException}.
*/
static boolean safeContainsKey(Map<?, ?> map, Object key) {
checkNotNull(map);
try {
return map.containsKey(key);
} catch (ClassCastException e) {
return false;
} catch (NullPointerException e) {
return false;
}
}
/**
* Delegates to {@link Map#remove}. Returns {@code null} on {@code
* ClassCastException} and {@code NullPointerException}.
*/
static <V> V safeRemove(Map<?, V> map, Object key) {
checkNotNull(map);
try {
return map.remove(key);
} catch (ClassCastException e) {
return null;
} catch (NullPointerException e) {
return null;
}
}
/**
* An admittedly inefficient implementation of {@link Map#containsKey}.
*/
static boolean containsKeyImpl(Map<?, ?> map, @Nullable Object key) {
return Iterators.contains(keyIterator(map.entrySet().iterator()), key);
}
/**
* An implementation of {@link Map#containsValue}.
*/
static boolean containsValueImpl(Map<?, ?> map, @Nullable Object value) {
return Iterators.contains(valueIterator(map.entrySet().iterator()), value);
}
/**
* Implements {@code Collection.contains} safely for forwarding collections of
* map entries. If {@code o} is an instance of {@code Map.Entry}, it is
* wrapped using {@link #unmodifiableEntry} to protect against a possible
* nefarious equals method.
*
* <p>Note that {@code c} is the backing (delegate) collection, rather than
* the forwarding collection.
*
* @param c the delegate (unwrapped) collection of map entries
* @param o the object that might be contained in {@code c}
* @return {@code true} if {@code c} contains {@code o}
*/
static <K, V> boolean containsEntryImpl(Collection<Entry<K, V>> c, Object o) {
if (!(o instanceof Entry)) {
return false;
}
return c.contains(unmodifiableEntry((Entry<?, ?>) o));
}
/**
* Implements {@code Collection.remove} safely for forwarding collections of
* map entries. If {@code o} is an instance of {@code Map.Entry}, it is
* wrapped using {@link #unmodifiableEntry} to protect against a possible
* nefarious equals method.
*
* <p>Note that {@code c} is backing (delegate) collection, rather than the
* forwarding collection.
*
* @param c the delegate (unwrapped) collection of map entries
* @param o the object to remove from {@code c}
* @return {@code true} if {@code c} was changed
*/
static <K, V> boolean removeEntryImpl(Collection<Entry<K, V>> c, Object o) {
if (!(o instanceof Entry)) {
return false;
}
return c.remove(unmodifiableEntry((Entry<?, ?>) o));
}
/**
* An implementation of {@link Map#equals}.
*/
static boolean equalsImpl(Map<?, ?> map, Object object) {
if (map == object) {
return true;
} else if (object instanceof Map) {
Map<?, ?> o = (Map<?, ?>) object;
return map.entrySet().equals(o.entrySet());
}
return false;
}
static final MapJoiner STANDARD_JOINER =
Collections2.STANDARD_JOINER.withKeyValueSeparator("=");
/**
* An implementation of {@link Map#toString}.
*/
static String toStringImpl(Map<?, ?> map) {
StringBuilder sb
= Collections2.newStringBuilderForCollection(map.size()).append('{');
STANDARD_JOINER.appendTo(sb, map);
return sb.append('}').toString();
}
/**
* An implementation of {@link Map#putAll}.
*/
static <K, V> void putAllImpl(
Map<K, V> self, Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
self.put(entry.getKey(), entry.getValue());
}
}
static class KeySet<K, V> extends Sets.ImprovedAbstractSet<K> {
final Map<K, V> map;
KeySet(Map<K, V> map) {
this.map = checkNotNull(map);
}
Map<K, V> map() {
return map;
}
@Override public Iterator<K> iterator() {
return keyIterator(map().entrySet().iterator());
}
@Override public int size() {
return map().size();
}
@Override public boolean isEmpty() {
return map().isEmpty();
}
@Override public boolean contains(Object o) {
return map().containsKey(o);
}
@Override public boolean remove(Object o) {
if (contains(o)) {
map().remove(o);
return true;
}
return false;
}
@Override public void clear() {
map().clear();
}
}
@Nullable
static <K> K keyOrNull(@Nullable Entry<K, ?> entry) {
return (entry == null) ? null : entry.getKey();
}
@Nullable
static <V> V valueOrNull(@Nullable Entry<?, V> entry) {
return (entry == null) ? null : entry.getValue();
}
static class SortedKeySet<K, V> extends KeySet<K, V> implements SortedSet<K> {
SortedKeySet(SortedMap<K, V> map) {
super(map);
}
@Override
SortedMap<K, V> map() {
return (SortedMap<K, V>) super.map();
}
@Override
public Comparator<? super K> comparator() {
return map().comparator();
}
@Override
public SortedSet<K> subSet(K fromElement, K toElement) {
return new SortedKeySet<K, V>(map().subMap(fromElement, toElement));
}
@Override
public SortedSet<K> headSet(K toElement) {
return new SortedKeySet<K, V>(map().headMap(toElement));
}
@Override
public SortedSet<K> tailSet(K fromElement) {
return new SortedKeySet<K, V>(map().tailMap(fromElement));
}
@Override
public K first() {
return map().firstKey();
}
@Override
public K last() {
return map().lastKey();
}
}
static class Values<K, V> extends AbstractCollection<V> {
final Map<K, V> map;
Values(Map<K, V> map) {
this.map = checkNotNull(map);
}
final Map<K, V> map() {
return map;
}
@Override public Iterator<V> iterator() {
return valueIterator(map().entrySet().iterator());
}
@Override public boolean remove(Object o) {
try {
return super.remove(o);
} catch (UnsupportedOperationException e) {
for (Entry<K, V> entry : map().entrySet()) {
if (Objects.equal(o, entry.getValue())) {
map().remove(entry.getKey());
return true;
}
}
return false;
}
}
@Override public boolean removeAll(Collection<?> c) {
try {
return super.removeAll(checkNotNull(c));
} catch (UnsupportedOperationException e) {
Set<K> toRemove = Sets.newHashSet();
for (Entry<K, V> entry : map().entrySet()) {
if (c.contains(entry.getValue())) {
toRemove.add(entry.getKey());
}
}
return map().keySet().removeAll(toRemove);
}
}
@Override public boolean retainAll(Collection<?> c) {
try {
return super.retainAll(checkNotNull(c));
} catch (UnsupportedOperationException e) {
Set<K> toRetain = Sets.newHashSet();
for (Entry<K, V> entry : map().entrySet()) {
if (c.contains(entry.getValue())) {
toRetain.add(entry.getKey());
}
}
return map().keySet().retainAll(toRetain);
}
}
@Override public int size() {
return map().size();
}
@Override public boolean isEmpty() {
return map().isEmpty();
}
@Override public boolean contains(@Nullable Object o) {
return map().containsValue(o);
}
@Override public void clear() {
map().clear();
}
}
abstract static class EntrySet<K, V>
extends Sets.ImprovedAbstractSet<Entry<K, V>> {
abstract Map<K, V> map();
@Override public int size() {
return map().size();
}
@Override public void clear() {
map().clear();
}
@Override public boolean contains(Object o) {
if (o instanceof Entry) {
Entry<?, ?> entry = (Entry<?, ?>) o;
Object key = entry.getKey();
V value = Maps.safeGet(map(), key);
return Objects.equal(value, entry.getValue())
&& (value != null || map().containsKey(key));
}
return false;
}
@Override public boolean isEmpty() {
return map().isEmpty();
}
@Override public boolean remove(Object o) {
if (contains(o)) {
Entry<?, ?> entry = (Entry<?, ?>) o;
return map().keySet().remove(entry.getKey());
}
return false;
}
@Override public boolean removeAll(Collection<?> c) {
try {
return super.removeAll(checkNotNull(c));
} catch (UnsupportedOperationException e) {
// if the iterators don't support remove
return Sets.removeAllImpl(this, c.iterator());
}
}
@Override public boolean retainAll(Collection<?> c) {
try {
return super.retainAll(checkNotNull(c));
} catch (UnsupportedOperationException e) {
// if the iterators don't support remove
Set<Object> keys = Sets.newHashSetWithExpectedSize(c.size());
for (Object o : c) {
if (contains(o)) {
Entry<?, ?> entry = (Entry<?, ?>) o;
keys.add(entry.getKey());
}
}
return map().keySet().retainAll(keys);
}
}
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/Maps.java | Java | asf20 | 99,012 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Maps.newTreeMap;
import static java.util.Collections.unmodifiableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
/**
* GWT emulated version of {@link ImmutableSortedMap}. It's a thin wrapper
* around a {@link java.util.TreeMap}.
*
* @author Hayward Chan
*/
public abstract class ImmutableSortedMap<K, V>
extends ForwardingImmutableMap<K, V> implements SortedMap<K, V> {
@SuppressWarnings("unchecked")
static final Comparator NATURAL_ORDER = Ordering.natural();
// This reference is only used by GWT compiler to infer the keys and values
// of the map that needs to be serialized.
private Comparator<? super K> unusedComparatorForSerialization;
private K unusedKeyForSerialization;
private V unusedValueForSerialization;
private final transient SortedMap<K, V> sortedDelegate;
// The comparator used by this map. It's the same as that of sortedDelegate,
// except that when sortedDelegate's comparator is null, it points to a
// non-null instance of Ordering.natural().
// (cpovirk: Is sortedDelegate's comparator really ever null?)
// The comparator will likely also differ because of our nullAccepting hack.
// See the bottom of the file for more information about it.
private final transient Comparator<? super K> comparator;
ImmutableSortedMap(SortedMap<K, V> delegate, Comparator<? super K> comparator) {
super(delegate);
this.comparator = comparator;
this.sortedDelegate = delegate;
}
private static <K, V> ImmutableSortedMap<K, V> create(
Comparator<? super K> comparator,
Entry<? extends K, ? extends V>... entries) {
checkNotNull(comparator);
SortedMap<K, V> delegate = newModifiableDelegate(comparator);
for (Entry<? extends K, ? extends V> entry : entries) {
delegate.put(entry.getKey(), entry.getValue());
}
return newView(unmodifiableSortedMap(delegate), comparator);
}
// Casting to any type is safe because the set will never hold any elements.
@SuppressWarnings("unchecked")
public static <K, V> ImmutableSortedMap<K, V> of() {
return EmptyImmutableSortedMap.forComparator(NATURAL_ORDER);
}
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K k1, V v1) {
return create(Ordering.natural(), entryOf(k1, v1));
}
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K k1, V v1, K k2, V v2) {
return new Builder<K, V>(Ordering.natural())
.put(k1, v1).put(k2, v2).build();
}
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3) {
return new Builder<K, V>(Ordering.natural())
.put(k1, v1).put(k2, v2).put(k3, v3).build();
}
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
return new Builder<K, V>(Ordering.natural())
.put(k1, v1).put(k2, v2).put(k3, v3).put(k4, v4).build();
}
public static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V>
of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
return new Builder<K, V>(Ordering.natural())
.put(k1, v1).put(k2, v2).put(k3, v3).put(k4, v4).put(k5, v5).build();
}
public static <K, V> ImmutableSortedMap<K, V>
copyOf(Map<? extends K, ? extends V> map) {
return copyOfInternal((Map) map, (Ordering<K>) Ordering.natural());
}
public static <K, V> ImmutableSortedMap<K, V> copyOf(
Map<? extends K, ? extends V> map, Comparator<? super K> comparator) {
return copyOfInternal(map, checkNotNull(comparator));
}
public static <K, V> ImmutableSortedMap<K, V> copyOfSorted(
SortedMap<K, ? extends V> map) {
// If map has a null comparator, the keys should have a natural ordering,
// even though K doesn't explicitly implement Comparable.
@SuppressWarnings("unchecked")
Comparator<? super K> comparator =
(map.comparator() == null) ? NATURAL_ORDER : map.comparator();
return copyOfInternal(map, comparator);
}
private static <K, V> ImmutableSortedMap<K, V> copyOfInternal(
Map<? extends K, ? extends V> map, Comparator<? super K> comparator) {
if (map instanceof ImmutableSortedMap) {
// TODO: Prove that this cast is safe, even though
// Collections.unmodifiableSortedMap requires the same key type.
@SuppressWarnings("unchecked")
ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map;
Comparator<?> comparator2 = kvMap.comparator();
boolean sameComparator = (comparator2 == null)
? comparator == NATURAL_ORDER
: comparator.equals(comparator2);
if (sameComparator) {
return kvMap;
}
}
SortedMap<K, V> delegate = newModifiableDelegate(comparator);
for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
putEntryWithChecks(delegate, entry);
}
return newView(unmodifiableSortedMap(delegate), comparator);
}
private static <K, V> void putEntryWithChecks(
SortedMap<K, V> map, Entry<? extends K, ? extends V> entry) {
K key = checkNotNull(entry.getKey());
V value = checkNotNull(entry.getValue());
if (map.containsKey(key)) {
// When a collision happens, the colliding entry is the first entry
// of the tail map.
Entry<K, V> previousEntry
= map.tailMap(key).entrySet().iterator().next();
throw new IllegalArgumentException(
"Duplicate keys in mappings " + previousEntry.getKey() +
"=" + previousEntry.getValue() + " and " + key +
"=" + value);
}
map.put(key, value);
}
public static <K extends Comparable<?>, V> Builder<K, V> naturalOrder() {
return new Builder<K, V>(Ordering.natural());
}
public static <K, V> Builder<K, V> orderedBy(Comparator<K> comparator) {
return new Builder<K, V>(comparator);
}
public static <K extends Comparable<?>, V> Builder<K, V> reverseOrder() {
return new Builder<K, V>(Ordering.natural().reverse());
}
public static final class Builder<K, V> extends ImmutableMap.Builder<K, V> {
private final Comparator<? super K> comparator;
public Builder(Comparator<? super K> comparator) {
this.comparator = checkNotNull(comparator);
}
@Override public Builder<K, V> put(K key, V value) {
entries.add(entryOf(key, value));
return this;
}
@Override public Builder<K, V> put(Entry<? extends K, ? extends V> entry) {
super.put(entry);
return this;
}
@Override public Builder<K, V> putAll(Map<? extends K, ? extends V> map) {
for (Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
return this;
}
@Override public ImmutableSortedMap<K, V> build() {
SortedMap<K, V> delegate = newModifiableDelegate(comparator);
for (Entry<? extends K, ? extends V> entry : entries) {
putEntryWithChecks(delegate, entry);
}
return newView(unmodifiableSortedMap(delegate), comparator);
}
}
private transient ImmutableSortedSet<K> keySet;
@Override public ImmutableSortedSet<K> keySet() {
ImmutableSortedSet<K> ks = keySet;
return (ks == null) ? (keySet = createKeySet()) : ks;
}
@Override ImmutableSortedSet<K> createKeySet() {
// the keySet() of the delegate is only a Set and TreeMap.navigatableKeySet
// is not available in GWT yet. To keep the code simple and code size more,
// we make a copy here, instead of creating a view of it.
//
// TODO: revisit if it's unbearably slow or when GWT supports
// TreeMap.navigatbleKeySet().
return ImmutableSortedSet.copyOf(comparator, sortedDelegate.keySet());
}
public Comparator<? super K> comparator() {
return comparator;
}
public K firstKey() {
return sortedDelegate.firstKey();
}
public K lastKey() {
return sortedDelegate.lastKey();
}
K higher(K k) {
Iterator<K> iterator = keySet().tailSet(k).iterator();
while (iterator.hasNext()) {
K tmp = iterator.next();
if (comparator().compare(k, tmp) < 0) {
return tmp;
}
}
return null;
}
public ImmutableSortedMap<K, V> headMap(K toKey) {
checkNotNull(toKey);
return newView(sortedDelegate.headMap(toKey));
}
ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) {
checkNotNull(toKey);
if (inclusive) {
K tmp = higher(toKey);
if (tmp == null) {
return this;
}
toKey = tmp;
}
return headMap(toKey);
}
public ImmutableSortedMap<K, V> subMap(K fromKey, K toKey) {
checkNotNull(fromKey);
checkNotNull(toKey);
checkArgument(comparator.compare(fromKey, toKey) <= 0);
return newView(sortedDelegate.subMap(fromKey, toKey));
}
ImmutableSortedMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) {
checkNotNull(fromKey);
checkNotNull(toKey);
checkArgument(comparator.compare(fromKey, toKey) <= 0);
return tailMap(fromKey, fromInclusive).headMap(toKey, toInclusive);
}
public ImmutableSortedMap<K, V> tailMap(K fromKey) {
checkNotNull(fromKey);
return newView(sortedDelegate.tailMap(fromKey));
}
public ImmutableSortedMap<K, V> tailMap(K fromKey, boolean inclusive) {
checkNotNull(fromKey);
if (!inclusive) {
fromKey = higher(fromKey);
if (fromKey == null) {
return EmptyImmutableSortedMap.forComparator(comparator());
}
}
return tailMap(fromKey);
}
private ImmutableSortedMap<K, V> newView(SortedMap<K, V> delegate) {
return newView(delegate, comparator);
}
private static <K, V> ImmutableSortedMap<K, V> newView(
SortedMap<K, V> delegate, Comparator<? super K> comparator) {
if (delegate.isEmpty()) {
return EmptyImmutableSortedMap.forComparator(comparator);
}
return new RegularImmutableSortedMap<K, V>(delegate, comparator);
}
/*
* We don't permit nulls, but we wrap every comparator with nullsFirst().
* Why? We want for queries like containsKey(null) to return false, but the
* GWT SortedMap implementation that we delegate to throws
* NullPointerException if the comparator does. Since our construction
* methods ensure that null is never present in the map, it's OK for the
* comparator to look for it wherever it wants.
*
* Note that we do NOT touch the comparator returned by comparator(), which
* should be identical to the one the user passed in. We touch only the
* "secret" comparator used by the delegate implementation.
*/
private static <K, V> SortedMap<K, V> newModifiableDelegate(Comparator<? super K> comparator) {
return newTreeMap(nullAccepting(comparator));
}
private static <E> Comparator<E> nullAccepting(Comparator<E> comparator) {
return Ordering.from(comparator).nullsFirst();
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ImmutableSortedMap.java | Java | asf20 | 11,852 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps.EntryTransformer;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedSet;
import javax.annotation.Nullable;
/**
* Provides static methods acting on or generating a {@code Multimap}.
*
* <p>See the Guava User Guide article on <a href=
* "http://code.google.com/p/guava-libraries/wiki/CollectionUtilitiesExplained#Multimaps">
* {@code Multimaps}</a>.
*
* @author Jared Levy
* @author Robert Konigsberg
* @author Mike Bostock
* @author Louis Wasserman
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class Multimaps {
private Multimaps() {}
/**
* Creates a new {@code Multimap} backed by {@code map}, whose internal value
* collections are generated by {@code factory}.
*
* <b>Warning: do not use</b> this method when the collections returned by
* {@code factory} implement either {@link List} or {@code Set}! Use the more
* specific method {@link #newListMultimap}, {@link #newSetMultimap} or {@link
* #newSortedSetMultimap} instead, to avoid very surprising behavior from
* {@link Multimap#equals}.
*
* <p>The {@code factory}-generated and {@code map} classes determine the
* multimap iteration order. They also specify the behavior of the
* {@code equals}, {@code hashCode}, and {@code toString} methods for the
* multimap and its returned views. However, the multimap's {@code get}
* method returns instances of a different class than {@code factory.get()}
* does.
*
* <p>The multimap is serializable if {@code map}, {@code factory}, the
* collections generated by {@code factory}, and the multimap contents are all
* serializable.
*
* <p>The multimap is not threadsafe when any concurrent operations update the
* multimap, even if {@code map} and the instances generated by
* {@code factory} are. Concurrent read operations will work correctly. To
* allow concurrent update operations, wrap the multimap with a call to
* {@link #synchronizedMultimap}.
*
* <p>Call this method only when the simpler methods
* {@link ArrayListMultimap#create()}, {@link HashMultimap#create()},
* {@link LinkedHashMultimap#create()}, {@link LinkedListMultimap#create()},
* {@link TreeMultimap#create()}, and
* {@link TreeMultimap#create(Comparator, Comparator)} won't suffice.
*
* <p>Note: the multimap assumes complete ownership over of {@code map} and
* the collections returned by {@code factory}. Those objects should not be
* manually updated and they should not use soft, weak, or phantom references.
*
* @param map place to store the mapping from each key to its corresponding
* values
* @param factory supplier of new, empty collections that will each hold all
* values for a given key
* @throws IllegalArgumentException if {@code map} is not empty
*/
public static <K, V> Multimap<K, V> newMultimap(Map<K, Collection<V>> map,
final Supplier<? extends Collection<V>> factory) {
return new CustomMultimap<K, V>(map, factory);
}
private static class CustomMultimap<K, V> extends AbstractMapBasedMultimap<K, V> {
transient Supplier<? extends Collection<V>> factory;
CustomMultimap(Map<K, Collection<V>> map,
Supplier<? extends Collection<V>> factory) {
super(map);
this.factory = checkNotNull(factory);
}
@Override protected Collection<V> createCollection() {
return factory.get();
}
// can't use Serialization writeMultimap and populateMultimap methods since
// there's no way to generate the empty backing map.
}
/**
* Creates a new {@code ListMultimap} that uses the provided map and factory.
* It can generate a multimap based on arbitrary {@link Map} and {@link List}
* classes.
*
* <p>The {@code factory}-generated and {@code map} classes determine the
* multimap iteration order. They also specify the behavior of the
* {@code equals}, {@code hashCode}, and {@code toString} methods for the
* multimap and its returned views. The multimap's {@code get}, {@code
* removeAll}, and {@code replaceValues} methods return {@code RandomAccess}
* lists if the factory does. However, the multimap's {@code get} method
* returns instances of a different class than does {@code factory.get()}.
*
* <p>The multimap is serializable if {@code map}, {@code factory}, the
* lists generated by {@code factory}, and the multimap contents are all
* serializable.
*
* <p>The multimap is not threadsafe when any concurrent operations update the
* multimap, even if {@code map} and the instances generated by
* {@code factory} are. Concurrent read operations will work correctly. To
* allow concurrent update operations, wrap the multimap with a call to
* {@link #synchronizedListMultimap}.
*
* <p>Call this method only when the simpler methods
* {@link ArrayListMultimap#create()} and {@link LinkedListMultimap#create()}
* won't suffice.
*
* <p>Note: the multimap assumes complete ownership over of {@code map} and
* the lists returned by {@code factory}. Those objects should not be manually
* updated, they should be empty when provided, and they should not use soft,
* weak, or phantom references.
*
* @param map place to store the mapping from each key to its corresponding
* values
* @param factory supplier of new, empty lists that will each hold all values
* for a given key
* @throws IllegalArgumentException if {@code map} is not empty
*/
public static <K, V> ListMultimap<K, V> newListMultimap(
Map<K, Collection<V>> map, final Supplier<? extends List<V>> factory) {
return new CustomListMultimap<K, V>(map, factory);
}
private static class CustomListMultimap<K, V>
extends AbstractListMultimap<K, V> {
transient Supplier<? extends List<V>> factory;
CustomListMultimap(Map<K, Collection<V>> map,
Supplier<? extends List<V>> factory) {
super(map);
this.factory = checkNotNull(factory);
}
@Override protected List<V> createCollection() {
return factory.get();
}
}
/**
* Creates a new {@code SetMultimap} that uses the provided map and factory.
* It can generate a multimap based on arbitrary {@link Map} and {@link Set}
* classes.
*
* <p>The {@code factory}-generated and {@code map} classes determine the
* multimap iteration order. They also specify the behavior of the
* {@code equals}, {@code hashCode}, and {@code toString} methods for the
* multimap and its returned views. However, the multimap's {@code get}
* method returns instances of a different class than {@code factory.get()}
* does.
*
* <p>The multimap is serializable if {@code map}, {@code factory}, the
* sets generated by {@code factory}, and the multimap contents are all
* serializable.
*
* <p>The multimap is not threadsafe when any concurrent operations update the
* multimap, even if {@code map} and the instances generated by
* {@code factory} are. Concurrent read operations will work correctly. To
* allow concurrent update operations, wrap the multimap with a call to
* {@link #synchronizedSetMultimap}.
*
* <p>Call this method only when the simpler methods
* {@link HashMultimap#create()}, {@link LinkedHashMultimap#create()},
* {@link TreeMultimap#create()}, and
* {@link TreeMultimap#create(Comparator, Comparator)} won't suffice.
*
* <p>Note: the multimap assumes complete ownership over of {@code map} and
* the sets returned by {@code factory}. Those objects should not be manually
* updated and they should not use soft, weak, or phantom references.
*
* @param map place to store the mapping from each key to its corresponding
* values
* @param factory supplier of new, empty sets that will each hold all values
* for a given key
* @throws IllegalArgumentException if {@code map} is not empty
*/
public static <K, V> SetMultimap<K, V> newSetMultimap(
Map<K, Collection<V>> map, final Supplier<? extends Set<V>> factory) {
return new CustomSetMultimap<K, V>(map, factory);
}
private static class CustomSetMultimap<K, V>
extends AbstractSetMultimap<K, V> {
transient Supplier<? extends Set<V>> factory;
CustomSetMultimap(Map<K, Collection<V>> map,
Supplier<? extends Set<V>> factory) {
super(map);
this.factory = checkNotNull(factory);
}
@Override protected Set<V> createCollection() {
return factory.get();
}
}
/**
* Creates a new {@code SortedSetMultimap} that uses the provided map and
* factory. It can generate a multimap based on arbitrary {@link Map} and
* {@link SortedSet} classes.
*
* <p>The {@code factory}-generated and {@code map} classes determine the
* multimap iteration order. They also specify the behavior of the
* {@code equals}, {@code hashCode}, and {@code toString} methods for the
* multimap and its returned views. However, the multimap's {@code get}
* method returns instances of a different class than {@code factory.get()}
* does.
*
* <p>The multimap is serializable if {@code map}, {@code factory}, the
* sets generated by {@code factory}, and the multimap contents are all
* serializable.
*
* <p>The multimap is not threadsafe when any concurrent operations update the
* multimap, even if {@code map} and the instances generated by
* {@code factory} are. Concurrent read operations will work correctly. To
* allow concurrent update operations, wrap the multimap with a call to
* {@link #synchronizedSortedSetMultimap}.
*
* <p>Call this method only when the simpler methods
* {@link TreeMultimap#create()} and
* {@link TreeMultimap#create(Comparator, Comparator)} won't suffice.
*
* <p>Note: the multimap assumes complete ownership over of {@code map} and
* the sets returned by {@code factory}. Those objects should not be manually
* updated and they should not use soft, weak, or phantom references.
*
* @param map place to store the mapping from each key to its corresponding
* values
* @param factory supplier of new, empty sorted sets that will each hold
* all values for a given key
* @throws IllegalArgumentException if {@code map} is not empty
*/
public static <K, V> SortedSetMultimap<K, V> newSortedSetMultimap(
Map<K, Collection<V>> map,
final Supplier<? extends SortedSet<V>> factory) {
return new CustomSortedSetMultimap<K, V>(map, factory);
}
private static class CustomSortedSetMultimap<K, V>
extends AbstractSortedSetMultimap<K, V> {
transient Supplier<? extends SortedSet<V>> factory;
transient Comparator<? super V> valueComparator;
CustomSortedSetMultimap(Map<K, Collection<V>> map,
Supplier<? extends SortedSet<V>> factory) {
super(map);
this.factory = checkNotNull(factory);
valueComparator = factory.get().comparator();
}
@Override protected SortedSet<V> createCollection() {
return factory.get();
}
@Override public Comparator<? super V> valueComparator() {
return valueComparator;
}
}
/**
* Copies each key-value mapping in {@code source} into {@code dest}, with
* its key and value reversed.
*
* <p>If {@code source} is an {@link ImmutableMultimap}, consider using
* {@link ImmutableMultimap#inverse} instead.
*
* @param source any multimap
* @param dest the multimap to copy into; usually empty
* @return {@code dest}
*/
public static <K, V, M extends Multimap<K, V>> M invertFrom(
Multimap<? extends V, ? extends K> source, M dest) {
checkNotNull(dest);
for (Map.Entry<? extends V, ? extends K> entry : source.entries()) {
dest.put(entry.getValue(), entry.getKey());
}
return dest;
}
/**
* Returns a synchronized (thread-safe) multimap backed by the specified
* multimap. In order to guarantee serial access, it is critical that
* <b>all</b> access to the backing multimap is accomplished through the
* returned multimap.
*
* <p>It is imperative that the user manually synchronize on the returned
* multimap when accessing any of its collection views: <pre> {@code
*
* Multimap<K, V> multimap = Multimaps.synchronizedMultimap(
* HashMultimap.<K, V>create());
* ...
* Collection<V> values = multimap.get(key); // Needn't be in synchronized block
* ...
* synchronized (multimap) { // Synchronizing on multimap, not values!
* Iterator<V> i = values.iterator(); // Must be in synchronized block
* while (i.hasNext()) {
* foo(i.next());
* }
* }}</pre>
*
* <p>Failure to follow this advice may result in non-deterministic behavior.
*
* <p>Note that the generated multimap's {@link Multimap#removeAll} and
* {@link Multimap#replaceValues} methods return collections that aren't
* synchronized.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param multimap the multimap to be wrapped in a synchronized view
* @return a synchronized view of the specified multimap
*/
public static <K, V> Multimap<K, V> synchronizedMultimap(
Multimap<K, V> multimap) {
return Synchronized.multimap(multimap, null);
}
/**
* Returns an unmodifiable view of the specified multimap. Query operations on
* the returned multimap "read through" to the specified multimap, and
* attempts to modify the returned multimap, either directly or through the
* multimap's views, result in an {@code UnsupportedOperationException}.
*
* <p>Note that the generated multimap's {@link Multimap#removeAll} and
* {@link Multimap#replaceValues} methods return collections that are
* modifiable.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param delegate the multimap for which an unmodifiable view is to be
* returned
* @return an unmodifiable view of the specified multimap
*/
public static <K, V> Multimap<K, V> unmodifiableMultimap(
Multimap<K, V> delegate) {
if (delegate instanceof UnmodifiableMultimap ||
delegate instanceof ImmutableMultimap) {
return delegate;
}
return new UnmodifiableMultimap<K, V>(delegate);
}
/**
* Simply returns its argument.
*
* @deprecated no need to use this
* @since 10.0
*/
@Deprecated public static <K, V> Multimap<K, V> unmodifiableMultimap(
ImmutableMultimap<K, V> delegate) {
return checkNotNull(delegate);
}
private static class UnmodifiableMultimap<K, V>
extends ForwardingMultimap<K, V> implements Serializable {
final Multimap<K, V> delegate;
transient Collection<Entry<K, V>> entries;
transient Multiset<K> keys;
transient Set<K> keySet;
transient Collection<V> values;
transient Map<K, Collection<V>> map;
UnmodifiableMultimap(final Multimap<K, V> delegate) {
this.delegate = checkNotNull(delegate);
}
@Override protected Multimap<K, V> delegate() {
return delegate;
}
@Override public void clear() {
throw new UnsupportedOperationException();
}
@Override public Map<K, Collection<V>> asMap() {
Map<K, Collection<V>> result = map;
if (result == null) {
result = map = Collections.unmodifiableMap(
Maps.transformValues(delegate.asMap(), new Function<Collection<V>, Collection<V>>() {
@Override
public Collection<V> apply(Collection<V> collection) {
return unmodifiableValueCollection(collection);
}
}));
}
return result;
}
@Override public Collection<Entry<K, V>> entries() {
Collection<Entry<K, V>> result = entries;
if (result == null) {
entries = result = unmodifiableEntries(delegate.entries());
}
return result;
}
@Override public Collection<V> get(K key) {
return unmodifiableValueCollection(delegate.get(key));
}
@Override public Multiset<K> keys() {
Multiset<K> result = keys;
if (result == null) {
keys = result = Multisets.unmodifiableMultiset(delegate.keys());
}
return result;
}
@Override public Set<K> keySet() {
Set<K> result = keySet;
if (result == null) {
keySet = result = Collections.unmodifiableSet(delegate.keySet());
}
return result;
}
@Override public boolean put(K key, V value) {
throw new UnsupportedOperationException();
}
@Override public boolean putAll(K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
throw new UnsupportedOperationException();
}
@Override public boolean remove(Object key, Object value) {
throw new UnsupportedOperationException();
}
@Override public Collection<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
@Override public Collection<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
@Override public Collection<V> values() {
Collection<V> result = values;
if (result == null) {
values = result = Collections.unmodifiableCollection(delegate.values());
}
return result;
}
private static final long serialVersionUID = 0;
}
private static class UnmodifiableListMultimap<K, V>
extends UnmodifiableMultimap<K, V> implements ListMultimap<K, V> {
UnmodifiableListMultimap(ListMultimap<K, V> delegate) {
super(delegate);
}
@Override public ListMultimap<K, V> delegate() {
return (ListMultimap<K, V>) super.delegate();
}
@Override public List<V> get(K key) {
return Collections.unmodifiableList(delegate().get(key));
}
@Override public List<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
@Override public List<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
private static final long serialVersionUID = 0;
}
private static class UnmodifiableSetMultimap<K, V>
extends UnmodifiableMultimap<K, V> implements SetMultimap<K, V> {
UnmodifiableSetMultimap(SetMultimap<K, V> delegate) {
super(delegate);
}
@Override public SetMultimap<K, V> delegate() {
return (SetMultimap<K, V>) super.delegate();
}
@Override public Set<V> get(K key) {
/*
* Note that this doesn't return a SortedSet when delegate is a
* SortedSetMultiset, unlike (SortedSet<V>) super.get().
*/
return Collections.unmodifiableSet(delegate().get(key));
}
@Override public Set<Map.Entry<K, V>> entries() {
return Maps.unmodifiableEntrySet(delegate().entries());
}
@Override public Set<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
@Override public Set<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
private static final long serialVersionUID = 0;
}
private static class UnmodifiableSortedSetMultimap<K, V>
extends UnmodifiableSetMultimap<K, V> implements SortedSetMultimap<K, V> {
UnmodifiableSortedSetMultimap(SortedSetMultimap<K, V> delegate) {
super(delegate);
}
@Override public SortedSetMultimap<K, V> delegate() {
return (SortedSetMultimap<K, V>) super.delegate();
}
@Override public SortedSet<V> get(K key) {
return Collections.unmodifiableSortedSet(delegate().get(key));
}
@Override public SortedSet<V> removeAll(Object key) {
throw new UnsupportedOperationException();
}
@Override public SortedSet<V> replaceValues(
K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
@Override
public Comparator<? super V> valueComparator() {
return delegate().valueComparator();
}
private static final long serialVersionUID = 0;
}
/**
* Returns a synchronized (thread-safe) {@code SetMultimap} backed by the
* specified multimap.
*
* <p>You must follow the warnings described in {@link #synchronizedMultimap}.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param multimap the multimap to be wrapped
* @return a synchronized view of the specified multimap
*/
public static <K, V> SetMultimap<K, V> synchronizedSetMultimap(
SetMultimap<K, V> multimap) {
return Synchronized.setMultimap(multimap, null);
}
/**
* Returns an unmodifiable view of the specified {@code SetMultimap}. Query
* operations on the returned multimap "read through" to the specified
* multimap, and attempts to modify the returned multimap, either directly or
* through the multimap's views, result in an
* {@code UnsupportedOperationException}.
*
* <p>Note that the generated multimap's {@link Multimap#removeAll} and
* {@link Multimap#replaceValues} methods return collections that are
* modifiable.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param delegate the multimap for which an unmodifiable view is to be
* returned
* @return an unmodifiable view of the specified multimap
*/
public static <K, V> SetMultimap<K, V> unmodifiableSetMultimap(
SetMultimap<K, V> delegate) {
if (delegate instanceof UnmodifiableSetMultimap ||
delegate instanceof ImmutableSetMultimap) {
return delegate;
}
return new UnmodifiableSetMultimap<K, V>(delegate);
}
/**
* Simply returns its argument.
*
* @deprecated no need to use this
* @since 10.0
*/
@Deprecated public static <K, V> SetMultimap<K, V> unmodifiableSetMultimap(
ImmutableSetMultimap<K, V> delegate) {
return checkNotNull(delegate);
}
/**
* Returns a synchronized (thread-safe) {@code SortedSetMultimap} backed by
* the specified multimap.
*
* <p>You must follow the warnings described in {@link #synchronizedMultimap}.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param multimap the multimap to be wrapped
* @return a synchronized view of the specified multimap
*/
public static <K, V> SortedSetMultimap<K, V>
synchronizedSortedSetMultimap(SortedSetMultimap<K, V> multimap) {
return Synchronized.sortedSetMultimap(multimap, null);
}
/**
* Returns an unmodifiable view of the specified {@code SortedSetMultimap}.
* Query operations on the returned multimap "read through" to the specified
* multimap, and attempts to modify the returned multimap, either directly or
* through the multimap's views, result in an
* {@code UnsupportedOperationException}.
*
* <p>Note that the generated multimap's {@link Multimap#removeAll} and
* {@link Multimap#replaceValues} methods return collections that are
* modifiable.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param delegate the multimap for which an unmodifiable view is to be
* returned
* @return an unmodifiable view of the specified multimap
*/
public static <K, V> SortedSetMultimap<K, V> unmodifiableSortedSetMultimap(
SortedSetMultimap<K, V> delegate) {
if (delegate instanceof UnmodifiableSortedSetMultimap) {
return delegate;
}
return new UnmodifiableSortedSetMultimap<K, V>(delegate);
}
/**
* Returns a synchronized (thread-safe) {@code ListMultimap} backed by the
* specified multimap.
*
* <p>You must follow the warnings described in {@link #synchronizedMultimap}.
*
* @param multimap the multimap to be wrapped
* @return a synchronized view of the specified multimap
*/
public static <K, V> ListMultimap<K, V> synchronizedListMultimap(
ListMultimap<K, V> multimap) {
return Synchronized.listMultimap(multimap, null);
}
/**
* Returns an unmodifiable view of the specified {@code ListMultimap}. Query
* operations on the returned multimap "read through" to the specified
* multimap, and attempts to modify the returned multimap, either directly or
* through the multimap's views, result in an
* {@code UnsupportedOperationException}.
*
* <p>Note that the generated multimap's {@link Multimap#removeAll} and
* {@link Multimap#replaceValues} methods return collections that are
* modifiable.
*
* <p>The returned multimap will be serializable if the specified multimap is
* serializable.
*
* @param delegate the multimap for which an unmodifiable view is to be
* returned
* @return an unmodifiable view of the specified multimap
*/
public static <K, V> ListMultimap<K, V> unmodifiableListMultimap(
ListMultimap<K, V> delegate) {
if (delegate instanceof UnmodifiableListMultimap ||
delegate instanceof ImmutableListMultimap) {
return delegate;
}
return new UnmodifiableListMultimap<K, V>(delegate);
}
/**
* Simply returns its argument.
*
* @deprecated no need to use this
* @since 10.0
*/
@Deprecated public static <K, V> ListMultimap<K, V> unmodifiableListMultimap(
ImmutableListMultimap<K, V> delegate) {
return checkNotNull(delegate);
}
/**
* Returns an unmodifiable view of the specified collection, preserving the
* interface for instances of {@code SortedSet}, {@code Set}, {@code List} and
* {@code Collection}, in that order of preference.
*
* @param collection the collection for which to return an unmodifiable view
* @return an unmodifiable view of the collection
*/
private static <V> Collection<V> unmodifiableValueCollection(
Collection<V> collection) {
if (collection instanceof SortedSet) {
return Collections.unmodifiableSortedSet((SortedSet<V>) collection);
} else if (collection instanceof Set) {
return Collections.unmodifiableSet((Set<V>) collection);
} else if (collection instanceof List) {
return Collections.unmodifiableList((List<V>) collection);
}
return Collections.unmodifiableCollection(collection);
}
/**
* Returns an unmodifiable view of the specified collection of entries. The
* {@link Entry#setValue} operation throws an {@link
* UnsupportedOperationException}. If the specified collection is a {@code
* Set}, the returned collection is also a {@code Set}.
*
* @param entries the entries for which to return an unmodifiable view
* @return an unmodifiable view of the entries
*/
private static <K, V> Collection<Entry<K, V>> unmodifiableEntries(
Collection<Entry<K, V>> entries) {
if (entries instanceof Set) {
return Maps.unmodifiableEntrySet((Set<Entry<K, V>>) entries);
}
return new Maps.UnmodifiableEntries<K, V>(
Collections.unmodifiableCollection(entries));
}
/**
* Returns {@link ListMultimap#asMap multimap.asMap()}, with its type
* corrected from {@code Map<K, Collection<V>>} to {@code Map<K, List<V>>}.
*
* @since 15.0
*/
@Beta
@SuppressWarnings("unchecked")
// safe by specification of ListMultimap.asMap()
public static <K, V> Map<K, List<V>> asMap(ListMultimap<K, V> multimap) {
return (Map<K, List<V>>) (Map<K, ?>) multimap.asMap();
}
/**
* Returns {@link SetMultimap#asMap multimap.asMap()}, with its type corrected
* from {@code Map<K, Collection<V>>} to {@code Map<K, Set<V>>}.
*
* @since 15.0
*/
@Beta
@SuppressWarnings("unchecked")
// safe by specification of SetMultimap.asMap()
public static <K, V> Map<K, Set<V>> asMap(SetMultimap<K, V> multimap) {
return (Map<K, Set<V>>) (Map<K, ?>) multimap.asMap();
}
/**
* Returns {@link SortedSetMultimap#asMap multimap.asMap()}, with its type
* corrected from {@code Map<K, Collection<V>>} to
* {@code Map<K, SortedSet<V>>}.
*
* @since 15.0
*/
@Beta
@SuppressWarnings("unchecked")
// safe by specification of SortedSetMultimap.asMap()
public static <K, V> Map<K, SortedSet<V>> asMap(
SortedSetMultimap<K, V> multimap) {
return (Map<K, SortedSet<V>>) (Map<K, ?>) multimap.asMap();
}
/**
* Returns {@link Multimap#asMap multimap.asMap()}. This is provided for
* parity with the other more strongly-typed {@code asMap()} implementations.
*
* @since 15.0
*/
@Beta
public static <K, V> Map<K, Collection<V>> asMap(Multimap<K, V> multimap) {
return multimap.asMap();
}
/**
* Returns a multimap view of the specified map. The multimap is backed by the
* map, so changes to the map are reflected in the multimap, and vice versa.
* If the map is modified while an iteration over one of the multimap's
* collection views is in progress (except through the iterator's own {@code
* remove} operation, or through the {@code setValue} operation on a map entry
* returned by the iterator), the results of the iteration are undefined.
*
* <p>The multimap supports mapping removal, which removes the corresponding
* mapping from the map. It does not support any operations which might add
* mappings, such as {@code put}, {@code putAll} or {@code replaceValues}.
*
* <p>The returned multimap will be serializable if the specified map is
* serializable.
*
* @param map the backing map for the returned multimap view
*/
public static <K, V> SetMultimap<K, V> forMap(Map<K, V> map) {
return new MapMultimap<K, V>(map);
}
/** @see Multimaps#forMap */
private static class MapMultimap<K, V>
extends AbstractMultimap<K, V> implements SetMultimap<K, V>, Serializable {
final Map<K, V> map;
MapMultimap(Map<K, V> map) {
this.map = checkNotNull(map);
}
@Override
public int size() {
return map.size();
}
@Override
public boolean containsKey(Object key) {
return map.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return map.containsValue(value);
}
@Override
public boolean containsEntry(Object key, Object value) {
return map.entrySet().contains(Maps.immutableEntry(key, value));
}
@Override
public Set<V> get(final K key) {
return new Sets.ImprovedAbstractSet<V>() {
@Override public Iterator<V> iterator() {
return new Iterator<V>() {
int i;
@Override
public boolean hasNext() {
return (i == 0) && map.containsKey(key);
}
@Override
public V next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
i++;
return map.get(key);
}
@Override
public void remove() {
checkRemove(i == 1);
i = -1;
map.remove(key);
}
};
}
@Override public int size() {
return map.containsKey(key) ? 1 : 0;
}
};
}
@Override
public boolean put(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public boolean putAll(K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
throw new UnsupportedOperationException();
}
@Override
public Set<V> replaceValues(K key, Iterable<? extends V> values) {
throw new UnsupportedOperationException();
}
@Override
public boolean remove(Object key, Object value) {
return map.entrySet().remove(Maps.immutableEntry(key, value));
}
@Override
public Set<V> removeAll(Object key) {
Set<V> values = new HashSet<V>(2);
if (!map.containsKey(key)) {
return values;
}
values.add(map.remove(key));
return values;
}
@Override
public void clear() {
map.clear();
}
@Override
public Set<K> keySet() {
return map.keySet();
}
@Override
public Collection<V> values() {
return map.values();
}
@Override
public Set<Entry<K, V>> entries() {
return map.entrySet();
}
@Override
Iterator<Entry<K, V>> entryIterator() {
return map.entrySet().iterator();
}
@Override
Map<K, Collection<V>> createAsMap() {
return new AsMap<K, V>(this);
}
@Override public int hashCode() {
return map.hashCode();
}
private static final long serialVersionUID = 7845222491160860175L;
}
/**
* Returns a view of a multimap where each value is transformed by a function.
* All other properties of the multimap, such as iteration order, are left
* intact. For example, the code: <pre> {@code
*
* Multimap<String, Integer> multimap =
* ImmutableSetMultimap.of("a", 2, "b", -3, "b", -3, "a", 4, "c", 6);
* Function<Integer, String> square = new Function<Integer, String>() {
* public String apply(Integer in) {
* return Integer.toString(in * in);
* }
* };
* Multimap<String, String> transformed =
* Multimaps.transformValues(multimap, square);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {a=[4, 16], b=[9, 9], c=[36]}}.
*
* <p>Changes in the underlying multimap are reflected in this view.
* Conversely, this view supports removal operations, and these are reflected
* in the underlying multimap.
*
* <p>It's acceptable for the underlying multimap to contain null keys, and
* even null values provided that the function is capable of accepting null
* input. The transformed multimap might contain null values, if the function
* sometimes gives a null result.
*
* <p>The returned multimap is not thread-safe or serializable, even if the
* underlying multimap is. The {@code equals} and {@code hashCode} methods
* of the returned multimap are meaningless, since there is not a definition
* of {@code equals} or {@code hashCode} for general collections, and
* {@code get()} will return a general {@code Collection} as opposed to a
* {@code List} or a {@code Set}.
*
* <p>The function is applied lazily, invoked when needed. This is necessary
* for the returned multimap to be a view, but it means that the function will
* be applied many times for bulk operations like
* {@link Multimap#containsValue} and {@code Multimap.toString()}. For this to
* perform well, {@code function} should be fast. To avoid lazy evaluation
* when the returned multimap doesn't need to be a view, copy the returned
* multimap into a new multimap of your choosing.
*
* @since 7.0
*/
public static <K, V1, V2> Multimap<K, V2> transformValues(
Multimap<K, V1> fromMultimap, final Function<? super V1, V2> function) {
checkNotNull(function);
EntryTransformer<K, V1, V2> transformer = Maps.asEntryTransformer(function);
return transformEntries(fromMultimap, transformer);
}
/**
* Returns a view of a multimap whose values are derived from the original
* multimap's entries. In contrast to {@link #transformValues}, this method's
* entry-transformation logic may depend on the key as well as the value.
*
* <p>All other properties of the transformed multimap, such as iteration
* order, are left intact. For example, the code: <pre> {@code
*
* SetMultimap<String, Integer> multimap =
* ImmutableSetMultimap.of("a", 1, "a", 4, "b", -6);
* EntryTransformer<String, Integer, String> transformer =
* new EntryTransformer<String, Integer, String>() {
* public String transformEntry(String key, Integer value) {
* return (value >= 0) ? key : "no" + key;
* }
* };
* Multimap<String, String> transformed =
* Multimaps.transformEntries(multimap, transformer);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {a=[a, a], b=[nob]}}.
*
* <p>Changes in the underlying multimap are reflected in this view.
* Conversely, this view supports removal operations, and these are reflected
* in the underlying multimap.
*
* <p>It's acceptable for the underlying multimap to contain null keys and
* null values provided that the transformer is capable of accepting null
* inputs. The transformed multimap might contain null values if the
* transformer sometimes gives a null result.
*
* <p>The returned multimap is not thread-safe or serializable, even if the
* underlying multimap is. The {@code equals} and {@code hashCode} methods
* of the returned multimap are meaningless, since there is not a definition
* of {@code equals} or {@code hashCode} for general collections, and
* {@code get()} will return a general {@code Collection} as opposed to a
* {@code List} or a {@code Set}.
*
* <p>The transformer is applied lazily, invoked when needed. This is
* necessary for the returned multimap to be a view, but it means that the
* transformer will be applied many times for bulk operations like {@link
* Multimap#containsValue} and {@link Object#toString}. For this to perform
* well, {@code transformer} should be fast. To avoid lazy evaluation when the
* returned multimap doesn't need to be a view, copy the returned multimap
* into a new multimap of your choosing.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* {@code EntryTransformer} key type {@code K}, {@code k.equals(k2)} implies
* that {@code k2} is also of type {@code K}. Using an {@code
* EntryTransformer} key type for which this may not hold, such as {@code
* ArrayList}, may risk a {@code ClassCastException} when calling methods on
* the transformed multimap.
*
* @since 7.0
*/
public static <K, V1, V2> Multimap<K, V2> transformEntries(
Multimap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
return new TransformedEntriesMultimap<K, V1, V2>(fromMap, transformer);
}
private static class TransformedEntriesMultimap<K, V1, V2>
extends AbstractMultimap<K, V2> {
final Multimap<K, V1> fromMultimap;
final EntryTransformer<? super K, ? super V1, V2> transformer;
TransformedEntriesMultimap(Multimap<K, V1> fromMultimap,
final EntryTransformer<? super K, ? super V1, V2> transformer) {
this.fromMultimap = checkNotNull(fromMultimap);
this.transformer = checkNotNull(transformer);
}
Collection<V2> transform(K key, Collection<V1> values) {
Function<? super V1, V2> function =
Maps.asValueToValueFunction(transformer, key);
if (values instanceof List) {
return Lists.transform((List<V1>) values, function);
} else {
return Collections2.transform(values, function);
}
}
@Override
Map<K, Collection<V2>> createAsMap() {
return Maps.transformEntries(fromMultimap.asMap(),
new EntryTransformer<K, Collection<V1>, Collection<V2>>() {
@Override public Collection<V2> transformEntry(
K key, Collection<V1> value) {
return transform(key, value);
}
});
}
@Override public void clear() {
fromMultimap.clear();
}
@Override public boolean containsKey(Object key) {
return fromMultimap.containsKey(key);
}
@Override
Iterator<Entry<K, V2>> entryIterator() {
return Iterators.transform(fromMultimap.entries().iterator(),
Maps.<K, V1, V2>asEntryToEntryFunction(transformer));
}
@Override public Collection<V2> get(final K key) {
return transform(key, fromMultimap.get(key));
}
@Override public boolean isEmpty() {
return fromMultimap.isEmpty();
}
@Override public Set<K> keySet() {
return fromMultimap.keySet();
}
@Override public Multiset<K> keys() {
return fromMultimap.keys();
}
@Override public boolean put(K key, V2 value) {
throw new UnsupportedOperationException();
}
@Override public boolean putAll(K key, Iterable<? extends V2> values) {
throw new UnsupportedOperationException();
}
@Override public boolean putAll(
Multimap<? extends K, ? extends V2> multimap) {
throw new UnsupportedOperationException();
}
@SuppressWarnings("unchecked")
@Override public boolean remove(Object key, Object value) {
return get((K) key).remove(value);
}
@SuppressWarnings("unchecked")
@Override public Collection<V2> removeAll(Object key) {
return transform((K) key, fromMultimap.removeAll(key));
}
@Override public Collection<V2> replaceValues(
K key, Iterable<? extends V2> values) {
throw new UnsupportedOperationException();
}
@Override public int size() {
return fromMultimap.size();
}
@Override
Collection<V2> createValues() {
return Collections2.transform(
fromMultimap.entries(), Maps.<K, V1, V2>asEntryToValueFunction(transformer));
}
}
/**
* Returns a view of a {@code ListMultimap} where each value is transformed by
* a function. All other properties of the multimap, such as iteration order,
* are left intact. For example, the code: <pre> {@code
*
* ListMultimap<String, Integer> multimap
* = ImmutableListMultimap.of("a", 4, "a", 16, "b", 9);
* Function<Integer, Double> sqrt =
* new Function<Integer, Double>() {
* public Double apply(Integer in) {
* return Math.sqrt((int) in);
* }
* };
* ListMultimap<String, Double> transformed = Multimaps.transformValues(map,
* sqrt);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {a=[2.0, 4.0], b=[3.0]}}.
*
* <p>Changes in the underlying multimap are reflected in this view.
* Conversely, this view supports removal operations, and these are reflected
* in the underlying multimap.
*
* <p>It's acceptable for the underlying multimap to contain null keys, and
* even null values provided that the function is capable of accepting null
* input. The transformed multimap might contain null values, if the function
* sometimes gives a null result.
*
* <p>The returned multimap is not thread-safe or serializable, even if the
* underlying multimap is.
*
* <p>The function is applied lazily, invoked when needed. This is necessary
* for the returned multimap to be a view, but it means that the function will
* be applied many times for bulk operations like
* {@link Multimap#containsValue} and {@code Multimap.toString()}. For this to
* perform well, {@code function} should be fast. To avoid lazy evaluation
* when the returned multimap doesn't need to be a view, copy the returned
* multimap into a new multimap of your choosing.
*
* @since 7.0
*/
public static <K, V1, V2> ListMultimap<K, V2> transformValues(
ListMultimap<K, V1> fromMultimap,
final Function<? super V1, V2> function) {
checkNotNull(function);
EntryTransformer<K, V1, V2> transformer = Maps.asEntryTransformer(function);
return transformEntries(fromMultimap, transformer);
}
/**
* Returns a view of a {@code ListMultimap} whose values are derived from the
* original multimap's entries. In contrast to
* {@link #transformValues(ListMultimap, Function)}, this method's
* entry-transformation logic may depend on the key as well as the value.
*
* <p>All other properties of the transformed multimap, such as iteration
* order, are left intact. For example, the code: <pre> {@code
*
* Multimap<String, Integer> multimap =
* ImmutableMultimap.of("a", 1, "a", 4, "b", 6);
* EntryTransformer<String, Integer, String> transformer =
* new EntryTransformer<String, Integer, String>() {
* public String transformEntry(String key, Integer value) {
* return key + value;
* }
* };
* Multimap<String, String> transformed =
* Multimaps.transformEntries(multimap, transformer);
* System.out.println(transformed);}</pre>
*
* ... prints {@code {"a"=["a1", "a4"], "b"=["b6"]}}.
*
* <p>Changes in the underlying multimap are reflected in this view.
* Conversely, this view supports removal operations, and these are reflected
* in the underlying multimap.
*
* <p>It's acceptable for the underlying multimap to contain null keys and
* null values provided that the transformer is capable of accepting null
* inputs. The transformed multimap might contain null values if the
* transformer sometimes gives a null result.
*
* <p>The returned multimap is not thread-safe or serializable, even if the
* underlying multimap is.
*
* <p>The transformer is applied lazily, invoked when needed. This is
* necessary for the returned multimap to be a view, but it means that the
* transformer will be applied many times for bulk operations like {@link
* Multimap#containsValue} and {@link Object#toString}. For this to perform
* well, {@code transformer} should be fast. To avoid lazy evaluation when the
* returned multimap doesn't need to be a view, copy the returned multimap
* into a new multimap of your choosing.
*
* <p><b>Warning:</b> This method assumes that for any instance {@code k} of
* {@code EntryTransformer} key type {@code K}, {@code k.equals(k2)} implies
* that {@code k2} is also of type {@code K}. Using an {@code
* EntryTransformer} key type for which this may not hold, such as {@code
* ArrayList}, may risk a {@code ClassCastException} when calling methods on
* the transformed multimap.
*
* @since 7.0
*/
public static <K, V1, V2> ListMultimap<K, V2> transformEntries(
ListMultimap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
return new TransformedEntriesListMultimap<K, V1, V2>(fromMap, transformer);
}
private static final class TransformedEntriesListMultimap<K, V1, V2>
extends TransformedEntriesMultimap<K, V1, V2>
implements ListMultimap<K, V2> {
TransformedEntriesListMultimap(ListMultimap<K, V1> fromMultimap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
super(fromMultimap, transformer);
}
@Override List<V2> transform(K key, Collection<V1> values) {
return Lists.transform((List<V1>) values, Maps.asValueToValueFunction(transformer, key));
}
@Override public List<V2> get(K key) {
return transform(key, fromMultimap.get(key));
}
@SuppressWarnings("unchecked")
@Override public List<V2> removeAll(Object key) {
return transform((K) key, fromMultimap.removeAll(key));
}
@Override public List<V2> replaceValues(
K key, Iterable<? extends V2> values) {
throw new UnsupportedOperationException();
}
}
/**
* Creates an index {@code ImmutableListMultimap} that contains the results of
* applying a specified function to each item in an {@code Iterable} of
* values. Each value will be stored as a value in the resulting multimap,
* yielding a multimap with the same size as the input iterable. The key used
* to store that value in the multimap will be the result of calling the
* function on that value. The resulting multimap is created as an immutable
* snapshot. In the returned multimap, keys appear in the order they are first
* encountered, and the values corresponding to each key appear in the same
* order as they are encountered.
*
* <p>For example, <pre> {@code
*
* List<String> badGuys =
* Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
* Function<String, Integer> stringLengthFunction = ...;
* Multimap<Integer, String> index =
* Multimaps.index(badGuys, stringLengthFunction);
* System.out.println(index);}</pre>
*
* <p>prints <pre> {@code
*
* {4=[Inky], 6=[Blinky], 5=[Pinky, Pinky, Clyde]}}</pre>
*
* <p>The returned multimap is serializable if its keys and values are all
* serializable.
*
* @param values the values to use when constructing the {@code
* ImmutableListMultimap}
* @param keyFunction the function used to produce the key for each value
* @return {@code ImmutableListMultimap} mapping the result of evaluating the
* function {@code keyFunction} on each value in the input collection to
* that value
* @throws NullPointerException if any of the following cases is true:
* <ul>
* <li>{@code values} is null
* <li>{@code keyFunction} is null
* <li>An element in {@code values} is null
* <li>{@code keyFunction} returns {@code null} for any element of {@code
* values}
* </ul>
*/
public static <K, V> ImmutableListMultimap<K, V> index(
Iterable<V> values, Function<? super V, K> keyFunction) {
return index(values.iterator(), keyFunction);
}
/**
* Creates an index {@code ImmutableListMultimap} that contains the results of
* applying a specified function to each item in an {@code Iterator} of
* values. Each value will be stored as a value in the resulting multimap,
* yielding a multimap with the same size as the input iterator. The key used
* to store that value in the multimap will be the result of calling the
* function on that value. The resulting multimap is created as an immutable
* snapshot. In the returned multimap, keys appear in the order they are first
* encountered, and the values corresponding to each key appear in the same
* order as they are encountered.
*
* <p>For example, <pre> {@code
*
* List<String> badGuys =
* Arrays.asList("Inky", "Blinky", "Pinky", "Pinky", "Clyde");
* Function<String, Integer> stringLengthFunction = ...;
* Multimap<Integer, String> index =
* Multimaps.index(badGuys.iterator(), stringLengthFunction);
* System.out.println(index);}</pre>
*
* <p>prints <pre> {@code
*
* {4=[Inky], 6=[Blinky], 5=[Pinky, Pinky, Clyde]}}</pre>
*
* <p>The returned multimap is serializable if its keys and values are all
* serializable.
*
* @param values the values to use when constructing the {@code
* ImmutableListMultimap}
* @param keyFunction the function used to produce the key for each value
* @return {@code ImmutableListMultimap} mapping the result of evaluating the
* function {@code keyFunction} on each value in the input collection to
* that value
* @throws NullPointerException if any of the following cases is true:
* <ul>
* <li>{@code values} is null
* <li>{@code keyFunction} is null
* <li>An element in {@code values} is null
* <li>{@code keyFunction} returns {@code null} for any element of {@code
* values}
* </ul>
* @since 10.0
*/
public static <K, V> ImmutableListMultimap<K, V> index(
Iterator<V> values, Function<? super V, K> keyFunction) {
checkNotNull(keyFunction);
ImmutableListMultimap.Builder<K, V> builder
= ImmutableListMultimap.builder();
while (values.hasNext()) {
V value = values.next();
checkNotNull(value, values);
builder.put(keyFunction.apply(value), value);
}
return builder.build();
}
static class Keys<K, V> extends AbstractMultiset<K> {
final Multimap<K, V> multimap;
Keys(Multimap<K, V> multimap) {
this.multimap = multimap;
}
@Override Iterator<Multiset.Entry<K>> entryIterator() {
return new TransformedIterator<Map.Entry<K, Collection<V>>, Multiset.Entry<K>>(
multimap.asMap().entrySet().iterator()) {
@Override
Multiset.Entry<K> transform(
final Map.Entry<K, Collection<V>> backingEntry) {
return new Multisets.AbstractEntry<K>() {
@Override
public K getElement() {
return backingEntry.getKey();
}
@Override
public int getCount() {
return backingEntry.getValue().size();
}
};
}
};
}
@Override int distinctElements() {
return multimap.asMap().size();
}
@Override Set<Multiset.Entry<K>> createEntrySet() {
return new KeysEntrySet();
}
class KeysEntrySet extends Multisets.EntrySet<K> {
@Override Multiset<K> multiset() {
return Keys.this;
}
@Override public Iterator<Multiset.Entry<K>> iterator() {
return entryIterator();
}
@Override public int size() {
return distinctElements();
}
@Override public boolean isEmpty() {
return multimap.isEmpty();
}
@Override public boolean contains(@Nullable Object o) {
if (o instanceof Multiset.Entry) {
Multiset.Entry<?> entry = (Multiset.Entry<?>) o;
Collection<V> collection = multimap.asMap().get(entry.getElement());
return collection != null && collection.size() == entry.getCount();
}
return false;
}
@Override public boolean remove(@Nullable Object o) {
if (o instanceof Multiset.Entry) {
Multiset.Entry<?> entry = (Multiset.Entry<?>) o;
Collection<V> collection = multimap.asMap().get(entry.getElement());
if (collection != null && collection.size() == entry.getCount()) {
collection.clear();
return true;
}
}
return false;
}
}
@Override public boolean contains(@Nullable Object element) {
return multimap.containsKey(element);
}
@Override public Iterator<K> iterator() {
return Maps.keyIterator(multimap.entries().iterator());
}
@Override public int count(@Nullable Object element) {
Collection<V> values = Maps.safeGet(multimap.asMap(), element);
return (values == null) ? 0 : values.size();
}
@Override public int remove(@Nullable Object element, int occurrences) {
checkNonnegative(occurrences, "occurrences");
if (occurrences == 0) {
return count(element);
}
Collection<V> values = Maps.safeGet(multimap.asMap(), element);
if (values == null) {
return 0;
}
int oldCount = values.size();
if (occurrences >= oldCount) {
values.clear();
} else {
Iterator<V> iterator = values.iterator();
for (int i = 0; i < occurrences; i++) {
iterator.next();
iterator.remove();
}
}
return oldCount;
}
@Override public void clear() {
multimap.clear();
}
@Override public Set<K> elementSet() {
return multimap.keySet();
}
}
/**
* A skeleton implementation of {@link Multimap#entries()}.
*/
abstract static class Entries<K, V> extends
AbstractCollection<Map.Entry<K, V>> {
abstract Multimap<K, V> multimap();
@Override public int size() {
return multimap().size();
}
@Override public boolean contains(@Nullable Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
return multimap().containsEntry(entry.getKey(), entry.getValue());
}
return false;
}
@Override public boolean remove(@Nullable Object o) {
if (o instanceof Map.Entry) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
return multimap().remove(entry.getKey(), entry.getValue());
}
return false;
}
@Override public void clear() {
multimap().clear();
}
}
/**
* A skeleton implementation of {@link Multimap#asMap()}.
*/
static final class AsMap<K, V> extends
Maps.ImprovedAbstractMap<K, Collection<V>> {
private final Multimap<K, V> multimap;
AsMap(Multimap<K, V> multimap) {
this.multimap = checkNotNull(multimap);
}
@Override public int size() {
return multimap.keySet().size();
}
@Override protected Set<Entry<K, Collection<V>>> createEntrySet() {
return new EntrySet();
}
void removeValuesForKey(Object key) {
multimap.keySet().remove(key);
}
class EntrySet extends Maps.EntrySet<K, Collection<V>> {
@Override Map<K, Collection<V>> map() {
return AsMap.this;
}
@Override public Iterator<Entry<K, Collection<V>>> iterator() {
return Maps.asMapEntryIterator(multimap.keySet(), new Function<K, Collection<V>>() {
@Override
public Collection<V> apply(K key) {
return multimap.get(key);
}
});
}
@Override public boolean remove(Object o) {
if (!contains(o)) {
return false;
}
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
removeValuesForKey(entry.getKey());
return true;
}
}
@SuppressWarnings("unchecked")
@Override public Collection<V> get(Object key) {
return containsKey(key) ? multimap.get((K) key) : null;
}
@Override public Collection<V> remove(Object key) {
return containsKey(key) ? multimap.removeAll(key) : null;
}
@Override public Set<K> keySet() {
return multimap.keySet();
}
@Override public boolean isEmpty() {
return multimap.isEmpty();
}
@Override public boolean containsKey(Object key) {
return multimap.containsKey(key);
}
@Override public void clear() {
multimap.clear();
}
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} whose keys
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a key that doesn't satisfy the predicate, the
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such
* as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
* with equals.
*
* @since 11.0
*/
public static <K, V> Multimap<K, V> filterKeys(
Multimap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
if (unfiltered instanceof SetMultimap) {
return filterKeys((SetMultimap<K, V>) unfiltered, keyPredicate);
} else if (unfiltered instanceof ListMultimap) {
return filterKeys((ListMultimap<K, V>) unfiltered, keyPredicate);
} else if (unfiltered instanceof FilteredKeyMultimap) {
FilteredKeyMultimap<K, V> prev = (FilteredKeyMultimap<K, V>) unfiltered;
return new FilteredKeyMultimap<K, V>(prev.unfiltered,
Predicates.and(prev.keyPredicate, keyPredicate));
} else if (unfiltered instanceof FilteredMultimap) {
FilteredMultimap<K, V> prev = (FilteredMultimap<K, V>) unfiltered;
return filterFiltered(prev, Maps.<K>keyPredicateOnEntries(keyPredicate));
} else {
return new FilteredKeyMultimap<K, V>(unfiltered, keyPredicate);
}
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} whose keys
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a key that doesn't satisfy the predicate, the
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such
* as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
* with equals.
*
* @since 14.0
*/
public static <K, V> SetMultimap<K, V> filterKeys(
SetMultimap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
if (unfiltered instanceof FilteredKeySetMultimap) {
FilteredKeySetMultimap<K, V> prev = (FilteredKeySetMultimap<K, V>) unfiltered;
return new FilteredKeySetMultimap<K, V>(prev.unfiltered(),
Predicates.and(prev.keyPredicate, keyPredicate));
} else if (unfiltered instanceof FilteredSetMultimap) {
FilteredSetMultimap<K, V> prev = (FilteredSetMultimap<K, V>) unfiltered;
return filterFiltered(prev, Maps.<K>keyPredicateOnEntries(keyPredicate));
} else {
return new FilteredKeySetMultimap<K, V>(unfiltered, keyPredicate);
}
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} whose keys
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a key that doesn't satisfy the predicate, the
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code keyPredicate} must be <i>consistent with equals</i>,
* as documented at {@link Predicate#apply}. Do not provide a predicate such
* as {@code Predicates.instanceOf(ArrayList.class)}, which is inconsistent
* with equals.
*
* @since 14.0
*/
public static <K, V> ListMultimap<K, V> filterKeys(
ListMultimap<K, V> unfiltered, final Predicate<? super K> keyPredicate) {
if (unfiltered instanceof FilteredKeyListMultimap) {
FilteredKeyListMultimap<K, V> prev = (FilteredKeyListMultimap<K, V>) unfiltered;
return new FilteredKeyListMultimap<K, V>(prev.unfiltered(),
Predicates.and(prev.keyPredicate, keyPredicate));
} else {
return new FilteredKeyListMultimap<K, V>(unfiltered, keyPredicate);
}
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} whose values
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a value that doesn't satisfy the predicate, the
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose value satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code valuePredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*
* @since 11.0
*/
public static <K, V> Multimap<K, V> filterValues(
Multimap<K, V> unfiltered, final Predicate<? super V> valuePredicate) {
return filterEntries(unfiltered, Maps.<V>valuePredicateOnEntries(valuePredicate));
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} whose values
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a value that doesn't satisfy the predicate, the
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose value satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code valuePredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}. Do not provide a
* predicate such as {@code Predicates.instanceOf(ArrayList.class)}, which is
* inconsistent with equals.
*
* @since 14.0
*/
public static <K, V> SetMultimap<K, V> filterValues(
SetMultimap<K, V> unfiltered, final Predicate<? super V> valuePredicate) {
return filterEntries(unfiltered, Maps.<V>valuePredicateOnEntries(valuePredicate));
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} that
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a key/value pair that doesn't satisfy the predicate,
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}.
*
* @since 11.0
*/
public static <K, V> Multimap<K, V> filterEntries(
Multimap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate) {
checkNotNull(entryPredicate);
if (unfiltered instanceof SetMultimap) {
return filterEntries((SetMultimap<K, V>) unfiltered, entryPredicate);
}
return (unfiltered instanceof FilteredMultimap)
? filterFiltered((FilteredMultimap<K, V>) unfiltered, entryPredicate)
: new FilteredEntryMultimap<K, V>(checkNotNull(unfiltered), entryPredicate);
}
/**
* Returns a multimap containing the mappings in {@code unfiltered} that
* satisfy a predicate. The returned multimap is a live view of
* {@code unfiltered}; changes to one affect the other.
*
* <p>The resulting multimap's views have iterators that don't support
* {@code remove()}, but all other methods are supported by the multimap and
* its views. When adding a key/value pair that doesn't satisfy the predicate,
* multimap's {@code put()}, {@code putAll()}, and {@code replaceValues()}
* methods throw an {@link IllegalArgumentException}.
*
* <p>When methods such as {@code removeAll()} and {@code clear()} are called on
* the filtered multimap or its views, only mappings whose keys satisfy the
* filter will be removed from the underlying multimap.
*
* <p>The returned multimap isn't threadsafe or serializable, even if
* {@code unfiltered} is.
*
* <p>Many of the filtered multimap's methods, such as {@code size()}, iterate
* across every key/value mapping in the underlying multimap and determine
* which satisfy the filter. When a live view is <i>not</i> needed, it may be
* faster to copy the filtered multimap and use the copy.
*
* <p><b>Warning:</b> {@code entryPredicate} must be <i>consistent with
* equals</i>, as documented at {@link Predicate#apply}.
*
* @since 14.0
*/
public static <K, V> SetMultimap<K, V> filterEntries(
SetMultimap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate) {
checkNotNull(entryPredicate);
return (unfiltered instanceof FilteredSetMultimap)
? filterFiltered((FilteredSetMultimap<K, V>) unfiltered, entryPredicate)
: new FilteredEntrySetMultimap<K, V>(checkNotNull(unfiltered), entryPredicate);
}
/**
* Support removal operations when filtering a filtered multimap. Since a
* filtered multimap has iterators that don't support remove, passing one to
* the FilteredEntryMultimap constructor would lead to a multimap whose removal
* operations would fail. This method combines the predicates to avoid that
* problem.
*/
private static <K, V> Multimap<K, V> filterFiltered(FilteredMultimap<K, V> multimap,
Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate
= Predicates.and(multimap.entryPredicate(), entryPredicate);
return new FilteredEntryMultimap<K, V>(multimap.unfiltered(), predicate);
}
/**
* Support removal operations when filtering a filtered multimap. Since a filtered multimap has
* iterators that don't support remove, passing one to the FilteredEntryMultimap constructor would
* lead to a multimap whose removal operations would fail. This method combines the predicates to
* avoid that problem.
*/
private static <K, V> SetMultimap<K, V> filterFiltered(
FilteredSetMultimap<K, V> multimap,
Predicate<? super Entry<K, V>> entryPredicate) {
Predicate<Entry<K, V>> predicate
= Predicates.and(multimap.entryPredicate(), entryPredicate);
return new FilteredEntrySetMultimap<K, V>(multimap.unfiltered(), predicate);
}
static boolean equalsImpl(Multimap<?, ?> multimap, @Nullable Object object) {
if (object == multimap) {
return true;
}
if (object instanceof Multimap) {
Multimap<?, ?> that = (Multimap<?, ?>) object;
return multimap.asMap().equals(that.asMap());
}
return false;
}
// TODO(jlevy): Create methods that filter a SortedSetMultimap.
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/Multimaps.java | Java | asf20 | 74,993 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkPositionIndexes;
import com.google.common.annotations.GwtCompatible;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* Static utility methods pertaining to object arrays.
*
* @author Kevin Bourrillion
* @since 2.0 (imported from Google Collections Library)
*/
@GwtCompatible(emulated = true)
public final class ObjectArrays {
static final Object[] EMPTY_ARRAY = new Object[0];
private ObjectArrays() {}
/**
* Returns a new array of the given length with the same type as a reference
* array.
*
* @param reference any array of the desired type
* @param length the length of the new array
*/
public static <T> T[] newArray(T[] reference, int length) {
return Platform.newArray(reference, length);
}
/**
* Returns a new array that prepends {@code element} to {@code array}.
*
* @param element the element to prepend to the front of {@code array}
* @param array the array of elements to append
* @return an array whose size is one larger than {@code array}, with
* {@code element} occupying the first position, and the
* elements of {@code array} occupying the remaining elements.
*/
public static <T> T[] concat(@Nullable T element, T[] array) {
T[] result = newArray(array, array.length + 1);
result[0] = element;
System.arraycopy(array, 0, result, 1, array.length);
return result;
}
/**
* Returns a new array that appends {@code element} to {@code array}.
*
* @param array the array of elements to prepend
* @param element the element to append to the end
* @return an array whose size is one larger than {@code array}, with
* the same contents as {@code array}, plus {@code element} occupying the
* last position.
*/
public static <T> T[] concat(T[] array, @Nullable T element) {
T[] result = arraysCopyOf(array, array.length + 1);
result[array.length] = element;
return result;
}
/** GWT safe version of Arrays.copyOf. */
static <T> T[] arraysCopyOf(T[] original, int newLength) {
T[] copy = newArray(original, newLength);
System.arraycopy(
original, 0, copy, 0, Math.min(original.length, newLength));
return copy;
}
/**
* Returns an array containing all of the elements in the specified
* collection; the runtime type of the returned array is that of the specified
* array. If the collection fits in the specified array, it is returned
* therein. Otherwise, a new array is allocated with the runtime type of the
* specified array and the size of the specified collection.
*
* <p>If the collection fits in the specified array with room to spare (i.e.,
* the array has more elements than the collection), the element in the array
* immediately following the end of the collection is set to {@code null}.
* This is useful in determining the length of the collection <i>only</i> if
* the caller knows that the collection does not contain any null elements.
*
* <p>This method returns the elements in the order they are returned by the
* collection's iterator.
*
* <p>TODO(kevinb): support concurrently modified collections?
*
* @param c the collection for which to return an array of elements
* @param array the array in which to place the collection elements
* @throws ArrayStoreException if the runtime type of the specified array is
* not a supertype of the runtime type of every element in the specified
* collection
*/
static <T> T[] toArrayImpl(Collection<?> c, T[] array) {
int size = c.size();
if (array.length < size) {
array = newArray(array, size);
}
fillArray(c, array);
if (array.length > size) {
array[size] = null;
}
return array;
}
/**
* Implementation of {@link Collection#toArray(Object[])} for collections backed by an object
* array. the runtime type of the returned array is that of the specified array. If the collection
* fits in the specified array, it is returned therein. Otherwise, a new array is allocated with
* the runtime type of the specified array and the size of the specified collection.
*
* <p>If the collection fits in the specified array with room to spare (i.e., the array has more
* elements than the collection), the element in the array immediately following the end of the
* collection is set to {@code null}. This is useful in determining the length of the collection
* <i>only</i> if the caller knows that the collection does not contain any null elements.
*/
static <T> T[] toArrayImpl(Object[] src, int offset, int len, T[] dst) {
checkPositionIndexes(offset, offset + len, src.length);
if (dst.length < len) {
dst = newArray(dst, len);
} else if (dst.length > len) {
dst[len] = null;
}
System.arraycopy(src, offset, dst, 0, len);
return dst;
}
/**
* Returns an array containing all of the elements in the specified
* collection. This method returns the elements in the order they are returned
* by the collection's iterator. The returned array is "safe" in that no
* references to it are maintained by the collection. The caller is thus free
* to modify the returned array.
*
* <p>This method assumes that the collection size doesn't change while the
* method is running.
*
* <p>TODO(kevinb): support concurrently modified collections?
*
* @param c the collection for which to return an array of elements
*/
static Object[] toArrayImpl(Collection<?> c) {
return fillArray(c, new Object[c.size()]);
}
/**
* Returns a copy of the specified subrange of the specified array that is literally an Object[],
* and not e.g. a {@code String[]}.
*/
static Object[] copyAsObjectArray(Object[] elements, int offset, int length) {
checkPositionIndexes(offset, offset + length, elements.length);
if (length == 0) {
return EMPTY_ARRAY;
}
Object[] result = new Object[length];
System.arraycopy(elements, offset, result, 0, length);
return result;
}
private static Object[] fillArray(Iterable<?> elements, Object[] array) {
int i = 0;
for (Object element : elements) {
array[i++] = element;
}
return array;
}
/**
* Swaps {@code array[i]} with {@code array[j]}.
*/
static void swap(Object[] array, int i, int j) {
Object temp = array[i];
array[i] = array[j];
array[j] = temp;
}
static Object[] checkElementsNotNull(Object... array) {
return checkElementsNotNull(array, array.length);
}
static Object[] checkElementsNotNull(Object[] array, int length) {
for (int i = 0; i < length; i++) {
checkElementNotNull(array[i], i);
}
return array;
}
// We do this instead of Preconditions.checkNotNull to save boxing and array
// creation cost.
static Object checkElementNotNull(Object element, int index) {
if (element == null) {
throw new NullPointerException("at index " + index);
}
return element;
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/ObjectArrays.java | Java | asf20 | 7,722 |
/*
* Copyright (C) 2010 The Guava Authors
*
* 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.common.collect;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Function;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
/**
* A class exactly like {@link MapMaker}, except restricted in the types of maps it can build.
* For the most part, you should probably just ignore the existence of this class.
*
* @param <K0> the base type for all key types of maps built by this map maker
* @param <V0> the base type for all value types of maps built by this map maker
* @author Kevin Bourrillion
* @since 7.0
* @deprecated This class existed only to support the generic paramterization necessary for the
* caching functionality in {@code MapMaker}. That functionality has been moved to {@link
* com.google.common.cache.CacheBuilder}, which is a properly generified class and thus needs no
* "Generic" equivalent; simple use {@code CacheBuilder} naturally. For general migration
* instructions, see the <a
* href="http://code.google.com/p/guava-libraries/wiki/MapMakerMigration">MapMaker Migration
* Guide</a>.
*/
@Beta
@Deprecated
@GwtCompatible(emulated = true)
abstract class GenericMapMaker<K0, V0> {
// Set by MapMaker, but sits in this class to preserve the type relationship
// No subclasses but our own
GenericMapMaker() {}
/**
* See {@link MapMaker#initialCapacity}.
*/
public abstract GenericMapMaker<K0, V0> initialCapacity(int initialCapacity);
/**
* See {@link MapMaker#maximumSize}.
*/
abstract GenericMapMaker<K0, V0> maximumSize(int maximumSize);
/**
* See {@link MapMaker#concurrencyLevel}.
*/
public abstract GenericMapMaker<K0, V0> concurrencyLevel(int concurrencyLevel);
/**
* See {@link MapMaker#expireAfterWrite}.
*/
abstract GenericMapMaker<K0, V0> expireAfterWrite(long duration, TimeUnit unit);
/*
* Note that MapMaker's removalListener() is not here, because once you're interacting with a
* GenericMapMaker you've already called that, and shouldn't be calling it again.
*/
/**
* See {@link MapMaker#makeMap}.
*/
public abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeMap();
/**
* See {@link MapMaker#makeComputingMap}.
*/
@Deprecated
abstract <K extends K0, V extends V0> ConcurrentMap<K, V> makeComputingMap(
Function<? super K, ? extends V> computingFunction);
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/GenericMapMaker.java | Java | asf20 | 3,071 |
/*
* Copyright (C) 2009 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Iterators;
import com.google.common.collect.UnmodifiableIterator;
/**
* GWT emulation of {@link SingletonImmutableSet}.
*
* @author Hayward Chan
*/
final class SingletonImmutableSet<E> extends ImmutableSet<E> {
// This reference is used both by the custom field serializer, and by the
// GWT compiler to infer the elements of the lists that needs to be
// serialized.
//
// Although this reference is non-final, it doesn't change after set creation.
E element;
SingletonImmutableSet(E element) {
this.element = checkNotNull(element);
}
@Override
public int size() {
return 1;
}
@Override
public UnmodifiableIterator<E> iterator() {
return Iterators.singletonIterator(element);
}
@Override
public boolean contains(Object object) {
return element.equals(object);
}
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/SingletonImmutableSet.java | Java | asf20 | 1,562 |
/*
* Copyright (C) 2007 The Guava Authors
*
* 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.common.collect;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.CollectPreconditions.checkNonnegative;
import static com.google.common.collect.CollectPreconditions.checkRemove;
import com.google.common.annotations.GwtCompatible;
import com.google.common.primitives.Ints;
import java.io.Serializable;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
/**
* Basic implementation of {@code Multiset<E>} backed by an instance of {@code
* Map<E, Count>}.
*
* <p>For serialization to work, the subclass must specify explicit {@code
* readObject} and {@code writeObject} methods.
*
* @author Kevin Bourrillion
*/
@GwtCompatible(emulated = true)
abstract class AbstractMapBasedMultiset<E> extends AbstractMultiset<E>
implements Serializable {
private transient Map<E, Count> backingMap;
/*
* Cache the size for efficiency. Using a long lets us avoid the need for
* overflow checking and ensures that size() will function correctly even if
* the multiset had once been larger than Integer.MAX_VALUE.
*/
private transient long size;
/** Standard constructor. */
protected AbstractMapBasedMultiset(Map<E, Count> backingMap) {
this.backingMap = checkNotNull(backingMap);
this.size = super.size();
}
/** Used during deserialization only. The backing map must be empty. */
void setBackingMap(Map<E, Count> backingMap) {
this.backingMap = backingMap;
}
// Required Implementations
/**
* {@inheritDoc}
*
* <p>Invoking {@link Multiset.Entry#getCount} on an entry in the returned
* set always returns the current count of that element in the multiset, as
* opposed to the count at the time the entry was retrieved.
*/
@Override
public Set<Multiset.Entry<E>> entrySet() {
return super.entrySet();
}
@Override
Iterator<Entry<E>> entryIterator() {
final Iterator<Map.Entry<E, Count>> backingEntries =
backingMap.entrySet().iterator();
return new Iterator<Multiset.Entry<E>>() {
Map.Entry<E, Count> toRemove;
@Override
public boolean hasNext() {
return backingEntries.hasNext();
}
@Override
public Multiset.Entry<E> next() {
final Map.Entry<E, Count> mapEntry = backingEntries.next();
toRemove = mapEntry;
return new Multisets.AbstractEntry<E>() {
@Override
public E getElement() {
return mapEntry.getKey();
}
@Override
public int getCount() {
Count count = mapEntry.getValue();
if (count == null || count.get() == 0) {
Count frequency = backingMap.get(getElement());
if (frequency != null) {
return frequency.get();
}
}
return (count == null) ? 0 : count.get();
}
};
}
@Override
public void remove() {
checkRemove(toRemove != null);
size -= toRemove.getValue().getAndSet(0);
backingEntries.remove();
toRemove = null;
}
};
}
@Override
public void clear() {
for (Count frequency : backingMap.values()) {
frequency.set(0);
}
backingMap.clear();
size = 0L;
}
@Override
int distinctElements() {
return backingMap.size();
}
// Optimizations - Query Operations
@Override public int size() {
return Ints.saturatedCast(size);
}
@Override public Iterator<E> iterator() {
return new MapBasedMultisetIterator();
}
/*
* Not subclassing AbstractMultiset$MultisetIterator because next() needs to
* retrieve the Map.Entry<E, Count> entry, which can then be used for
* a more efficient remove() call.
*/
private class MapBasedMultisetIterator implements Iterator<E> {
final Iterator<Map.Entry<E, Count>> entryIterator;
Map.Entry<E, Count> currentEntry;
int occurrencesLeft;
boolean canRemove;
MapBasedMultisetIterator() {
this.entryIterator = backingMap.entrySet().iterator();
}
@Override
public boolean hasNext() {
return occurrencesLeft > 0 || entryIterator.hasNext();
}
@Override
public E next() {
if (occurrencesLeft == 0) {
currentEntry = entryIterator.next();
occurrencesLeft = currentEntry.getValue().get();
}
occurrencesLeft--;
canRemove = true;
return currentEntry.getKey();
}
@Override
public void remove() {
checkRemove(canRemove);
int frequency = currentEntry.getValue().get();
if (frequency <= 0) {
throw new ConcurrentModificationException();
}
if (currentEntry.getValue().addAndGet(-1) == 0) {
entryIterator.remove();
}
size--;
canRemove = false;
}
}
@Override public int count(@Nullable Object element) {
Count frequency = Maps.safeGet(backingMap, element);
return (frequency == null) ? 0 : frequency.get();
}
// Optional Operations - Modification Operations
/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if the call would result in more than
* {@link Integer#MAX_VALUE} occurrences of {@code element} in this
* multiset.
*/
@Override public int add(@Nullable E element, int occurrences) {
if (occurrences == 0) {
return count(element);
}
checkArgument(
occurrences > 0, "occurrences cannot be negative: %s", occurrences);
Count frequency = backingMap.get(element);
int oldCount;
if (frequency == null) {
oldCount = 0;
backingMap.put(element, new Count(occurrences));
} else {
oldCount = frequency.get();
long newCount = (long) oldCount + (long) occurrences;
checkArgument(newCount <= Integer.MAX_VALUE,
"too many occurrences: %s", newCount);
frequency.getAndAdd(occurrences);
}
size += occurrences;
return oldCount;
}
@Override public int remove(@Nullable Object element, int occurrences) {
if (occurrences == 0) {
return count(element);
}
checkArgument(
occurrences > 0, "occurrences cannot be negative: %s", occurrences);
Count frequency = backingMap.get(element);
if (frequency == null) {
return 0;
}
int oldCount = frequency.get();
int numberRemoved;
if (oldCount > occurrences) {
numberRemoved = occurrences;
} else {
numberRemoved = oldCount;
backingMap.remove(element);
}
frequency.addAndGet(-numberRemoved);
size -= numberRemoved;
return oldCount;
}
// Roughly a 33% performance improvement over AbstractMultiset.setCount().
@Override public int setCount(@Nullable E element, int count) {
checkNonnegative(count, "count");
Count existingCounter;
int oldCount;
if (count == 0) {
existingCounter = backingMap.remove(element);
oldCount = getAndSet(existingCounter, count);
} else {
existingCounter = backingMap.get(element);
oldCount = getAndSet(existingCounter, count);
if (existingCounter == null) {
backingMap.put(element, new Count(count));
}
}
size += (count - oldCount);
return oldCount;
}
private static int getAndSet(Count i, int count) {
if (i == null) {
return 0;
}
return i.getAndSet(count);
}
// Don't allow default serialization.
}
| zzhhhhh-aw4rwer | guava-gwt/src-super/com/google/common/collect/super/com/google/common/collect/AbstractMapBasedMultiset.java | Java | asf20 | 8,157 |