1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.block_app.framework.block;
2021import com.google.common.base.Objects;
2223/**24 * Number of pieces25 */26publicclassPieceCount {
27privateboolean known;
28privateint count;
2930publicPieceCount(int count) {
31 known = true;
32this.count = count;
33 }
3435privatePieceCount() {
36 known = false;
37 }
3839publicstaticPieceCount createUnknownCount() {
40returnnewPieceCount();
41 }
424344publicPieceCount add(PieceCount other) {
45if (!this.known || !other.known) {
46 known = false;
47 } else {
48 count += other.count;
49 }
50returnthis;
51 }
5253publicPieceCount multiply(int value) {
54 count *= value;
55returnthis;
56 }
5758publicint getCount() {
59if (known) {
60return count;
61 } else {
62thrownew IllegalStateException(
63"Can't get superstep count when it's unknown");
64 }
65 }
6667publicboolean isKnown() {
68return known;
69 }
7071 @Override
72publicboolean equals(Object obj) {
73if (this == obj) {
74returntrue;
75 }
76if (obj instanceof PieceCount) {
77PieceCount other = (PieceCount) obj;
78if (known) {
79return other.known && other.count == count;
80 } else {
81return !other.known;
82 }
83 }
84return false;
85 }
8687 @Override
88publicint hashCode() {
89return Objects.hashCode(known, count);
90 }
91 }