Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.task.task20.task2028;
- import java.io.Serializable;
- import java.util.AbstractList;
- import java.util.Collection;
- import java.util.List;
- /*
- Построй дерево(1)
- */
- public class CustomTree extends AbstractList<String> implements Cloneable, Serializable {
- Entry<String> root;
- @Override
- public String get(int index) {
- throw new UnsupportedOperationException();
- }
- @Override
- public int size() {
- return 0;
- }
- @Override
- public String set(int index, String element) {
- throw new UnsupportedOperationException();
- }
- @Override
- public void add(int index, String element) {
- throw new UnsupportedOperationException();
- }
- @Override
- public String remove(int index) {
- throw new UnsupportedOperationException();
- }
- @Override
- public List<String> subList(int fromIndex, int toIndex) {
- throw new UnsupportedOperationException();
- }
- @Override
- protected void removeRange(int fromIndex, int toIndex) {
- throw new UnsupportedOperationException();
- }
- @Override
- public boolean addAll(int index, Collection<? extends String> c) {
- throw new UnsupportedOperationException();
- }
- static class Entry<T> implements Serializable {
- String elementName;
- int lineNumber;
- boolean availableToAddLeftChildren;
- boolean availableToAddRightChildren;
- Entry<T> parent;
- Entry<T> leftChild;
- Entry<T> rightChild;
- public Entry(String e) {
- elementName = e;
- availableToAddLeftChildren = true;
- availableToAddRightChildren = true;
- }
- public void checkChildren() {
- if (leftChild != null) {
- availableToAddLeftChildren = false;
- }
- if (rightChild != null) {
- availableToAddRightChildren = false;
- }
- }
- public boolean isAvailableToAddChildren() {
- return (availableToAddLeftChildren || availableToAddRightChildren);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement