[JAVA-621] core-java-lang-oop-types module
* Creation * Moved code from https://www.baeldung.com/java-marker-interfaces * Moved code from https://www.baeldung.com/java-abstract-class * Moved code from https://www.baeldung.com/java-this * Moved code from https://www.baeldung.com/java-nested-classes * Moved code from https://www.baeldung.com/java-inner-interfaces * Moved code from https://www.baeldung.com/java-classes-objects * Moved article references to the new README.md
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.abstractclasses.application;
|
||||
|
||||
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
|
||||
import com.baeldung.abstractclasses.filereaders.LowercaseFileReader;
|
||||
import com.baeldung.abstractclasses.filereaders.UppercaseFileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws IOException, URISyntaxException {
|
||||
|
||||
Application application = new Application();
|
||||
Path path = application.getPathFromResourcesFile("files/test.txt");
|
||||
BaseFileReader lowercaseFileReader = new LowercaseFileReader(path);
|
||||
lowercaseFileReader.readFile().forEach(line -> System.out.println(line));
|
||||
|
||||
BaseFileReader uppercaseFileReader = new UppercaseFileReader(path);
|
||||
uppercaseFileReader.readFile().forEach(line -> System.out.println(line));
|
||||
|
||||
}
|
||||
|
||||
private Path getPathFromResourcesFile(String filePath) throws URISyntaxException {
|
||||
return Paths.get(getClass().getClassLoader().getResource(filePath).toURI());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.baeldung.abstractclasses.filereaders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class BaseFileReader {
|
||||
|
||||
protected Path filePath;
|
||||
|
||||
protected BaseFileReader(Path filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public Path getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public List<String> readFile() throws IOException {
|
||||
return Files.lines(filePath)
|
||||
.map(this::mapFileLine).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected abstract String mapFileLine(String line);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.abstractclasses.filereaders;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LowercaseFileReader extends BaseFileReader {
|
||||
|
||||
public LowercaseFileReader(Path filePath) {
|
||||
super(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFileLine(String line) {
|
||||
return line.toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.abstractclasses.filereaders;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class UppercaseFileReader extends BaseFileReader {
|
||||
|
||||
public UppercaseFileReader(Path filePath) {
|
||||
super(filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFileLine(String line) {
|
||||
return line.toUpperCase();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public interface DeletableShape extends Shape {
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public class Rectangle implements DeletableShape {
|
||||
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public Rectangle(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCircumference() {
|
||||
return 2 * (width + height);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public interface Shape {
|
||||
double getArea();
|
||||
double getCircumference();
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public class ShapeDao {
|
||||
|
||||
public boolean delete(Object object) {
|
||||
if (!(object instanceof DeletableShape)) {
|
||||
return false;
|
||||
}
|
||||
// Calling the code that deletes the entity from the database
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.abstractclasses.test;
|
||||
|
||||
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
|
||||
import com.baeldung.abstractclasses.filereaders.LowercaseFileReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LowercaseFileReaderUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenLowercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
|
||||
Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI());
|
||||
BaseFileReader lowercaseFileReader = new LowercaseFileReader(path);
|
||||
|
||||
assertThat(lowercaseFileReader.readFile()).isInstanceOf(List.class);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.abstractclasses.test;
|
||||
|
||||
import com.baeldung.abstractclasses.filereaders.BaseFileReader;
|
||||
import com.baeldung.abstractclasses.filereaders.UppercaseFileReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UppercaseFileReaderUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenUppercaseFileReaderInstance_whenCalledreadFile_thenCorrect() throws Exception {
|
||||
Path path = Paths.get(getClass().getClassLoader().getResource("files/test.txt").toURI());
|
||||
BaseFileReader uppercaseFileReader = new UppercaseFileReader(path);
|
||||
|
||||
assertThat(uppercaseFileReader.readFile()).isInstanceOf(List.class);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class MarkerInterfaceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenDeletableObjectThenTrueReturned() {
|
||||
ShapeDao shapeDao = new ShapeDao();
|
||||
Object rectangle = new Rectangle(2, 3);
|
||||
|
||||
boolean result = shapeDao.delete(rectangle);
|
||||
assertEquals(true, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNonDeletableObjectThenFalseReturned() {
|
||||
ShapeDao shapeDao = new ShapeDao();
|
||||
Object object = new Object();
|
||||
|
||||
boolean result = shapeDao.delete(object);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user