[JAVA-621] core-java-lang-oop-modifiers module
* Creation * Moved code from https://www.baeldung.com/java-static * Moved code from https://www.baeldung.com/java-final * Moved code from https://www.baeldung.com/java-public-keyword * Moved code from https://www.baeldung.com/java-access-modifiers * Moved code from https://www.baeldung.com/java-private-keyword * Moved code from https://www.baeldung.com/java-static-default-methods * Moved code from https://www.baeldung.com/java-strictfp * Moved article references to the new README.md
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
package com.baeldung.core.privatemodifier;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private String privateId;
|
||||
private String name;
|
||||
private boolean manager;
|
||||
|
||||
public Employee(String id, String name) {
|
||||
setPrivateId(id);
|
||||
setName(name);
|
||||
}
|
||||
|
||||
private Employee(String id, String name, boolean managerAttribute) {
|
||||
this.privateId = id;
|
||||
this.name = name;
|
||||
this.privateId = id + "_ID-MANAGER";
|
||||
}
|
||||
|
||||
public void setPrivateId(String customId) {
|
||||
if (customId.endsWith("_ID")) {
|
||||
this.privateId = customId;
|
||||
} else {
|
||||
this.privateId = customId + "_ID";
|
||||
}
|
||||
}
|
||||
|
||||
public String getPrivateId() {
|
||||
return privateId;
|
||||
}
|
||||
|
||||
public boolean isManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public void elevateToManager() {
|
||||
if ("Carl".equals(this.name)) {
|
||||
setManager(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setManager(boolean manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Employee buildManager(String id, String name) {
|
||||
return new Employee(id, name, true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.core.privatemodifier;
|
||||
|
||||
public class ExampleClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Employee employee = new Employee("Bob","ABC123");
|
||||
employee.setPrivateId("BCD234");
|
||||
System.out.println(employee.getPrivateId());
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.core.privatemodifier;
|
||||
|
||||
public class PublicOuterClass {
|
||||
|
||||
public PrivateInnerClass getInnerClassInstance() {
|
||||
PrivateInnerClass myPrivateClassInstance = this.new PrivateInnerClass();
|
||||
myPrivateClassInstance.id = "ID1";
|
||||
myPrivateClassInstance.name = "Bob";
|
||||
return myPrivateClassInstance;
|
||||
}
|
||||
|
||||
private class PrivateInnerClass {
|
||||
public String name;
|
||||
public String id;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
public strictfp interface Circle {
|
||||
double computeArea(double radius);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
public strictfp class ScientificCalculator {
|
||||
|
||||
public double sum(double value1, double value2) {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
public double diff(double value1, double value2) {
|
||||
return value1 - value2;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.baeldung.strictfpUsage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ScientificCalculatorUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenMethodOfstrictfpClassInvoked_thenIdenticalResultOnAllPlatforms() {
|
||||
ScientificCalculator calculator = new ScientificCalculator();
|
||||
double result = calculator.sum(23e10, 98e17);
|
||||
assertThat(result, is(9.800000230000001E18));
|
||||
result = calculator.diff(Double.MAX_VALUE, 1.56);
|
||||
assertThat(result, is(1.7976931348623157E308));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user