Rewrite instanceof contacts
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,9 +4,7 @@ abstract class GenericContact {
|
||||
String name;
|
||||
String number;
|
||||
|
||||
String getType() {
|
||||
return this instanceof PersonalContact == true ? "Персональный контакт" : "Деловой контакт";
|
||||
}
|
||||
abstract String getType();
|
||||
|
||||
String getInfo() {
|
||||
return "This message is unseen";
|
||||
|
||||
@@ -283,7 +283,7 @@ public class Main {
|
||||
case ('6'):
|
||||
{ // Show all work contacts
|
||||
for (var x : contacts.contacts.values()) {
|
||||
if (x instanceof WorkContact) {
|
||||
if (x.getType() == "work") {
|
||||
x.getInfo();
|
||||
}
|
||||
}
|
||||
@@ -293,7 +293,7 @@ public class Main {
|
||||
case ('7'):
|
||||
{ // Show all personal contacts
|
||||
for (var x : contacts.contacts.values()) {
|
||||
if (x instanceof PersonalContact) {
|
||||
if (x.getType() == "personal") {
|
||||
x.getInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ public class PersonalContact extends GenericContact implements Callable {
|
||||
return name + " " + number + " " + birthdate + " " + commentary + " " + address;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getType() {
|
||||
return this instanceof PersonalContact ? "personal" : "work";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@summary Interface Callable's method.}
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,11 @@ public class WorkContact extends GenericContact implements Callable, Emailable {
|
||||
return this.name + " " + this.number + " " + this.company + " " + this.duty + " " + this.email;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getType() {
|
||||
return this instanceof WorkContact ? "work" : "personal";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@summary Interface Callable's method.}
|
||||
*/
|
||||
|
||||
@@ -650,7 +650,7 @@ code + .copy-button {
|
||||
<script type="text/javascript">
|
||||
function configurationCacheProblems() { return (
|
||||
// begin-report-data
|
||||
{"diagnostics":[{"locations":[{"path":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/Main.java","line":169,"column":13,"length":1137},{"taskPath":":app:compileJava"}],"problem":[{"text":"duplicate case label"}],"severity":"ERROR","problemDetails":[{"text":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/Main.java:169: error: duplicate case label\n case (\"personal\"): \n ^"}],"contextualLabel":"duplicate case label","error":{"parts":[{"text":"org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler output below.\n/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/Main.java:169: error: duplicate case label\n case (\"personal\"): \n ^\n1 error\n"},{"internalText":"\tat org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:89)\n\tat org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:50)\n\tat org.gradle.api.internal.tasks.compile.daemon.AbstractIsolatedCompilerWorkerExecutor$CompilerWorkAction.execute(AbstractIsolatedCompilerWorkerExecutor.java:78)\n\tat org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)\n\tat org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)\n\tat org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)\n\tat org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)\n\tat org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)\n\tat org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:32)\n\tat org.gradle.workers.internal.FlatClassLoaderWorker.run(FlatClassLoaderWorker.java:22)\n\tat org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:108)\n\tat org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:77)\n\tat org.gradle.process.internal.worker.request.WorkerAction.lambda$run$1(WorkerAction.java:150)\n\tat org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)\n\tat org.gradle.process.internal.worker.request.WorkerAction.lambda$run$2(WorkerAction.java:150)\n\tat org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:85)\n\tat org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:142)\n\tat java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)\n\tat org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)\n\tat org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)\n\tat org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)\n\tat org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)\n\tat org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)\n\tat org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)\n\tat org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)\n"}]},"problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.err.duplicate.case.label","displayName":"duplicate case label"}],"solutions":[[{"text":"Check your code and dependencies to fix the compilation error(s)"}]]}],"problemsReport":{"totalProblemCount":1,"requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.1/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
||||
{"diagnostics":[{"locations":[{"path":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java"},{"taskPath":":app:compileJava"}],"problem":[{"text":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java uses unchecked or unsafe operations."}],"severity":"ADVICE","problemDetails":[{"text":"Note: /home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java uses unchecked or unsafe operations."}],"contextualLabel":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java uses unchecked or unsafe operations.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.filename","displayName":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java uses unchecked or unsafe operations."}]},{"locations":[{"path":"/home/maksytka/work/java/java_lab1/app/src/main/java/org/lab/main/PhoneBook.java"},{"taskPath":":app:compileJava"}],"problem":[{"text":"Recompile with -Xlint:unchecked for details."}],"severity":"ADVICE","problemDetails":[{"text":"Note: Recompile with -Xlint:unchecked for details."}],"contextualLabel":"Recompile with -Xlint:unchecked for details.","problemId":[{"name":"java","displayName":"Java compilation"},{"name":"compilation","displayName":"Compilation"},{"name":"compiler.note.unchecked.recompile","displayName":"Recompile with -Xlint:unchecked for details."}]}],"problemsReport":{"totalProblemCount":2,"requestedTasks":"build","documentationLink":"https://docs.gradle.org/8.14.1/userguide/reporting_problems.html","documentationLinkCaption":"Problem report","summaries":[]}}
|
||||
// end-report-data
|
||||
);}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user