This project has retired. For details please refer to its Attic page.
DefaultKeyFactory xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.giraph.io.gora.utils;
19  
20  /**
21   * Example class for defining a way to construct Gora keys.
22   * Uses strings as keys inside Gora.
23   */
24  public class DefaultKeyFactory extends KeyFactory {
25  
26    /**
27     * Builds a key from a string parameter.
28     * @param keyString the key object as a string.
29     * @return the key object.
30     */
31    @Override
32    public Object buildKey(String keyString) {
33      Object key = null;
34      if (getDataStore() == null) {
35        throw new RuntimeException(
36            "DataStore must be defined before using a key Builder.");
37      } else {
38        key = getDataStore().newKey();
39        // Do specific transformation
40        key = keyString;
41      }
42      return key;
43    }
44  
45  }