This project has retired. For details please refer to its Attic page.
IntTypeOps 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.types.ops;
19  
20  import org.apache.giraph.types.ops.collections.Basic2ObjectMap.BasicInt2ObjectOpenHashMap;
21  import org.apache.giraph.types.ops.collections.BasicSet.BasicIntOpenHashSet;
22  import org.apache.giraph.types.ops.collections.array.WIntArrayList;
23  import org.apache.giraph.types.ops.collections.WritableWriter;
24  import org.apache.hadoop.io.IntWritable;
25  
26  import java.io.DataInput;
27  import java.io.IOException;
28  
29  // AUTO-GENERATED class via class:
30  // org.apache.giraph.generate.GeneratePrimitiveClasses
31  
32  /** TypeOps implementation for working with IntWritable type */
33  public enum IntTypeOps implements
34      PrimitiveIdTypeOps<IntWritable>, NumericTypeOps<IntWritable> {
35    /** Singleton instance */
36    INSTANCE;
37  
38    @Override
39    public Class<IntWritable> getTypeClass() {
40      return IntWritable.class;
41    }
42  
43    @Override
44    public IntWritable create() {
45      return new IntWritable();
46    }
47  
48    @Override
49    public IntWritable createCopy(IntWritable from) {
50      return new IntWritable(from.get());
51    }
52  
53    @Override
54    public void set(IntWritable to, IntWritable from) {
55      to.set(from.get());
56    }
57  
58    @Override
59    public WIntArrayList createArrayList() {
60      return new WIntArrayList();
61    }
62  
63    @Override
64    public WIntArrayList createArrayList(int capacity) {
65      return new WIntArrayList(capacity);
66    }
67  
68    @Override
69    public WIntArrayList readNewArrayList(DataInput in) throws IOException {
70      return WIntArrayList.readNew(in);
71    }
72  
73    @Override
74    public BasicIntOpenHashSet createOpenHashSet() {
75      return new BasicIntOpenHashSet();
76    }
77  
78    @Override
79    public BasicIntOpenHashSet createOpenHashSet(long capacity) {
80      return new BasicIntOpenHashSet(capacity);
81    }
82  
83    @Override
84    public <V> BasicInt2ObjectOpenHashMap<V> create2ObjectOpenHashMap(
85        WritableWriter<V> valueWriter) {
86      return new BasicInt2ObjectOpenHashMap<>(valueWriter);
87    }
88  
89    @Override
90    public <V> BasicInt2ObjectOpenHashMap<V> create2ObjectOpenHashMap(
91        int capacity, WritableWriter<V> valueWriter) {
92      return new BasicInt2ObjectOpenHashMap<>(capacity, valueWriter);
93    }
94  
95    @Override
96    public IntWritable createZero() {
97      return new IntWritable(0);
98    }
99  
100   @Override
101   public IntWritable createOne() {
102     return new IntWritable(1);
103   }
104 
105   @Override
106   public IntWritable createMinNegativeValue() {
107     return new IntWritable(Integer.MIN_VALUE);
108   }
109 
110   @Override
111   public IntWritable createMaxPositiveValue() {
112     return new IntWritable(Integer.MAX_VALUE);
113   }
114 
115   @Override
116   public void plusInto(IntWritable value, IntWritable increment) {
117     value.set(value.get() + increment.get());
118   }
119 
120   @Override
121   public void multiplyInto(IntWritable value, IntWritable multiplier) {
122     value.set(value.get() * multiplier.get());
123   }
124 
125   @Override
126   public void negate(IntWritable value) {
127     value.set(-value.get());
128   }
129 
130   @Override
131   public int compare(IntWritable value1, IntWritable value2) {
132     return Integer.compare(value1.get(), value2.get());
133   }
134 }