Package com.luxoft.dnepr.courses.regular.unit6.familytree.impl

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.impl.PersonImpl


        }
        if (key.equals(AGE_ATTRIBUTE)) {
            person.setAge(Integer.parseInt(value));
        }
        if (key.equals(FATHER_ATTRIBUTE)) {
            Person father = JSONPerson.parseJSON(value);
            person.setFather(father);
        }
        if (key.equals(MOTHER_ATTRIBUTE)) {
            Person mother = JSONPerson.parseJSON(value);
            person.setMother(mother);
        }
    }
View Full Code Here


        if (person != null) {
            writer.write("\"name\":\"" + notNullString(person.getName()) + "\",\n");
            writer.write("\"gender\":\"" + notNullString(person.getGender()) + "\",\n");
            writer.write("\"ethnicity\":\"" + notNullString(person.getEthnicity()) + "\",\n");
            writer.write("\"father\":");
            Person father = person.getFather();
            writePerson(writer, father);
            writer.write(",\n\"mother\":");
            Person mother = person.getMother();
            writePerson(writer, mother);
            writer.write(",\n\"age\":\"" + person.getAge() + "\"");
        }
        writer.write("}");
    }
View Full Code Here

        String fieldName = readFamilyTreeRootName(reader);
        if (fieldName == null) {
            return null;
        }
        Person root = readFamilyTreeRootValue(reader);

        return FamilyTreeImpl.create(root);
    }
View Full Code Here

        writer.flush();
    }

    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        Reader reader = new BufferedReader(new InputStreamReader(in));
        Person tmp = IOJsonUtils.readPerson(reader);
        setName(tmp.getName());
        setAge(tmp.getAge());
        setFather(tmp.getFather());
        setMother(tmp.getMother());
        setEthnicity(tmp.getEthnicity());
        setGender(tmp.getGender());
    }
View Full Code Here

*/
public class IOUtilsTest {

    @Test
    public void testSaveAndReadJSON() {
        Person kot1 = new PersonImpl("Barsik", "Black", null, null, Gender.MALE, 11);
        Person kot2 = new PersonImpl("Murka", "White", null, null, Gender.FEMALE, 10);
        Person kot3 = new PersonImpl("Vaska", "Black and White", kot1, kot2, Gender.MALE, 8);
        Person kot4 = new PersonImpl("Fedora", "Orange", null, null, Gender.FEMALE, 8);
        Person kot5 = new PersonImpl("Malysh", "Tricolor", kot3, kot4, Gender.MALE, 6);
        Person kot6 = new PersonImpl(null, null, null, null, null, 0);
        Person kot7 = new PersonImpl(null, "Trikolor", kot1, kot2,Gender.MALE, 6);


        IOUtils.save("kot1.json", FamilyTreeImpl.create(kot1));
        IOUtils.save("kot5.json", FamilyTreeImpl.create(kot5));
        IOUtils.save("kot6.json", FamilyTreeImpl.create(kot6));
View Full Code Here

public class JSONFamilyTreeTest {

    @Test
    public void saveToFileTest() {
        PersonImpl person = new PersonImpl("Paraska", Gender.FEMALE, "ukrainian", 19, null, null);
        PersonImpl father = new PersonImpl("Vasiliy", Gender.MALE, "ukrainian", 40, null, null);
        PersonImpl mother = new PersonImpl("Ludmila", Gender.FEMALE, "ukrainian", 39, null, null);
        person.setFather(father);
        person.setMother(mother);

        FamilyTree familyTree = FamilyTreeImpl.create(person);
View Full Code Here

    }

    @Test
    public void saveToStreamTest() throws IOException {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
            PersonImpl person = new PersonImpl("Ivan", Gender.MALE, "ukrainian", 18, null, null);
            PersonImpl mother = new PersonImpl("Marina", Gender.FEMALE, "ukrainian", 38, null, null);
            PersonImpl father = new PersonImpl("Igor", Gender.MALE, "ukrainian", 40, null, null);
            PersonImpl grandFather = new PersonImpl("Vitalii Ivanovich", Gender.MALE, "ukrainian", 67, null, null);
            person.setMother(mother);
            person.setFather(father);
            father.setFather(grandFather);

            FamilyTree familyTree = FamilyTreeImpl.create(person);
View Full Code Here

            return item.toString();
        } else return QUOTE_SYMBOL + item.toString() + QUOTE_SYMBOL;
    }

    public static PersonImpl parseJSON(String JSON) {
        PersonImpl person = null;
        String hash = JSONUtils.getHashWithoutBrackets(JSON);
        String[] keyValues = JSONUtils.getKeyValuePairs(hash);
        if (keyValues.length > 0) {
            person = new PersonImpl();
        }
        for (String keyValue : keyValues) {
            String key = JSONUtils.getKey(keyValue);
            String value = JSONUtils.getValue(keyValue);
            setAttribute(person, key, value);
View Full Code Here

        }
        return character;
    }

    private static Person readPersonBody(Reader reader) throws IOException {
        PersonImpl person = new PersonImpl();
        int character = readChar(reader);
        String fieldName;
        Object fieldValue;
        boolean notNull = false;
        while (character != '}') {
View Full Code Here

*/
public class IOUtilsTest {

    @Test
    public void testSaveAndReadJSON() {
        Person kot1 = new PersonImpl("Barsik", "Black", null, null, Gender.MALE, 11);
        Person kot2 = new PersonImpl("Murka", "White", null, null, Gender.FEMALE, 10);
        Person kot3 = new PersonImpl("Vaska", "Black and White", kot1, kot2, Gender.MALE, 8);
        Person kot4 = new PersonImpl("Fedora", "Orange", null, null, Gender.FEMALE, 8);
        Person kot5 = new PersonImpl("Malysh", "Tricolor", kot3, kot4, Gender.MALE, 6);
        Person kot6 = new PersonImpl(null, null, null, null, null, 0);
        Person kot7 = new PersonImpl(null, "Trikolor", kot1, kot2,Gender.MALE, 6);


        IOUtils.save("kot1.json", FamilyTreeImpl.create(kot1));
        IOUtils.save("kot5.json", FamilyTreeImpl.create(kot5));
        IOUtils.save("kot6.json", FamilyTreeImpl.create(kot6));
View Full Code Here

TOP

Related Classes of com.luxoft.dnepr.courses.regular.unit6.familytree.impl.PersonImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.