/*
 * Copyright (c) 2015  NECTEC
 *   National Electronics and Computer Technology Center, Thailand
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package th.or.nectec.tanrabad.entity;


public class SurveyDetail {
    private final ContainerType containerType;
    private int totalContainer;
    private int foundLarvaContainer;
    public SurveyDetail(ContainerType containerType, int totalContainer, int foundLarvaContainer) {
        this.containerType = containerType;
        setContainerCount(totalContainer, foundLarvaContainer);
    }

    public static SurveyDetail fromResult(ContainerType containerType, int total, int found) {
        return new SurveyDetail(containerType, total, found);
    }

    @Override
    public String toString() {
        return "SurveyDetail{" +
                "containerType=" + containerType +
                ", totalContainer=" + totalContainer +
                ", foundLarvaContainer=" + foundLarvaContainer +
                '}';
    }

    private void setContainerCount(int total, int found) {
        if (found > total)
            throw new ContainerFoundLarvaOverTotalException();
        this.totalContainer = total;
        this.foundLarvaContainer = found;
    }

    public ContainerType getContainerType() {
        return containerType;
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) return true;
        if (other == null || getClass() != other.getClass()) return false;

        SurveyDetail that = (SurveyDetail) other;
        return totalContainer == that.totalContainer &&
                foundLarvaContainer == that.foundLarvaContainer &&
                containerType.equals(that.containerType);
    }

    @Override
    public int hashCode() {
        int result = containerType.hashCode();
        result = 31 * result + totalContainer;
        result = 31 * result + foundLarvaContainer;
        return result;
    }

    public int getTotalContainer() {
        return totalContainer;
    }

    public int getFoundLarvaContainer() {
        return foundLarvaContainer;
    }

    public class ContainerFoundLarvaOverTotalException extends RuntimeException {
    }
}

@@ -18,17 +18,16 @@
 c) 2015 
- 
 NECTEC%0A 
@@ -834,24 +834,25 @@
 aContainer;%0A
+%0A
     public S
@@ -1063,315 +1063,165 @@
    p
-ublic static SurveyDetail fromResult(ContainerType containerType, int total, int found) %7B%0A        return new SurveyDetail(containerType, total, found);
+rivate void setContainerCount(int total, int found) %7B%0A        if (found %3E total)
 %0A    
-%7D%0A%0A
     
-@Override%0A    public String toString() %7B%0A        return %22SurveyDetail%7B%22 +%0A                %22containerType=%22 + containerType +%0A                %22, 
+    throw new ContainerFoundLarvaOverTotalException();%0A        this.
 tota
@@ -1234,49 +1234,31 @@
 iner
+ 
 =
-%22 +
  total
-Container +%0A                %22, 
+;%0A        this.
 foun
@@ -1276,326 +1276,449 @@
 iner
+ 
 =
-%22 +
  found
-LarvaContainer +%0A                '%7D';%0A    %7D%0A%0A    private void setContainerCount(int total, int found) %7B%0A        if (found %3E total)
+;%0A    %7D%0A%0A    public static SurveyDetail fromResult(ContainerType containerType, int total, int found) %7B%0A        return new SurveyDetail(containerType, total, found);
 %0A    
+%7D%0A%0A
     
-    throw new ContainerFoundLarvaOverTotalException();%0A        this.totalContainer = total;%0A        this.foundLarvaContainer = found;%0A    %7D%0A%0A    public ContainerType get
+public ContainerType getContainerType() %7B%0A        return containerType;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        int result = containerType.hashCode();%0A        result = 31 * result + totalContainer;%0A        result = 31 * result + foundLarva
 Cont
@@ -1718,32 +1718,25 @@
 rvaContainer
-Type() %7B
+;
 %0A        ret
@@ -1735,37 +1735,30 @@
      return 
-containerType
+result
 ;%0A    %7D%0A%0A   
@@ -2193,100 +2193,147 @@
 lic 
-int hashCode() %7B%0A        int result = containerType.hashCode();%0A        result = 31 * result
+String toString() %7B%0A        return %22SurveyDetail%7B%22 +%0A                %22containerType=%22 + containerType +%0A                %22, totalContainer=%22
  + t
@@ -2337,33 +2337,34 @@
 + totalContainer
-;
+ +
 %0A        result 
@@ -2356,36 +2356,48 @@
         
-result = 31 * result
+        %22, foundLarvaContainer=%22
  + found
@@ -2402,33 +2402,34 @@
 ndLarvaContainer
-;
+ +
 %0A        return 
@@ -2417,37 +2417,35 @@
 r +%0A        
-return result
+        '%7D'
 ;%0A    %7D%0A%0A   

Rearrange SurveyDetail