/*
 * The MIT License
 *
 * Copyright © 2014 Filip Plesinger, Juraj Jurco.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 * Authors: 
 * 
 * Filip Plesinger <fplesinger@isibrno.cz>
 * Institute of Scientific Instruments of the ASCR, v. v. i.
 * Brno, Czech Republic
 * 
 * Juraj Jurco <xjuraj@isibrno.cz>
 * Institute of Scientific Instruments of the ASCR, v. v. i.
 * Brno, Czech Republic
 */


package cz.academyofscience.upt.challenge2014;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author xjuraj
 */
public class Channel implements Comparable<Channel>{
    
    private Matcher BP_PATTERN;
    private Matcher ECG_PATTERN;
    public boolean isBP = false;
    public boolean isECG = false;
    
    private String name;
    private String units;
    private Integer number;
    public double[] values;
    private String[] data;

    public Channel(String name, String units, int number) {
        this(name, number);
        this.units = units;
    }
    
    public Channel(String name, int number) {
        setName(name);
        this.number = number;
        BP_PATTERN = Pattern.compile("BP.*").matcher(name);
        isBP = BP_PATTERN.matches();
        ECG_PATTERN = Pattern.compile("E.G.*").matcher(name);
        isECG = ECG_PATTERN.matches();
    }

    public Matcher getBP_PATTERN() {
        return BP_PATTERN;
    }

    public void setBP_PATTERN(Pattern BP_PATTERN) {
        this.BP_PATTERN = BP_PATTERN.matcher(name);
        isBP = this.BP_PATTERN.matches();
    }

    public Matcher getECG_PATTERN() {
        return ECG_PATTERN;
    }

    public void setECG_PATTERN(Pattern ECG_PATTERN) {
        this.ECG_PATTERN = ECG_PATTERN.matcher(name);
        isECG =  this.ECG_PATTERN.matches();
    }
    
    public String[] getData() {
        return data;
    }

    public void setData(String[] data) {
        this.data = data;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public final void setName(String name) {
        this.name = name.toUpperCase();
    }

    public String getUnits() {
        return units;
    }

    public void setUnits(String units) {
        this.units = units;
    }

    @Override
    public String toString() {
        String result = String.format("%s\n%s\n", name, units);
        for (double f : values) {
            result += String.format("%f.4\n", f);
        }
        return result;
    }

    @Override
    public int compareTo(Channel t) {
        return this.name.compareTo(t.getName());
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 23 * hash + Objects.hashCode(this.name);
        hash = 23 * hash + Objects.hashCode(this.units);
        hash = 23 * hash + Objects.hashCode(this.values);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Channel other = (Channel) obj;
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(this.units, other.units)) {
            return false;
        }
        if (!Objects.equals(this.values, other.values)) {
            return false;
        }
        return true;
    }

    
}
