1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.search
;
5 import com
.google
.appengine
.api
.search
.checkers
.IndexChecker
;
8 * Represents information about an index. This class is used to fully specify
9 * the index you want to retrieve from the {@link SearchService}.
10 * To build an instance use the {@link #newBuilder()} method and set
11 * all required parameters, plus optional values different than the defaults.
13 * SearchService searchService = SearchServiceFactory.getSearchService();
15 * IndexSpec spec = IndexSpec.newBuilder()
19 * Index index = searchService.getIndex(spec);
23 public class IndexSpec
{
26 * A builder of IndexSpec.
28 public static final class Builder
{
32 * Constructs a builder for an IndexSpec.
38 * Sets the unique name of the index.
40 * @param name the name of the index
41 * @return this Builder
42 * @throws IllegalArgumentException if the index name length is not between 1
43 * and {@literal IndexChecker#MAXIMUM_INDEX_NAME_LENGTH}
45 public Builder
setName(String name
) {
46 this.name
= IndexChecker
.checkName(name
);
51 * Builds a valid IndexSpec. The builder must have set a valid
54 * @return the IndexSpec built by this builder
55 * @throws IllegalArgumentException if the IndexSpec built is not valid
57 public IndexSpec
build() {
58 return new IndexSpec(this);
62 private final String name
;
65 * Creates new index specification.
67 * @param builder the IndexSpec builder to use to construct an instance
68 * @throws IllegalArgumentException if the index name is invalid
70 private IndexSpec(Builder builder
) {
75 * @return the name of the index
77 public String
getName() {
82 * Creates a new IndexSpec builder. You must use this method to obtain a new
83 * builder. The returned builder must be used to specify all properties of
84 * the IndexSpec. To obtain the IndexSpec call the {@link Builder#build()}
85 * method on the returned builder.
87 * @return a builder which constructs a IndexSpec object
89 public static Builder
newBuilder() {
94 public int hashCode() {
97 result
= prime
* result
+ ((name
== null) ?
0 : name
.hashCode());
102 public boolean equals(Object obj
) {
109 if (getClass() != obj
.getClass()) {
112 IndexSpec other
= (IndexSpec
) obj
;
114 if (other
.name
!= null) {
117 } else if (!name
.equals(other
.name
)) {
124 public String
toString() {
125 return String
.format("IndexSpec{name: %s}", name
);
129 * Creates an SearchServicePb.IndexSpec from the given Index.
131 * @param namespace the namespace for the index
132 * @return a valid SearchServicePb.IndexSpec.Builder
134 SearchServicePb
.IndexSpec
.Builder
copyToProtocolBuffer(String namespace
) {
135 SearchServicePb
.IndexSpec
.Builder builder
= SearchServicePb
.IndexSpec
.newBuilder()
137 .setNamespace(namespace
);