Add out directory
parent
02373f4063
commit
87b0097009
@ -0,0 +1,41 @@
|
|||||||
|
import common.Product;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ArrayListExamples {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Product door = new Product("Wooden Door", 35);
|
||||||
|
Product floorPanel = new Product("Floor Panel", 25);
|
||||||
|
Product window = new Product("Glass Window", 10);
|
||||||
|
|
||||||
|
List<Product> streamProducts = new ArrayList<>();
|
||||||
|
streamProducts.add(door);
|
||||||
|
streamProducts.add(floorPanel);
|
||||||
|
|
||||||
|
System.out.println(streamProducts);
|
||||||
|
|
||||||
|
// Lists auto-resize, with add method
|
||||||
|
streamProducts.add(window);
|
||||||
|
|
||||||
|
System.out.println(streamProducts);
|
||||||
|
|
||||||
|
// We can query for size
|
||||||
|
System.out.println(streamProducts.size());
|
||||||
|
|
||||||
|
// Lists have order, we retrieve elements by index
|
||||||
|
for (int i = 0; i < streamProducts.size(); i++) {
|
||||||
|
// Generic get method
|
||||||
|
Product streamProduct = streamProducts.get(i);
|
||||||
|
System.out.println(streamProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
// can loop over them with a for loop
|
||||||
|
for (Product streamProduct : streamProducts) {
|
||||||
|
System.out.println(streamProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can still add duplicates though
|
||||||
|
streamProducts.add(window);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
import common.Product;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CollectionConcepts {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Product door = new Product("Wooden Door", 35);
|
||||||
|
Product floorPanel = new Product("Floor Panel", 25);
|
||||||
|
Product window = new Product("Glass Window", 10);
|
||||||
|
|
||||||
|
Collection<Product> streamProducts = new ArrayList<>();
|
||||||
|
streamProducts.add(door);
|
||||||
|
streamProducts.add(floorPanel);
|
||||||
|
streamProducts.add(window);
|
||||||
|
|
||||||
|
// Iterating with foreach
|
||||||
|
for (Product streamProduct : streamProducts) {
|
||||||
|
System.out.println(streamProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Broken removal using foreach
|
||||||
|
/*
|
||||||
|
* for (Product product : products) { if (product.getWeight() > 20) {
|
||||||
|
* System.out.println(product); } else { products.remove(product); } }
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Refactor to use iterator to remove products.
|
||||||
|
Iterator<Product> iterator = streamProducts.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
final Product streamProduct = iterator.next();
|
||||||
|
if (streamProduct.getWeight() > 20) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(streamProducts);
|
||||||
|
|
||||||
|
// 4. other methods
|
||||||
|
System.out.println(streamProducts.size());
|
||||||
|
System.out.println(streamProducts.isEmpty());
|
||||||
|
System.out.println(streamProducts.contains(floorPanel));
|
||||||
|
streamProducts.remove(floorPanel);
|
||||||
|
System.out.println(streamProducts.contains(floorPanel));
|
||||||
|
|
||||||
|
// 5. removeAll
|
||||||
|
List<Product> toRemove = new ArrayList<>();
|
||||||
|
toRemove.add(door);
|
||||||
|
toRemove.add(floorPanel);
|
||||||
|
|
||||||
|
streamProducts.removeAll(toRemove);
|
||||||
|
System.out.println(streamProducts);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
import common.Java8Product;
|
||||||
|
import common.ProductFixtures;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Java8Enhancements {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final Java8Product defaultProduct = new Java8Product(-1, "Whatever the customer wants", 100);
|
||||||
|
|
||||||
|
final Map<Integer, Java8Product> idToProduct = new HashMap<>();
|
||||||
|
idToProduct.put(1, ProductFixtures.door);
|
||||||
|
idToProduct.put(2, ProductFixtures.floorPanel);
|
||||||
|
idToProduct.put(3, ProductFixtures.window);
|
||||||
|
|
||||||
|
Java8Product result = idToProduct.getOrDefault(10, defaultProduct);
|
||||||
|
System.out.println(result);
|
||||||
|
System.out.println(idToProduct.get(10));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
result = idToProduct.computeIfAbsent(10, (id) -> new Java8Product(id, "Custom Java8Product", 10));
|
||||||
|
System.out.println(result);
|
||||||
|
System.out.println(idToProduct.get(10));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
result = idToProduct.replace(1, new Java8Product(1, "Big Door", 50));
|
||||||
|
System.out.println(result);
|
||||||
|
System.out.println(idToProduct.get(1));
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
idToProduct.replaceAll((key, oldProduct) -> new Java8Product(oldProduct.getId(), oldProduct.getName(),
|
||||||
|
oldProduct.getWeight() + 10));
|
||||||
|
System.out.println(idToProduct);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
idToProduct.forEach((key, value) -> System.out.println(key + " -> " + value));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static java.util.Comparator.comparing;
|
||||||
|
|
||||||
|
public class Java8Product {
|
||||||
|
|
||||||
|
public static final Comparator<Java8Product> BY_NAME = comparing(Java8Product::getName);
|
||||||
|
|
||||||
|
public static final Comparator<Java8Product> BY_WEIGHT = comparing(Java8Product::getWeight);
|
||||||
|
|
||||||
|
private final int id;
|
||||||
|
private final String name;
|
||||||
|
private final int weight;
|
||||||
|
|
||||||
|
public Java8Product(final int id, final String name, final int weight) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Product{" + "id=" + id + ", name='" + name + '\'' + ", weight=" + weight + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
if (!(o instanceof Java8Product))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
final Java8Product product = (Java8Product) o;
|
||||||
|
|
||||||
|
return Objects.equals(id, product.id) && Objects.equals(weight, product.weight)
|
||||||
|
&& Objects.equals(name, product.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class Product {
|
||||||
|
private final String name;
|
||||||
|
private final int weight;
|
||||||
|
|
||||||
|
public Product(String name, int weight) {
|
||||||
|
this.name = name;
|
||||||
|
this.weight = weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWeight() {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Product{" + "name='" + name + '\'' + ", weight=" + weight + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Comparator<Product> BY_WEIGHT = Comparator.comparingInt(Product::getWeight);
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
public class ProductFixtures {
|
||||||
|
public static Java8Product door = new Java8Product(1, "Wooden Door", 35);
|
||||||
|
public static Java8Product floorPanel = new Java8Product(2, "Floor Panel", 25);
|
||||||
|
public static Java8Product window = new Java8Product(3, "Glass Window", 10);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package common;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Supplier {
|
||||||
|
private final String name;
|
||||||
|
private final List<Product> products = new ArrayList<>();
|
||||||
|
|
||||||
|
public Supplier(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Product> getProducts() {
|
||||||
|
return products;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Supplier{" + "name='" + name + '\'' + ", products=" + products + '}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/../../../../../../../../:\Users\sgoud\JavaProjects\Learning-Java\Personal\Anagram\.idea/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="accountSettings">
|
||||||
|
<option name="activeRegion" value="us-east-1" />
|
||||||
|
<option name="recentlyUsedRegions">
|
||||||
|
<list>
|
||||||
|
<option value="us-east-1" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="PROJECT_FILES" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Anagram.iml" filepath="$PROJECT_DIR$/Anagram.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/../../../../../../../../:\Users\sgoud\JavaProjects\Learning-Java\Personal\Anagram\.idea/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="accountSettings">
|
||||||
|
<option name="activeRegion" value="us-east-1" />
|
||||||
|
<option name="recentlyUsedRegions">
|
||||||
|
<list>
|
||||||
|
<option value="us-east-1" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="15" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Anagram.iml" filepath="$PROJECT_DIR$/Anagram.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
Binary file not shown.
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
@ -0,0 +1 @@
|
|||||||
|
HelloWorld
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="HelloWorld" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="HelloWorld" target="13.0.2" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Maven: junit:junit:4.11">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -0,0 +1,13 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="Maven: org.hamcrest:hamcrest-core:1.3">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
|
||||||
|
</JAVADOC>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" project-jdk-name="13.0.2" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/HelloWorld.iml" filepath="$PROJECT_DIR$/HelloWorld.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue