File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\value\ValueStringFixed.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.value;
8
9 import org.h2.constant.SysProperties;
10 import org.h2.util.StringUtils;
11
12 /**
13 * Implementation of the CHAR data type.
14 */
15 public class ValueStringFixed extends ValueString {
16
17 private static final ValueStringFixed EMPTY = new ValueStringFixed("");
18
19 protected ValueStringFixed(String value) {
20 super(value);
21 }
22
23 private static String trimRight(String s) {
24 int endIndex = s.length() - 1;
25 int i = endIndex;
26 while (i >= 0 && s.charAt(i) == ' ') {
27 i--;
28 }
29 s = i == endIndex ? s : s.substring(0, i + 1);
30 return s;
31 }
32
33 public int getType() {
34 return Value.STRING_FIXED;
35 }
36
37 /**
38 * Get or create a fixed length string value for the given string.
39 * Spaces at the end of the string will be removed.
40 *
41 * @param s the string
42 * @return the value
43 */
44 public static ValueStringFixed get(String s) {
45 s = trimRight(s);
46 if (s.length() == 0) {
47 return EMPTY;
48 }
49 ValueStringFixed obj = new ValueStringFixed(StringUtils.cache(s));
50 if (s.length() > SysProperties.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) {
51 return obj;
52 }
53 return (ValueStringFixed) Value.cache(obj);
54 }
55
56 protected ValueString getNew(String s) {
57 return ValueStringFixed.get(s);
58 }
59
60 }
61