1
0
Fork 0

Add addInput and select on NoteBook, add research on NoteBook, Society, Person and create TestSelection

This commit is contained in:
Ethanell 2020-04-04 14:32:01 +02:00
parent d40eea9e73
commit 8ac38b547d
4 changed files with 61 additions and 3 deletions

View file

@ -1,5 +1,7 @@
package input; package input;
import java.security.KeyStore;
public class Person implements Input{ public class Person implements Input{
public String lastName; public String lastName;
public String firstName[]; public String firstName[];
@ -61,6 +63,12 @@ public class Person implements Input{
@Override @Override
public boolean research(String search) { public boolean research(String search) {
if (lastName.equals(search))
return true;
else
for (String s: firstName)
if (s.equals(search))
return true;
return false; return false;
} }
} }

View file

@ -15,6 +15,6 @@ public class Society implements Input{
@Override @Override
public boolean research(String search) { public boolean research(String search) {
return false; return socialReason.equals(search);
} }
} }

View file

@ -1,8 +1,45 @@
package noteBook; package noteBook;
import input.Input; import input.Input;
import input.Person;
import input.Society;
public class NoteBook { public class NoteBook {
Input inputs[]; public Input[] inputs;
Input selected[]; public Input[] selected;
public void addInput(Input in) {
Input[] tmp = new Input[inputs.length+1];
System.arraycopy(inputs, 0, tmp, 0, inputs.length);
tmp[inputs.length] = in;
inputs = tmp;
}
public void select(String selected) {
for (Input i: inputs)
if (i.toString().equals(selected)) {
this.selected = new Input[]{i};
break;
}
}
public void select(Input selected) {
this.selected = new Input[]{selected};
}
public void select(Input[] selected) {
this.selected = selected;
}
public Input[] research(String target) {
Input[] tmp = new Input[inputs.length];
int index = 0;
for (Input i: inputs) {
if (i.research(target))
tmp[index++] = i;
}
Input[] out = new Input[index];
System.arraycopy(tmp, 0, out, 0, out.length);
return out;
}
} }

View file

@ -0,0 +1,13 @@
package test;
import input.Input;
import noteBook.NoteBook;
public class TestSelection {
public static void main(String[] args) {
NoteBook book = new NoteBook();
book.FileReading("testBook");
for (Input i: book.inputs)
System.out.println(i);
}
}