Coverage Summary for Class: ListGenerators (com.google.common.collect.testing.google)
| Class | Method, % | Line, % |
|---|---|---|
| ListGenerators | 0% (0/1) | 0% (0/1) |
| ListGenerators$BuilderAddAllListGenerator | 0% (0/2) | 0% (0/2) |
| ListGenerators$BuilderAddListGenerator | 0% (0/2) | 0% (0/5) |
| ListGenerators$BuilderReversedListGenerator | 0% (0/2) | 0% (0/4) |
| ListGenerators$CharactersOfCharSequenceGenerator | 0% (0/2) | 0% (0/5) |
| ListGenerators$CharactersOfStringGenerator | 0% (0/2) | 0% (0/3) |
| ListGenerators$ImmutableListHeadSubListGenerator | 0% (0/2) | 0% (0/6) |
| ListGenerators$ImmutableListMiddleSubListGenerator | 0% (0/2) | 0% (0/8) |
| ListGenerators$ImmutableListOfGenerator | 0% (0/2) | 0% (0/2) |
| ListGenerators$ImmutableListTailSubListGenerator | 0% (0/2) | 0% (0/6) |
| ListGenerators$TestUnhashableListGenerator | 0% (0/1) | 0% (0/1) |
| ListGenerators$UnhashableElementsImmutableListGenerator | 0% (0/2) | 0% (0/2) |
| Total | 0% (0/22) | 0% (0/45) |
1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.collect.testing.google; 18 19 import static java.util.Arrays.asList; 20 21 import com.google.common.annotations.GwtCompatible; 22 import com.google.common.collect.ImmutableList; 23 import com.google.common.collect.Lists; 24 import com.google.common.collect.testing.TestCharacterListGenerator; 25 import com.google.common.collect.testing.TestListGenerator; 26 import com.google.common.collect.testing.TestStringListGenerator; 27 import com.google.common.collect.testing.TestUnhashableCollectionGenerator; 28 import com.google.common.collect.testing.UnhashableObject; 29 import com.google.common.primitives.Chars; 30 import java.util.Arrays; 31 import java.util.Collections; 32 import java.util.List; 33 34 /** 35 * Common generators of different types of lists. 36 * 37 * @author Hayward Chan 38 */ 39 @GwtCompatible 40 public final class ListGenerators { 41 42 private ListGenerators() {} 43 44 public static class ImmutableListOfGenerator extends TestStringListGenerator { 45 @Override 46 protected List<String> create(String[] elements) { 47 return ImmutableList.copyOf(elements); 48 } 49 } 50 51 public static class BuilderAddListGenerator extends TestStringListGenerator { 52 @Override 53 protected List<String> create(String[] elements) { 54 ImmutableList.Builder<String> builder = ImmutableList.<String>builder(); 55 for (String element : elements) { 56 builder.add(element); 57 } 58 return builder.build(); 59 } 60 } 61 62 public static class BuilderAddAllListGenerator extends TestStringListGenerator { 63 @Override 64 protected List<String> create(String[] elements) { 65 return ImmutableList.<String>builder().addAll(asList(elements)).build(); 66 } 67 } 68 69 public static class BuilderReversedListGenerator extends TestStringListGenerator { 70 @Override 71 protected List<String> create(String[] elements) { 72 List<String> list = asList(elements); 73 Collections.reverse(list); 74 return ImmutableList.copyOf(list).reverse(); 75 } 76 } 77 78 public static class ImmutableListHeadSubListGenerator extends TestStringListGenerator { 79 @Override 80 protected List<String> create(String[] elements) { 81 String[] suffix = {"f", "g"}; 82 String[] all = new String[elements.length + suffix.length]; 83 System.arraycopy(elements, 0, all, 0, elements.length); 84 System.arraycopy(suffix, 0, all, elements.length, suffix.length); 85 return ImmutableList.copyOf(all).subList(0, elements.length); 86 } 87 } 88 89 public static class ImmutableListTailSubListGenerator extends TestStringListGenerator { 90 @Override 91 protected List<String> create(String[] elements) { 92 String[] prefix = {"f", "g"}; 93 String[] all = new String[elements.length + prefix.length]; 94 System.arraycopy(prefix, 0, all, 0, 2); 95 System.arraycopy(elements, 0, all, 2, elements.length); 96 return ImmutableList.copyOf(all).subList(2, elements.length + 2); 97 } 98 } 99 100 public static class ImmutableListMiddleSubListGenerator extends TestStringListGenerator { 101 @Override 102 protected List<String> create(String[] elements) { 103 String[] prefix = {"f", "g"}; 104 String[] suffix = {"h", "i"}; 105 106 String[] all = new String[2 + elements.length + 2]; 107 System.arraycopy(prefix, 0, all, 0, 2); 108 System.arraycopy(elements, 0, all, 2, elements.length); 109 System.arraycopy(suffix, 0, all, 2 + elements.length, 2); 110 111 return ImmutableList.copyOf(all).subList(2, elements.length + 2); 112 } 113 } 114 115 public static class CharactersOfStringGenerator extends TestCharacterListGenerator { 116 @Override 117 public List<Character> create(Character[] elements) { 118 char[] chars = Chars.toArray(Arrays.asList(elements)); 119 return Lists.charactersOf(String.copyValueOf(chars)); 120 } 121 } 122 123 public static class CharactersOfCharSequenceGenerator extends TestCharacterListGenerator { 124 @Override 125 public List<Character> create(Character[] elements) { 126 char[] chars = Chars.toArray(Arrays.asList(elements)); 127 StringBuilder str = new StringBuilder(); 128 str.append(chars); 129 return Lists.charactersOf(str); 130 } 131 } 132 133 private abstract static class TestUnhashableListGenerator 134 extends TestUnhashableCollectionGenerator<List<UnhashableObject>> 135 implements TestListGenerator<UnhashableObject> {} 136 137 public static class UnhashableElementsImmutableListGenerator extends TestUnhashableListGenerator { 138 @Override 139 public List<UnhashableObject> create(UnhashableObject[] elements) { 140 return ImmutableList.copyOf(elements); 141 } 142 } 143 }