Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -39,6 +39,3 @@ This tutorials project is being built **[>> HERE](https://rest-security.ci.cloud
|
||||
|
||||
- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure)
|
||||
- [Apache Maven Tutorial](http://www.baeldung.com/maven)
|
||||
- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library)
|
||||
- [Java Service Provider Interface](http://www.baeldung.com/java-spi)
|
||||
- [Java Streams vs Vavr Streams](http://www.baeldung.com/vavr-java-streams)
|
||||
|
||||
@@ -148,7 +148,7 @@ public class Board {
|
||||
System.out.println("Game Draw");
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
System.out.println("Game In rogress");
|
||||
System.out.println("Game In Progress");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jgrapht.traverse.DepthFirstIterator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DirectedGraphUnitTests {
|
||||
public class DirectedGraphUnitTest {
|
||||
DirectedGraph<String, DefaultEdge> directedGraph;
|
||||
|
||||
@Before
|
||||
@@ -5,7 +5,7 @@
|
||||
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>example-animal-sniffer-mvn-plugin</name>
|
||||
<name>animal-sniffer-mvn-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CayenneAdvancedOperationIntegrationTest {
|
||||
public class CayenneAdvancedOperationLiveTest {
|
||||
private static ObjectContext context = null;
|
||||
|
||||
@BeforeClass
|
||||
+1
-1
@@ -16,7 +16,7 @@ import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
||||
public class CayenneOperationIntegrationTest {
|
||||
public class CayenneOperationLiveTest {
|
||||
private static ObjectContext context = null;
|
||||
|
||||
@BeforeClass
|
||||
+1
-1
@@ -8,7 +8,7 @@ import opennlp.tools.tokenize.WhitespaceTokenizer;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TokenizerTest {
|
||||
public class TokenizerUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenEnglishModel_whenTokenize_thenTokensAreDetected() throws Exception {
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Deploy Spring Boot App to Azure]()
|
||||
- [Deploy Spring Boot App to Azure](http://www.baeldung.com/spring-boot-azure)
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class AzureApplicationTests {
|
||||
public class AzureApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
@@ -5,7 +5,6 @@
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>spring-boot-camel</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>Spring-Boot - Camel API</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
+2
-3
@@ -8,9 +8,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-spring</artifactId>
|
||||
<artifactId>parent-spring-4</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-spring</relativePath>
|
||||
<relativePath>../parent-spring-4</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -38,7 +38,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring.version>4.3.4.RELEASE</spring.version>
|
||||
<aspectjweaver.version>1.8.9</aspectjweaver.version>
|
||||
<weld-se-core.version>2.4.1.Final</weld-se-core.version>
|
||||
</properties>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference)
|
||||
- [Guide to Java 10](http://www.baeldung.com/java-10-overview)
|
||||
@@ -50,4 +50,6 @@
|
||||
- [Filtering Kotlin Collections](http://www.baeldung.com/kotlin-filter-collection)
|
||||
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
|
||||
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)
|
||||
- [Java Optional – orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get)
|
||||
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
|
||||
|
||||
|
||||
@@ -195,6 +195,16 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.reflect;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String fullName;
|
||||
|
||||
public Person(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public void setFullName(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.reflect;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MethodParamNameUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenGetConstructorParams_thenOk()
|
||||
throws NoSuchMethodException, SecurityException {
|
||||
List<Parameter> parameters
|
||||
= Arrays.asList(Person.class.getConstructor(String.class).getParameters());
|
||||
Optional<Parameter> parameter
|
||||
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
|
||||
assertThat(parameter.get().getName()).isEqualTo("fullName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMethodParams_thenOk()
|
||||
throws NoSuchMethodException, SecurityException {
|
||||
List<Parameter> parameters
|
||||
= Arrays.asList(
|
||||
Person.class.getMethod("setFullName", String.class).getParameters());
|
||||
Optional<Parameter> parameter
|
||||
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
|
||||
assertThat(parameter.get().getName()).isEqualTo("fullName");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class StreamIndicesTest {
|
||||
public class StreamIndicesUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCalled_thenReturnListOfEvenIndexedStrings() {
|
||||
@@ -24,3 +24,4 @@
|
||||
- [Method Handles in Java](http://www.baeldung.com/java-method-handles)
|
||||
- [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
|
||||
- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity)
|
||||
- [Optional orElse Optional](http://www.baeldung.com/java-optional-or-else-optional)
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package com.baeldung.java9.modules;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.module.ModuleDescriptor;
|
||||
import java.lang.module.ModuleDescriptor.*;
|
||||
import java.sql.Date;
|
||||
import java.sql.Driver;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ModuleAPIUnitTest {
|
||||
|
||||
public static final String JAVA_BASE_MODULE_NAME = "java.base";
|
||||
|
||||
private Module javaBaseModule;
|
||||
private Module javaSqlModule;
|
||||
private Module module;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Class<HashMap> hashMapClass = HashMap.class;
|
||||
javaBaseModule = hashMapClass.getModule();
|
||||
|
||||
Class<Date> dateClass = Date.class;
|
||||
javaSqlModule = dateClass.getModule();
|
||||
|
||||
Class<Person> personClass = Person.class;
|
||||
module = personClass.getModule();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckingIfNamed_thenModuleIsNamed() {
|
||||
assertThat(javaBaseModule.isNamed(), is(true));
|
||||
assertThat(javaBaseModule.getName(), is(JAVA_BASE_MODULE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckingIfNamed_thenModuleIsUnnamed() {
|
||||
assertThat(module.isNamed(), is(false));
|
||||
assertThat(module.getName(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenExtractingPackagesContainedInAModule_thenModuleContainsOnlyFewOfThem() {
|
||||
assertTrue(javaBaseModule.getPackages().contains("java.lang.annotation"));
|
||||
assertFalse(javaBaseModule.getPackages().contains("java.sql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrievingClassLoader_thenClassLoaderIsReturned() {
|
||||
assertThat(
|
||||
module.getClassLoader().getClass().getName(),
|
||||
is("jdk.internal.loader.ClassLoaders$AppClassLoader")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGettingAnnotationsPresentOnAModule_thenNoAnnotationsArePresent() {
|
||||
assertThat(javaBaseModule.getAnnotations().length, is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGettingLayerOfAModule_thenModuleLayerInformationAreAvailable() {
|
||||
ModuleLayer javaBaseModuleLayer = javaBaseModule.getLayer();
|
||||
|
||||
assertTrue(javaBaseModuleLayer.configuration().findModule(JAVA_BASE_MODULE_NAME).isPresent());
|
||||
assertThat(javaBaseModuleLayer.configuration().modules().size(), is(78));
|
||||
assertTrue(javaBaseModuleLayer.parents().get(0).configuration().parents().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrievingModuleDescriptor_thenTypeOfModuleIsInferred() {
|
||||
ModuleDescriptor javaBaseModuleDescriptor = javaBaseModule.getDescriptor();
|
||||
ModuleDescriptor javaSqlModuleDescriptor = javaSqlModule.getDescriptor();
|
||||
|
||||
assertFalse(javaBaseModuleDescriptor.isAutomatic());
|
||||
assertFalse(javaBaseModuleDescriptor.isOpen());
|
||||
assertFalse(javaSqlModuleDescriptor.isAutomatic());
|
||||
assertFalse(javaSqlModuleDescriptor.isOpen());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModuleName_whenBuildingModuleDescriptor_thenBuilt() {
|
||||
Builder moduleBuilder = ModuleDescriptor.newModule("baeldung.base");
|
||||
|
||||
ModuleDescriptor moduleDescriptor = moduleBuilder.build();
|
||||
|
||||
assertThat(moduleDescriptor.name(), is("baeldung.base"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorRequires_thenRequiresAreReturned() {
|
||||
Set<Requires> javaBaseRequires = javaBaseModule.getDescriptor().requires();
|
||||
Set<Requires> javaSqlRequires = javaSqlModule.getDescriptor().requires();
|
||||
|
||||
Set<String> javaSqlRequiresNames = javaSqlRequires.stream()
|
||||
.map(Requires::name)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseRequires, empty());
|
||||
assertThat(javaSqlRequires.size(), is(3));
|
||||
assertThat(javaSqlRequiresNames, containsInAnyOrder("java.base", "java.xml", "java.logging"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorProvides_thenProvidesAreReturned() {
|
||||
Set<Provides> javaBaseProvides = javaBaseModule.getDescriptor().provides();
|
||||
Set<Provides> javaSqlProvides = javaSqlModule.getDescriptor().provides();
|
||||
|
||||
Set<String> javaBaseProvidesService = javaBaseProvides.stream()
|
||||
.map(Provides::service)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseProvidesService, contains("java.nio.file.spi.FileSystemProvider"));
|
||||
assertThat(javaSqlProvides, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorExports_thenExportsAreReturned() {
|
||||
Set<Exports> javaBaseExports = javaBaseModule.getDescriptor().exports();
|
||||
Set<Exports> javaSqlExports = javaSqlModule.getDescriptor().exports();
|
||||
|
||||
Set<String> javaSqlExportsSource = javaSqlExports.stream()
|
||||
.map(Exports::source)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseExports.size(), is(108));
|
||||
assertThat(javaSqlExports.size(), is(3));
|
||||
assertThat(javaSqlExportsSource, containsInAnyOrder("java.sql", "javax.transaction.xa", "javax.sql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorUses_thenUsesAreReturned() {
|
||||
Set<String> javaBaseUses = javaBaseModule.getDescriptor().uses();
|
||||
Set<String> javaSqlUses = javaSqlModule.getDescriptor().uses();
|
||||
|
||||
assertThat(javaBaseUses.size(), is(34));
|
||||
assertThat(javaSqlUses, contains("java.sql.Driver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorOpen_thenOpenAreReturned() {
|
||||
Set<Opens> javaBaseUses = javaBaseModule.getDescriptor().opens();
|
||||
Set<Opens> javaSqlUses = javaSqlModule.getDescriptor().opens();
|
||||
|
||||
assertThat(javaBaseUses, empty());
|
||||
assertThat(javaSqlUses, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingReadsToAModule_thenModuleCanReadNewModule() {
|
||||
Module updatedModule = module.addReads(javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.canRead(javaSqlModule));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenExportingPackage_thenPackageIsExported() {
|
||||
Module updatedModule = module.addExports("com.baeldung.java9.modules", javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.isExported("com.baeldung.java9.modules"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOpeningAModulePackage_thenPackagedIsOpened() {
|
||||
Module updatedModule = module.addOpens("com.baeldung.java9.modules", javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.isOpen("com.baeldung.java9.modules", javaSqlModule));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUsesToModule_thenUsesIsAdded() {
|
||||
Module updatedModule = module.addUses(Driver.class);
|
||||
|
||||
assertTrue(updatedModule.canUse(Driver.class));
|
||||
}
|
||||
|
||||
private class Person {
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,3 +29,4 @@
|
||||
- [Java TreeMap vs HashMap](http://www.baeldung.com/java-treemap-vs-hashmap)
|
||||
- [How to TDD a List Implementation in Java](http://www.baeldung.com/java-test-driven-list)
|
||||
- [How to Store Duplicate Keys in a Map in Java?](http://www.baeldung.com/java-map-duplicate-keys)
|
||||
- [Getting the Size of an Iterable in Java](http://www.baeldung.com/java-iterable-size)
|
||||
|
||||
@@ -27,3 +27,4 @@
|
||||
- [A Guide to WatchService in Java NIO2](http://www.baeldung.com/java-nio2-watchservice)
|
||||
- [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels)
|
||||
- [A Guide to NIO2 Asynchronous Socket Channel](http://www.baeldung.com/java-nio2-async-socket-channel)
|
||||
- [Download a File From an URL in Java](http://www.baeldung.com/java-download-file)
|
||||
|
||||
@@ -77,6 +77,6 @@ public class FilesManualTest {
|
||||
bw.newLine();
|
||||
bw.close();
|
||||
|
||||
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
|
||||
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.baeldung.java.io;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -105,8 +106,9 @@ public class JavaReadFromFileUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO
|
||||
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
|
||||
final String expected_value = "�空";
|
||||
final String expected_value = "青空";
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
|
||||
final String currentLine = reader.readLine();
|
||||
reader.close();
|
||||
|
||||
@@ -141,3 +141,12 @@
|
||||
- [Java KeyStore API](http://www.baeldung.com/java-keystore)
|
||||
- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking)
|
||||
- [Guide to Java Clock Class](http://www.baeldung.com/java-clock)
|
||||
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
||||
- [Using Java Assertions](http://www.baeldung.com/java-assert)
|
||||
- [Pass-By-Value as a Parameter Passing Mechanism in Java](http://www.baeldung.com/java-pass-by-value-or-pass-by-reference)
|
||||
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
||||
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
|
||||
- [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers)
|
||||
- [NaN in Java](http://www.baeldung.com/java-not-a-number)
|
||||
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
||||
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
||||
|
||||
@@ -198,6 +198,11 @@
|
||||
<artifactId>mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.5.0-b01</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.baeldung.array;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class JaggedArray {
|
||||
|
||||
int[][] shortHandFormInitialization() {
|
||||
int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
int[][] declarationAndThenInitialization() {
|
||||
int[][] jaggedArr = new int[3][];
|
||||
jaggedArr[0] = new int[] { 1, 2 };
|
||||
jaggedArr[1] = new int[] { 3, 4, 5 };
|
||||
jaggedArr[2] = new int[] { 6, 7, 8, 9 };
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
int[][] declarationAndThenInitializationUsingUserInputs() {
|
||||
int[][] jaggedArr = new int[3][];
|
||||
jaggedArr[0] = new int[2];
|
||||
jaggedArr[1] = new int[3];
|
||||
jaggedArr[2] = new int[4];
|
||||
initializeElements(jaggedArr);
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
void initializeElements(int[][] jaggedArr) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
for (int outer = 0; outer < jaggedArr.length; outer++) {
|
||||
for (int inner = 0; inner < jaggedArr[outer].length; inner++) {
|
||||
jaggedArr[outer][inner] = sc.nextInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printElements(int[][] jaggedArr) {
|
||||
for (int index = 0; index < jaggedArr.length; index++) {
|
||||
System.out.println(Arrays.toString(jaggedArr[index]));
|
||||
}
|
||||
}
|
||||
|
||||
int[] getElementAtGivenIndex(int[][] jaggedArr, int index) {
|
||||
return jaggedArr[index];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.keyword;
|
||||
|
||||
import com.baeldung.keyword.superkeyword.SuperSub;
|
||||
import com.baeldung.keyword.thiskeyword.KeywordTest;
|
||||
import com.baeldung.keyword.thiskeyword.KeywordUnitTest;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/14/2018.
|
||||
@@ -9,7 +9,7 @@ import com.baeldung.keyword.thiskeyword.KeywordTest;
|
||||
public class KeywordDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
KeywordTest keyword = new KeywordTest();
|
||||
KeywordUnitTest keyword = new KeywordUnitTest();
|
||||
|
||||
SuperSub child = new SuperSub("message from the child class");
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package com.baeldung.keyword.thiskeyword;
|
||||
|
||||
public class KeywordTest {
|
||||
public class KeywordUnitTest {
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public KeywordTest() {
|
||||
public KeywordUnitTest() {
|
||||
this("John", 27);
|
||||
this.printMessage();
|
||||
printInstance(this);
|
||||
}
|
||||
|
||||
public KeywordTest(String name, int age) {
|
||||
public KeywordUnitTest(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
@@ -20,11 +20,11 @@ public class KeywordTest {
|
||||
System.out.println("invoked by this");
|
||||
}
|
||||
|
||||
public void printInstance(KeywordTest thisKeyword) {
|
||||
public void printInstance(KeywordUnitTest thisKeyword) {
|
||||
System.out.println(thisKeyword);
|
||||
}
|
||||
|
||||
public KeywordTest getCurrentInstance() {
|
||||
public KeywordUnitTest getCurrentInstance() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ public class KeywordTest {
|
||||
boolean isInnerClass = true;
|
||||
|
||||
public ThisInnerClass() {
|
||||
KeywordTest thisKeyword = KeywordTest.this;
|
||||
String outerString = KeywordTest.this.name;
|
||||
KeywordUnitTest thisKeyword = KeywordUnitTest.this;
|
||||
String outerString = KeywordUnitTest.this.name;
|
||||
System.out.println(this.isInnerClass);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
package com.baeldung.linkedlist;
|
||||
|
||||
import com.baeldung.linkedlist.LinkedList.Node;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.baeldung.linkedlist.Node;
|
||||
|
||||
public class MiddleElementLookup {
|
||||
|
||||
public static String findMiddleElement(Node head) {
|
||||
public static String findMiddleElementLinkedList(LinkedList<String> linkedList) {
|
||||
if (linkedList == null || linkedList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return linkedList.get((linkedList.size() - 1) / 2);
|
||||
}
|
||||
|
||||
public static String findMiddleElementFromHead(Node head) {
|
||||
if (head == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -26,7 +36,7 @@ public class MiddleElementLookup {
|
||||
return current.data();
|
||||
}
|
||||
|
||||
public static String findMiddleElement1PassRecursively(Node head) {
|
||||
public static String findMiddleElementFromHead1PassRecursively(Node head) {
|
||||
if (head == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -53,7 +63,7 @@ public class MiddleElementLookup {
|
||||
middleAux.length--;
|
||||
}
|
||||
|
||||
public static String findMiddleElement1PassIteratively(Node head) {
|
||||
public static String findMiddleElementFromHead1PassIteratively(Node head) {
|
||||
if (head == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.linkedlist;
|
||||
|
||||
public class Node {
|
||||
private Node next;
|
||||
private String data;
|
||||
|
||||
public Node(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return next != null;
|
||||
}
|
||||
|
||||
public Node next() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public void setNext(Node next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user