//Jesus therefore came out, wearing the crown of thorns and the purple garment. Pilate said to them, "Behold, the man!" (John 19:5)
package com.javarush.task.task20.task2013;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
/*
Externalizable Person
*/
public class Solution {
public static class Person implements Externalizable {
private String firstName;
private String lastName;
private int age;
private Person mother;
private Person father;
private List children;
public Person() {}
public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public void setMother(Person mother) {
this.mother = mother;
}
public void setFather(Person father) {
this.father = father;
}
public void setChildren(List children) {
this.children = children;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(mother);
out.writeObject(father);
out.writeChars(firstName);
out.writeChars(lastName);
out.writeInt(age);
out.writeObject(children);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
firstName = in.readLine();
lastName = in.readLine();
father = (Person)in.readObject();
mother = (Person)in.readObject();
age = in.readInt();
children = (List)in.readObject();
}
}
public static void main(String[] args) {
}
}
/*
Externalizable Person
ÐлаÑÑ Person должен ÑеÑиализовÑваÑÑÑÑ Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ Ð¸Ð½ÑеÑÑейÑа Externalizable.
ÐÑпÑÐ°Ð²Ñ Ð¾ÑÐ¸Ð±ÐºÑ ÑеÑиализаÑии.
СигнаÑÑÑÑ Ð¼ÐµÑодов менÑÑÑ Ð½ÐµÐ»ÑзÑ.
ТÑебованиÑ:
1.âÐлаÑÑ Solution.Person должен поддеÑживаÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ Externalizable.
2.âÐеÑÐ¾Ð´Ñ readExternal и writeExternal Ð´Ð¾Ð»Ð¶Ð½Ñ Ð¿Ð¾Ð·Ð²Ð¾Ð»ÑÑÑ ÐºÐ¾ÑÑекÑно ÑеÑиализовÑваÑÑ Ð¸ деÑеÑиализовÑваÑÑ Ð¾Ð±ÑекÑÑ Ñипа Person.
3.âРклаÑÑе Solution.Person должен бÑÑÑ Ñоздан конÑÑÑÑкÑÐ¾Ñ Ð±ÐµÐ· паÑамеÑÑов.
4.âРклаÑÑе Solution.Person должен бÑÑÑ Ñоздан конÑÑÑÑкÑÐ¾Ñ Ñ ÑÑÐµÐ¼Ñ Ð¿Ð°ÑамеÑÑами (String firstName, String lastName, int age).
package com.javarush.task.task20.task2013;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
*
Externalizable Person
*
public class Solution {
public static class Person {
private String firstName;
private String lastName;
private int age;
private Person mother;
private Person father;
private List children;
public Person(String firstName, String lastName, int age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public void setMother(Person mother) {
this.mother = mother;
}
public void setFather(Person father) {
this.father = father;
}
public void setChildren(List children) {
this.children = children;
}
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(mother);
out.writeObject(father);
out.writeChars(firstName);
out.writeChars(lastName);
out.writeInt(age);
out.writeObject(children);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
firstName = in.readLine();
lastName = in.readLine();
father = (Person)in.readObject();
mother = (Person)in.readObject();
age = in.readInt();
children = (List)in.readObject();
}
}
public static void main(String[] args) {
}
}
*/