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
19 package org.apache.giraph.graph;
20
21 /**
22 * Simple immutable structure for storing a final vertex and edge count.
23 */
24 public class VertexEdgeCount {
25 /** Immutable vertices */
26 private final long vertexCount;
27 /** Immutable edges */
28 private final long edgeCount;
29 /** Immutable mappings */
30 private final long mappingCount;
31
32 /**
33 * Default constructor.
34 */
35 public VertexEdgeCount() {
36 vertexCount = 0;
37 edgeCount = 0;
38 mappingCount = 0;
39 }
40
41 /**
42 * Constructor with initial values.
43 *
44 * @param vertexCount Final number of vertices.
45 * @param edgeCount Final number of edges.
46 * @param mappingCount Final number of mappings.
47 */
48 public VertexEdgeCount(long vertexCount, long edgeCount, long mappingCount) {
49 this.vertexCount = vertexCount;
50 this.edgeCount = edgeCount;
51 this.mappingCount = mappingCount;
52 }
53
54 public long getVertexCount() {
55 return vertexCount;
56 }
57
58 public long getEdgeCount() {
59 return edgeCount;
60 }
61
62 public long getMappingCount() {
63 return mappingCount;
64 }
65
66 /**
67 * Increment the both the vertex edge count with a {@link VertexEdgeCount}.
68 *
69 * @param vertexEdgeCount add both the vertices and edges of this object.
70 * @return New immutable object with the new vertex and edge counts.
71 */
72 public VertexEdgeCount incrVertexEdgeCount(
73 VertexEdgeCount vertexEdgeCount) {
74 return new VertexEdgeCount(
75 vertexCount + vertexEdgeCount.getVertexCount(),
76 edgeCount + vertexEdgeCount.getEdgeCount(),
77 mappingCount + vertexEdgeCount.getMappingCount());
78 }
79
80 /**
81 * Increment the both the vertex edge count with primitives.
82 *
83 * @param vertexCount Add this many vertices.
84 * @param edgeCount Add this many edges.
85 * @return New immutable object with the new vertex and edge counts.
86 */
87 public VertexEdgeCount incrVertexEdgeCount(
88 long vertexCount, long edgeCount) {
89 return new VertexEdgeCount(
90 this.vertexCount + vertexCount,
91 this.edgeCount + edgeCount,
92 this.mappingCount + mappingCount);
93 }
94
95 @Override
96 public String toString() {
97 return "(v=" + getVertexCount() + ", e=" + getEdgeCount() +
98 (mappingCount > 0 ? ", m=" + mappingCount : "") + ")";
99 }
100 }