File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\mvstore\type\StringType.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.mvstore.type;
8
9 import java.nio.ByteBuffer;
10 import org.h2.mvstore.DataUtils;
11
12 /**
13 * A string type.
14 */
15 public class StringType implements DataType {
16
17 public static final StringType INSTANCE = new StringType();
18
19 public int compare(Object a, Object b) {
20 return a.toString().compareTo(b.toString());
21 }
22
23 public int getMaxLength(Object obj) {
24 return DataUtils.MAX_VAR_INT_LEN + 3 * obj.toString().length();
25 }
26
27 public int getMemory(Object obj) {
28 return 24 + 2 * obj.toString().length();
29 }
30
31 public String read(ByteBuffer buff) {
32 int len = DataUtils.readVarInt(buff);
33 return DataUtils.readString(buff, len);
34 }
35
36 public void write(ByteBuffer buff, Object obj) {
37 String s = obj.toString();
38 int len = s.length();
39 DataUtils.writeVarInt(buff, len);
40 DataUtils.writeStringData(buff, s, len);
41 }
42
43 public String asString() {
44 return "";
45 }
46
47 }
48
49