package com.bina.varsim.fastqLiftover.types;

public class MapBlock implements Comparable<MapBlock> {
    public int size;
    public GenomeLocation srcLoc;
    public GenomeLocation dstLoc;
    public BlockType blockType;
    public int direction;
    public String name;

    public MapBlock(final int size, final String srcChr, final int srcLocation, final String dstChr, final int dstLocation, final String direction, final String featureType, final String name) {
        this.size = size;
        srcLoc = new GenomeLocation(srcChr, srcLocation);
        dstLoc = new GenomeLocation(dstChr, dstLocation);
        this.direction = direction.equals("+") ? 0 : 1;
        this.blockType = BlockType.valueOf(featureType);
        this.name = name;
    }

    public MapBlock(final GenomeLocation srcLoc) {
        size = 0;
        this.srcLoc = srcLoc;
        this.dstLoc = new GenomeLocation("", 0);
        this.blockType = BlockType.UNKNOWN;
        this.direction = 0;
    }

    @Override
    public int compareTo(MapBlock rhs) {
        return srcLoc.location - rhs.srcLoc.location;
    }

    public String toString() {
        return srcLoc.toString() + " -> " + dstLoc.toString() + " " + blockType.name() + ((direction == 0) ? "+" : "-") + " " + size + "bp";
    }

    @Override
    public boolean equals(Object rhs) {
        boolean result = false;
        if (rhs instanceof MapBlock) {
            MapBlock rhsMapBlock = (MapBlock) rhs;
            result = (size == rhsMapBlock.size && srcLoc.chromosome.equals(rhsMapBlock.srcLoc.chromosome) && srcLoc.location == rhsMapBlock.srcLoc.location);
        }
        return result;
    }

    public enum BlockType {
        SEQ("S"), INS("I"), DEL("D"), INV("V"), DUP_TANDEM("T"), UNKNOWN("U");

        private final String name;

        private BlockType(String s) {
            name = s;
        }

        public boolean equalsName(String otherName) {
            return (otherName == null) ? false : name.equals(otherName);
        }

        public String toString() {
            return name;
        }
    }
}

@@ -699,15 +699,16 @@
 ype.
-valueOf
+fromName
 (fea
@@ -1694,54 +1694,126 @@
 (%22S%22
-), INS(%22I%22), DEL(%22D%22), INV(%22V%22), DUP_TANDEM(%22T
+, %22Sequence%22), INS(%22I%22, %22Insertion%22), DEL(%22D%22, %22Deletion%22), INV(%22V%22, %22Inversion%22), DUP_TANDEM(%22T%22, %22Tandem_Duplication
 %22), 
@@ -1823,16 +1823,27 @@
 NOWN(%22U%22
+, %22Unknown%22
 );%0A%0A    
@@ -1871,73 +1871,551 @@
 ing 
-name;%0A%0A        private BlockType(String s) %7B%0A            name = s
+shortName;%0A        private final String longName;%0A%0A        BlockType(String shortName, String longName) %7B%0A            this.shortName = shortName;%0A            this.longName = longName;%0A        %7D%0A%0A        public static BlockType fromName(final String s) %7B%0A            for (final BlockType blockType : values()) %7B%0A                if (blockType.name().equals(s) %7C%7C blockType.shortName.equals(s) %7C%7C blockType.longName.equals(s)) %7B%0A                    return blockType;%0A                %7D%0A            %7D%0A            return %22%22.equals(s) ? SEQ : UNKNOWN
 ;%0A  
@@ -2526,17 +2526,22 @@
 false : 
-n
+shortN
 ame.equa
@@ -2620,17 +2620,180 @@
  return 
-n
+shortName;%0A        %7D%0A%0A        public String getShortName() %7B%0A            return shortName;%0A        %7D%0A%0A        public String getLongName() %7B%0A            return longN
 ame;%0A   

improve BlockType for better code