Merge branch 'search_selection' into 'master'
Add addInput and select on NoteBook, add research on NoteBook, Society, Person... See merge request p1905458/git-cvda!4
This commit is contained in:
commit
c8d4ec48fd
4 changed files with 61 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
package input;
|
||||
|
||||
import java.security.KeyStore;
|
||||
|
||||
public class Person implements Input{
|
||||
public String lastName;
|
||||
public String firstName[];
|
||||
|
@ -61,6 +63,12 @@ public class Person implements Input{
|
|||
|
||||
@Override
|
||||
public boolean research(String search) {
|
||||
if (lastName.equals(search))
|
||||
return true;
|
||||
else
|
||||
for (String s: firstName)
|
||||
if (s.equals(search))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,6 @@ public class Society implements Input{
|
|||
|
||||
@Override
|
||||
public boolean research(String search) {
|
||||
return false;
|
||||
return socialReason.equals(search);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,45 @@
|
|||
package noteBook;
|
||||
|
||||
import input.Input;
|
||||
import input.Person;
|
||||
import input.Society;
|
||||
|
||||
public class NoteBook {
|
||||
Input inputs[];
|
||||
Input selected[];
|
||||
public Input[] inputs;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
13
src/test/TestSelection.java
Normal file
13
src/test/TestSelection.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in a new issue