1.9.30 sync.
[gae.git] / java / src / main / com / google / appengine / api / datastore / Text.java
blobc7f580457e136a9604a0f435e22180532867efd3
1 /*
2 * Copyright 2007 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
16 package com.google.appengine.api.datastore;
18 import java.io.Serializable;
20 /**
21 * {@code Text} wraps around a string of unlimited size.
23 * Ordinary Java strings stored as properties in {@code Entity}
24 * objects are limited to 500 characters. However, {@code Text}
25 * objects can also be stored in properties, and are unlimited in
26 * size. However, they will not be indexed for query purposes.
29 public final class Text implements Serializable {
31 public static final long serialVersionUID = -8389037235415462280L;
33 private String value;
35 /**
36 * This constructor exists for frameworks (e.g. Google Web Toolkit)
37 * that require it for serialization purposes. It should not be
38 * called explicitly.
40 @SuppressWarnings("unused")
41 private Text() {
44 /**
45 * Construct a new {@code Text} object with the specified value.
46 * This object cannot be modified after construction.
48 public Text(String value) {
49 this.value = value;
52 /**
53 * Return the value of this {@code Text}. Can be {@code null}.
55 public String getValue() {
56 return value;
59 @Override
60 public int hashCode() {
61 if (value == null) {
62 return -1;
64 return value.hashCode();
67 /**
68 * Two {@code Text} objects are considered equal if their content
69 * strings match exactly.
71 @Override
72 public boolean equals(Object object) {
73 if (object instanceof Text) {
74 Text key = (Text) object;
75 if (value == null) {
76 return key.value == null;
78 return value.equals(key.value);
80 return false;
83 /**
84 * Returns the first 70 characters of the underlying string.
86 @Override
87 public String toString() {
88 if (value == null) {
89 return "<Text: null>";
91 String text = value;
92 if (text.length() > 70) {
93 text = text.substring(0, 70) + "...";
95 return "<Text: " + text + ">";