author | František Kučera <franta-hg@frantovo.cz> |
Wed, 15 Dec 2010 23:29:14 +0100 | |
branch | v_0 |
changeset 10 | b3aeabbb1b43 |
parent 9 | 22e22077498f |
child 11 | cc6e58fb6aad |
permissions | -rw-r--r-- |
franta-hg@6 | 1 |
package cz.frantovo.rozsireneAtributy; |
franta-hg@6 | 2 |
|
franta-hg@9 | 3 |
import java.nio.ByteBuffer; |
franta-hg@9 | 4 |
import java.nio.charset.Charset; |
franta-hg@9 | 5 |
|
franta-hg@6 | 6 |
public class Atribut { |
franta-hg@6 | 7 |
|
franta-hg@6 | 8 |
private String klic; |
franta-hg@6 | 9 |
private String hodnota; |
franta-hg@6 | 10 |
|
franta-hg@6 | 11 |
public Atribut(String klic, String hodnota) { |
franta-hg@6 | 12 |
this.klic = klic; |
franta-hg@6 | 13 |
this.hodnota = hodnota; |
franta-hg@6 | 14 |
} |
franta-hg@6 | 15 |
|
franta-hg@9 | 16 |
public Atribut(String klic, ByteBuffer hodnota) { |
franta-hg@9 | 17 |
this.klic = klic; |
franta-hg@9 | 18 |
setHodnota(hodnota); |
franta-hg@9 | 19 |
} |
franta-hg@9 | 20 |
|
franta-hg@10 | 21 |
public Atribut() { |
franta-hg@10 | 22 |
} |
franta-hg@10 | 23 |
|
franta-hg@6 | 24 |
public String getKlic() { |
franta-hg@6 | 25 |
return klic; |
franta-hg@6 | 26 |
} |
franta-hg@6 | 27 |
|
franta-hg@6 | 28 |
public void setKlic(String klic) { |
franta-hg@6 | 29 |
this.klic = klic; |
franta-hg@6 | 30 |
} |
franta-hg@6 | 31 |
|
franta-hg@6 | 32 |
public String getHodnota() { |
franta-hg@6 | 33 |
return hodnota; |
franta-hg@6 | 34 |
} |
franta-hg@6 | 35 |
|
franta-hg@9 | 36 |
public final ByteBuffer getHodnotaBajty() { |
franta-hg@9 | 37 |
return zakóduj(getHodnota()); |
franta-hg@9 | 38 |
} |
franta-hg@9 | 39 |
|
franta-hg@6 | 40 |
public void setHodnota(String hodnota) { |
franta-hg@6 | 41 |
this.hodnota = hodnota; |
franta-hg@6 | 42 |
} |
franta-hg@9 | 43 |
|
franta-hg@9 | 44 |
public final void setHodnota(ByteBuffer hodnota) { |
franta-hg@9 | 45 |
setHodnota(dekóduj(hodnota)); |
franta-hg@9 | 46 |
} |
franta-hg@9 | 47 |
|
franta-hg@9 | 48 |
private static String dekóduj(ByteBuffer bajty) { |
franta-hg@9 | 49 |
bajty.flip(); |
franta-hg@9 | 50 |
return Charset.defaultCharset().decode(bajty).toString(); |
franta-hg@9 | 51 |
} |
franta-hg@9 | 52 |
|
franta-hg@9 | 53 |
private static ByteBuffer zakóduj(String text) { |
franta-hg@10 | 54 |
if (text == null) { |
franta-hg@10 | 55 |
return null; |
franta-hg@10 | 56 |
} else { |
franta-hg@10 | 57 |
return Charset.defaultCharset().encode(text); |
franta-hg@10 | 58 |
} |
franta-hg@9 | 59 |
} |
franta-hg@6 | 60 |
} |