File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\mvstore\type\DataType.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
11 /**
12 * A data type.
13 */
14 public interface DataType {
15
16 /**
17 * Compare two keys.
18 *
19 * @param a the first key
20 * @param b the second key
21 * @return -1 if the first key is smaller, 1 if larger, and 0 if equal
22 */
23 int compare(Object a, Object b);
24
25 /**
26 * Get the maximum length in bytes used to store an object. In many cases,
27 * this method can be faster than calculating the exact length.
28 *
29 * @param obj the object
30 * @return the maximum length
31 */
32 int getMaxLength(Object obj);
33
34 /**
35 * Estimate the used memory in bytes.
36 *
37 * @param obj the object
38 * @return the used memory
39 */
40 int getMemory(Object obj);
41
42 /**
43 * Write the object.
44 *
45 * @param buff the target buffer
46 * @param obj the value
47 */
48 void write(ByteBuffer buff, Object obj);
49
50 /**
51 * Read an object.
52 *
53 * @param buff the source buffer
54 * @return the object
55 */
56 Object read(ByteBuffer buff);
57
58 /**
59 * Get the stable string representation that is used to build this data
60 * type.
61 * <p>
62 * To avoid conflict with the default factory, the returned string should
63 * start with the package name of the type factory.
64 *
65 * @return the string representation
66 */
67 String asString();
68
69 }
70
71