Examples of FamilyTree


Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        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);

        IOUtils.save("file.txt", familyTree);
        FamilyTree fromJSON = IOUtils.load("file.txt");

        new File("file.txt").delete();

        Assert.assertEquals(familyTree.getRoot(), fromJSON.getRoot());
    }
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

            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);

            IOUtils.save(baos, familyTree);

            try (ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray())) {
                FamilyTree familyTreeFromJSON = IOUtils.load(bais);
                Assert.assertEquals(familyTree.getRoot(), familyTreeFromJSON.getRoot());
            }

        }
    }
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        jsonBuilder.append(CLOSE_BRACKET);
        return jsonBuilder.toString();
    }

    public static FamilyTree parseJSON(String JSON) {
        FamilyTree familyTree = null;
        String hash = JSONUtils.getHashWithoutBrackets(JSON);
        String[] keyValues = JSONUtils.getKeyValuePairs(hash);
        if (keyValues.length == 0) {
            return null;
        }
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        oos.writeUTF(JSON);
    }

    private void readObject(ObjectInputStream ois) throws IOException {
        String JSON = ois.readUTF();
        FamilyTree familyTree = JSONFamilyTree.parseJSON(JSON);
        this.root = familyTree.getRoot();
    }
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

    private IOUtils() {
    }

    public static FamilyTree load(String filename) {
        File file = new File(filename);
        FamilyTree familyTree = null;
        if (file.exists() && file.isFile()) {
            try (FileInputStream fis = new FileInputStream(file)) {
                familyTree = load(fis);
            } catch (IOException e) {
                e.printStackTrace();
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        }
        return familyTree;
    }

    public static FamilyTree load(InputStream is) {
        FamilyTree familyTree = null;
        try (ObjectInputStream ois = new ObjectInputStream(is)) {
            familyTree = (FamilyTree) ois.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        }
        return null;
    }

    public static FamilyTree load(InputStream is) {
        FamilyTree tree = null;
        try (ObjectInputStream objectInput = new ObjectInputStream(is)) {
            tree = (FamilyTree) objectInput.readObject();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
View Full Code Here

Examples of com.luxoft.dnepr.courses.regular.unit6.familytree.FamilyTree

        IOUtils.save("kot5.json", FamilyTreeImpl.create(kot5));
        IOUtils.save("kot6.json", FamilyTreeImpl.create(kot6));
        IOUtils.save("kot7.json", FamilyTreeImpl.create(kot7));
        IOUtils.save("nullkot.json", null);

        FamilyTree tree1 = IOUtils.load("kot1.json");
        assertEquals(kot1, tree1.getRoot());

        FamilyTree tree5 = IOUtils.load("kot5.json");
        assertEquals(kot5, tree5.getRoot());
        assertEquals(tree5, FamilyTreeImpl.create(kot5));

        FamilyTree tree6 = IOUtils.load("kot6.json");
        assertEquals(kot6, tree6.getRoot());
        assertEquals(tree6, FamilyTreeImpl.create(kot6));

        FamilyTree tree7 = IOUtils.load("kot7.json");
        assertEquals(kot7, tree7.getRoot());

        FamilyTree nulltree = IOUtils.load("nullkot.json");
        assertTrue(nulltree == null);

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.