java guava examples
This commit is contained in:
parent
361111b1e6
commit
e491f953a5
@ -65,35 +65,6 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
<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>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -7,28 +7,36 @@ import org.junit.Test;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
public class GuavaCollectionsExamples {
|
public class GuavaCollectionsExamplesTest {
|
||||||
|
|
||||||
|
// tests
|
||||||
|
|
||||||
@SuppressWarnings({ "unused", "unchecked" })
|
|
||||||
@Test
|
@Test
|
||||||
public final void whenCastingAllElementsOfACollectionToSubtype_thenCastIsOK() {
|
public final void whenDowncastingGenerifiedCollectionToNewGenerifiedCollection_thenCastIsOK() {
|
||||||
final class CastFunction<F, T extends F> implements Function<F, T> {
|
final class CastFunction<F, T extends F> implements Function<F, T> {
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
public final T apply(final F from) {
|
public final T apply(final F from) {
|
||||||
return (T) from;
|
return (T) from;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Number> originalList = Lists.newArrayList();
|
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>());
|
final List<Integer> selectedProducts = Lists.transform(originalList, new CastFunction<Number, Integer>());
|
||||||
System.out.println(selectedProducts);
|
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
|
@Test
|
||||||
public final void when_then() {
|
public final void when_then() {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user