Coverage Report - org.apache.giraph.block_app.framework.block.PieceCount
 
Classes in this File Line Coverage Branch Coverage Complexity
PieceCount
0%
0/27
0%
0/18
2.333
 
 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.block_app.framework.block;
 20  
 
 21  
 import com.google.common.base.Objects;
 22  
 
 23  
 /**
 24  
  * Number of pieces
 25  
  */
 26  
 public class PieceCount {
 27  
   private boolean known;
 28  
   private int count;
 29  
 
 30  0
   public PieceCount(int count) {
 31  0
     known = true;
 32  0
     this.count = count;
 33  0
   }
 34  
 
 35  0
   private PieceCount() {
 36  0
     known = false;
 37  0
   }
 38  
 
 39  
   public static PieceCount createUnknownCount() {
 40  0
     return new PieceCount();
 41  
   }
 42  
 
 43  
 
 44  
   public PieceCount add(PieceCount other) {
 45  0
     if (!this.known || !other.known) {
 46  0
       known = false;
 47  
     } else {
 48  0
       count += other.count;
 49  
     }
 50  0
     return this;
 51  
   }
 52  
 
 53  
   public PieceCount multiply(int value) {
 54  0
     count *= value;
 55  0
     return this;
 56  
   }
 57  
 
 58  
   public int getCount() {
 59  0
     if (known) {
 60  0
       return count;
 61  
     } else {
 62  0
       throw new IllegalStateException(
 63  
           "Can't get superstep count when it's unknown");
 64  
     }
 65  
   }
 66  
 
 67  
   public boolean isKnown() {
 68  0
     return known;
 69  
   }
 70  
 
 71  
   @Override
 72  
   public boolean equals(Object obj) {
 73  0
     if (this == obj) {
 74  0
       return true;
 75  
     }
 76  0
     if (obj instanceof PieceCount) {
 77  0
       PieceCount other = (PieceCount) obj;
 78  0
       if (known) {
 79  0
         return other.known && other.count == count;
 80  
       } else {
 81  0
         return !other.known;
 82  
       }
 83  
     }
 84  0
     return false;
 85  
   }
 86  
 
 87  
   @Override
 88  
   public int hashCode() {
 89  0
     return Objects.hashCode(known, count);
 90  
   }
 91  
 }