java guava examples
This commit is contained in:
		
							parent
							
								
									361111b1e6
								
							
						
					
					
						commit
						e491f953a5
					
				| @ -65,35 +65,6 @@ | ||||
| 				<groupId>org.apache.maven.plugins</groupId> | ||||
| 				<artifactId>maven-surefire-plugin</artifactId> | ||||
| 				<version>${maven-surefire-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<excludes> | ||||
| 						<!-- <exclude>**/*ProductionTest.java</exclude> --> | ||||
| 					</excludes> | ||||
| 					<systemPropertyVariables> | ||||
| 						<!-- <provPersistenceTarget>h2</provPersistenceTarget> --> | ||||
| 					</systemPropertyVariables> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 
 | ||||
| 			<plugin> | ||||
| 				<groupId>org.codehaus.cargo</groupId> | ||||
| 				<artifactId>cargo-maven2-plugin</artifactId> | ||||
| 				<version>${cargo-maven2-plugin.version}</version> | ||||
| 				<configuration> | ||||
| 					<wait>true</wait> | ||||
| 					<container> | ||||
| 						<containerId>jetty8x</containerId> | ||||
| 						<type>embedded</type> | ||||
| 						<systemProperties> | ||||
| 							<!-- <provPersistenceTarget>cargo</provPersistenceTarget> --> | ||||
| 						</systemProperties> | ||||
| 					</container> | ||||
| 					<configuration> | ||||
| 						<properties> | ||||
| 							<cargo.servlet.port>8082</cargo.servlet.port> | ||||
| 						</properties> | ||||
| 					</configuration> | ||||
| 				</configuration> | ||||
| 			</plugin> | ||||
| 
 | ||||
| 		</plugins> | ||||
|  | ||||
| @ -7,28 +7,36 @@ import org.junit.Test; | ||||
| import com.google.common.base.Function; | ||||
| import com.google.common.collect.Lists; | ||||
| 
 | ||||
| public class GuavaCollectionsExamples { | ||||
| public class GuavaCollectionsExamplesTest { | ||||
| 
 | ||||
|     // tests | ||||
| 
 | ||||
|     @SuppressWarnings({ "unused", "unchecked" }) | ||||
|     @Test | ||||
|     public final void whenCastingAllElementsOfACollectionToSubtype_thenCastIsOK() { | ||||
|     public final void whenDowncastingGenerifiedCollectionToNewGenerifiedCollection_thenCastIsOK() { | ||||
|         final class CastFunction<F, T extends F> implements Function<F, T> { | ||||
|             @Override | ||||
|             @SuppressWarnings("unchecked") | ||||
|             @Override | ||||
|             public final T apply(final F from) { | ||||
|                 return (T) from; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         final List<Number> originalList = Lists.newArrayList(); | ||||
|         final List<Integer> selectedProductsQuick = (List<Integer>) (List<? extends Number>) originalList; | ||||
|         final List<Integer> selectedProducts = Lists.transform(originalList, new CastFunction<Number, Integer>()); | ||||
|         System.out.println(selectedProducts); | ||||
|     } | ||||
| 
 | ||||
|     @SuppressWarnings({ "unchecked" }) | ||||
|     @Test | ||||
|     public final void whenDowncastingGenerifiedCollectionToNewGenerifiedCollection_thenCastIsOK2() { | ||||
|         final List<Number> originalList = Lists.newArrayList(); | ||||
|         final List<Integer> selectedProducts = (List<Integer>) (List<? extends Number>) originalList; | ||||
|         System.out.println(selectedProducts); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public final void when_then() { | ||||
| 
 | ||||
|         // | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user