java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java
branchv_0
changeset 39 ec0e970e0830
parent 38 41e91ea94acb
child 40 1978eaf429de
     1.1 --- a/java/rozsirene-atributy/src/cz/frantovo/rozsireneatributy/Atribut.java	Sat Dec 16 19:09:35 2023 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,97 +0,0 @@
     1.4 -/**
     1.5 - * Rozšířené atributy – program na správu rozšířených atributů souborů
     1.6 - * Copyright © 2012 František Kučera (frantovo.cz)
     1.7 - * 
     1.8 - * This program is free software: you can redistribute it and/or modify
     1.9 - * it under the terms of the GNU General Public License as published by
    1.10 - * the Free Software Foundation, either version 3 of the License.
    1.11 - * 
    1.12 - * This program is distributed in the hope that it will be useful,
    1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 - * GNU General Public License for more details.
    1.16 - * 
    1.17 - * You should have received a copy of the GNU General Public License
    1.18 - * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.19 - */
    1.20 -package cz.frantovo.rozsireneatributy;
    1.21 -
    1.22 -import java.nio.ByteBuffer;
    1.23 -import java.nio.charset.Charset;
    1.24 -
    1.25 -/**
    1.26 - * @author Ing. František Kučera (frantovo.cz)
    1.27 - */
    1.28 -public class Atribut {
    1.29 -
    1.30 -	private String klíč;
    1.31 -	private String hodnota;
    1.32 -
    1.33 -	public Atribut(String klíč, String hodnota) {
    1.34 -		this.klíč = klíč;
    1.35 -		this.hodnota = hodnota;
    1.36 -	}
    1.37 -
    1.38 -	public Atribut(String klíč, ByteBuffer hodnota) {
    1.39 -		this.klíč = klíč;
    1.40 -		setHodnota(hodnota);
    1.41 -	}
    1.42 -
    1.43 -	public Atribut() {
    1.44 -	}
    1.45 -
    1.46 -	public String getKlíč() {
    1.47 -		return klíč;
    1.48 -	}
    1.49 -
    1.50 -	public void setKlíč(String klíč) {
    1.51 -		this.klíč = klíč;
    1.52 -	}
    1.53 -
    1.54 -	/**
    1.55 -	 * Název atributu musí být nenulový a mít nějakou délku, aby šel uložit
    1.56 -	 * TODO: další kontroly?
    1.57 -	 * @return jestli je platný
    1.58 -	 */
    1.59 -	public boolean isPlatnýKlíč() {
    1.60 -		return klíč != null && klíč.length() > 0;
    1.61 -	}
    1.62 -
    1.63 -	/**
    1.64 -	 * nulová hodnota → smazání atributu
    1.65 -	 * (ale může být prázdný řetězec)
    1.66 -	 * @return jestli je platná
    1.67 -	 */
    1.68 -	public boolean isPlatnáHodnota() {
    1.69 -		return hodnota != null;
    1.70 -	}
    1.71 -
    1.72 -	public String getHodnota() {
    1.73 -		return hodnota;
    1.74 -	}
    1.75 -
    1.76 -	public final ByteBuffer getHodnotaBajty() {
    1.77 -		return zakóduj(getHodnota());
    1.78 -	}
    1.79 -
    1.80 -	public void setHodnota(String hodnota) {
    1.81 -		this.hodnota = hodnota;
    1.82 -	}
    1.83 -
    1.84 -	public final void setHodnota(ByteBuffer hodnota) {
    1.85 -		setHodnota(dekóduj(hodnota));
    1.86 -	}
    1.87 -
    1.88 -	private static String dekóduj(ByteBuffer bajty) {
    1.89 -		bajty.flip();
    1.90 -		return Charset.defaultCharset().decode(bajty).toString();
    1.91 -	}
    1.92 -
    1.93 -	private static ByteBuffer zakóduj(String text) {
    1.94 -		if (text == null) {
    1.95 -			return null;
    1.96 -		} else {
    1.97 -			return Charset.defaultCharset().encode(text);
    1.98 -		}
    1.99 -	}
   1.100 -}