1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*
* Copyright (C) 2014-2021 Brian L. Browning
*
* This file is part of Beagle
*
* Beagle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Beagle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package vcf;
/**
* <p>Class {@code VcfMetaInfo} represents a VCF meta-information line.
* </p>
* <p>Instances of class {@code VcfMetaInfo} are immutable.
* </p>
*
* @author Brian L. Browning {@code <browning@uw.edu>}
*/
public final class VcfMetaInfo {
/**
* The VCF meta-information line prefix: "##"
*/
public static final String PREFIX = "##";
/**
* The VCF meta-information line key-value delimiter: '='
*/
public static final char DELIMITER = '=';
private final String line;
private final String key;
private final String value;
/**
* Constructs a {@code VcfMetaInfo} instance representing
* the specified VCF meta-information line.
*
* @param line a VCF meta-information line
*
* @throws IllegalArgumentException if the specified information line,
* after removing any beginning and ending white-space, does not begin with
* {@code VcfMetaInfo.PREFIX}, and does not contain non-empty key and
* value strings separated by the {@code VcfMetaInfo.DELIMITER} character
*
* @throws NullPointerException if {@code line == null}
*/
public VcfMetaInfo(String line) {
line = line.trim();
if (line.startsWith(PREFIX)==false) {
String s = "VCF meta-information line: missing starting \""
+ PREFIX + "\": " + line;
throw new IllegalArgumentException(s);
}
int index = line.indexOf(DELIMITER);
if (index <=0 || index == line.length() - 1) {
String s = "VCF meta-information line: missing \""
+ DELIMITER + "\"";
throw new IllegalArgumentException(s);
}
this.line = line;
this.key = line.substring(2, index);
this.value = line.substring(index+1);
}
/**
* Returns the VCF meta-information line key.
* @return the VCF meta-information line key
*/
public String key() {
return key;
}
/**
* Returns the VCF meta-information line value.
* @return the VCF meta-information line value
*/
public String value() {
return value;
}
/**
* Returns the VCF meta-information line represented by {@code this}.
*
* @return the VCF meta-information line represented by {@code this}
*/
@Override
public String toString() {
return line;
}
}
|