Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / datastore / ShortBlob.java
blob5529695d0f7fe555845b879a21ea4c014cf78130
1 // Copyright 2007 Google Inc. All rights reserved.
3 package com.google.appengine.api.datastore;
5 import java.io.Serializable;
6 import java.util.Arrays;
8 /**
9 * {@code ShortBlob} contains an array of bytes no longer than
10 * {@link DataTypeUtils#MAX_SHORT_BLOB_PROPERTY_LENGTH}. Unlike {@link Blob},
11 * {@code ShortBlobs} are indexed by the datastore and can therefore be
12 * filtered and sorted on in queries. If your data is too large to fit
13 * in a {@code ShortBlob} use {@link Blob} instead.
16 public final class ShortBlob implements Serializable, Comparable<ShortBlob> {
18 public static final long serialVersionUID = -3427166602866836472L;
20 private byte[] bytes;
22 /**
23 * This constructor exists for frameworks (e.g. Google Web Toolkit)
24 * that require it for serialization purposes. It should not be
25 * called explicitly.
27 @SuppressWarnings("unused")
28 private ShortBlob() {
29 bytes = null;
32 /**
33 * Construct a new {@code ShortBlob} with the specified bytes. This
34 * blob cannot be modified after construction.
36 public ShortBlob(byte[] bytes) {
38 this.bytes = new byte[bytes.length];
39 System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
42 /**
43 * Return the bytes stored in this {@code ShortBlob}.
45 public byte[] getBytes() {
46 return bytes;
49 @Override
50 public int hashCode() {
51 return Arrays.hashCode(bytes);
54 /**
55 * Two {@code ShortBlob} objects are considered equal if their contained
56 * bytes match exactly.
58 @Override
59 public boolean equals(Object object) {
60 if (object instanceof ShortBlob) {
61 ShortBlob other = (ShortBlob) object;
62 return Arrays.equals(bytes, other.bytes);
64 return false;
67 /**
68 * Simply prints the number of bytes contained in this {@code ShortBlob}.
70 @Override
71 public String toString() {
72 return "<ShortBlob: " + bytes.length + " bytes>";
75 @Override
76 public int compareTo(ShortBlob other) {
77 DataTypeTranslator.ComparableByteArray cba1 = new DataTypeTranslator.ComparableByteArray(bytes);
78 DataTypeTranslator.ComparableByteArray cba2 =
79 new DataTypeTranslator.ComparableByteArray(other.bytes);
80 return cba1.compareTo(cba2);