package net.ranides.test.adapter.example;

import java.util.List;
import java.util.Map;

public class InnerDefs {

    public interface IRecordStats {

        boolean isSquare();

        boolean isWide();
    }

    public interface IRecord1 {

        int getX();

        int getY();

        int area();

    }

    public interface IRecord2 {

        int getX();

        int getY();

        int area();

        Object resize(int times);

    }

    public interface IRecord3 {

        int getX();

        int getY();

        int area();

        AbstractRecord resize(int times);

        RecordStats stats();

        String args1(int[] a, Float[] b, Number c);

        String complex(List<String> list, Map<String, Number> map) throws NumberFormatException, IllegalStateException;

    }

    public interface IRecord4 {

        int getX();

        int getY();

        int area();

        IRecord4 resize(int times);

        IRecordStats stats();

    }

    public static class RecordStats {

        private final AbstractRecord r;

        public RecordStats(AbstractRecord r) {
            this.r = r;
        }

        public boolean isSquare() {
            return r.getX() == r.getY();
        }

        public boolean isWide() {
            return r.getX() >= 2*r.getY();
        }

        public boolean isThin() {
            return r.getY() >= 2*r.getX();
        }
    }

    public static class Record extends AbstractRecord {

        protected int x;

        protected int y;

        public Record(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public Record(String value) {
            String[] a = value.split(",");
            this.x = Integer.parseInt(a[0]);
            this.y = Integer.parseInt(a[1]);
        }

        @Override
        public int getX() {
            return x;
        }

        @Override
        public int getY() {
            return y;
        }

        public RecordStats stats() {
            return new RecordStats(this);
        }

        public String args1(int[] ints, Float[] floats, Number opt) {
            return String.valueOf(100 * ints[0] + 10 * floats[0].intValue() + opt.intValue());
        }

        public String complex(List<String> list, Map<String, Number> map) throws NumberFormatException, IllegalStateException {
            return String.valueOf(Integer.parseInt(list.get(0)) + map.values().iterator().next().intValue());
        }

    }

    public static class MutableRecord extends Record {

        public MutableRecord(int x, int y) {
            super(x, y);
        }

        public MutableRecord(String value) {
            super(value);
        }

        public int area() {
            return getX() * getY();
        }

        public AbstractRecord resize(int times) {
            x *= times;
            y *= times;
            return this;
        }

        public void doSomething(String a, int b, Object c, List<String> d) {
            // do nothing
        }

    }
}
