public void FindParentClusters(TrafficCluster TCluster) {
    Iterator<Entry<Long, TrafficCluster>> ClusterIterator = BaseClusters.entrySet().iterator();
    TrafficCluster TempBaseCluster;
    while (ClusterIterator.hasNext()) {
      boolean IsParent = false;
      Map.Entry<Long, TrafficCluster> BaseClusterEntry =
          (Map.Entry<Long, TrafficCluster>) ClusterIterator.next();
      TempBaseCluster = BaseClusterEntry.getValue();
      IsParent =
          TrafficCluster.CompareTwoNwAddr(
                  TempBaseCluster.MatchOnSrcIP,
                  TempBaseCluster.SrcIPMatch,
                  TempBaseCluster.SrcMask,
                  TCluster.SrcIPMatch)
              && TrafficCluster.CompareTwoNwAddr(
                  TempBaseCluster.MatchOnDstIP,
                  TempBaseCluster.DstIPMatch,
                  TempBaseCluster.DstMask,
                  TCluster.DstIPMatch)
              && TrafficCluster.CheckPortMatches(
                  TempBaseCluster, TCluster.SrcPort, TCluster.DstPort)
              && TrafficCluster.CheckProtocolMatches(
                  TempBaseCluster.MatchOnProtocol, TempBaseCluster.Protocol, TCluster.Protocol);

      if (IsParent == true) {
        TCluster.ParentClusterIDs.add(TempBaseCluster.ClusterID);
      }
    }
  }
 private void FinishBaseClusterCt() {
   Iterator<Entry<Long, TrafficCluster>> ClusterIterator = BaseClusters.entrySet().iterator();
   TrafficCluster TempCluster;
   while (ClusterIterator.hasNext()) {
     Map.Entry<Long, TrafficCluster> Cluster =
         (Map.Entry<Long, TrafficCluster>) ClusterIterator.next();
     TempCluster = Cluster.getValue();
     TempCluster.AdjustBaseClusterCount();
     if ((this.TotalPacketCount > 0) && (this.TotalByteCount > 0)) {
       TempCluster.CalculateContribution(this.TotalPacketCount, this.TotalByteCount);
     }
   }
 }
  private void UpdateClusterStat() {

    TrafficCluster VolatileCluster;
    long TempTotalPacketCount = 0;
    double TempTotalByteCount = 0.0;
    for (StatResult result : this.ClusterStats) {
      VolatileCluster = UniqueClusters.get(result.ClusterID);
      if (VolatileCluster != null) {
        TempTotalPacketCount += result.PacketCount;
        TempTotalByteCount += result.ByteCount;
        VolatileCluster.UpdateCount(result.PacketCount, result.ByteCount);
        InitBaseClusterCt(VolatileCluster.ParentClusterIDs, result.PacketCount, result.ByteCount);
      } else {
        System.out.println("SOMETHING WENT WRONG");
        break;
      }
    }
    this.ClusterStats.clear();
    this.TotalPacketCount = TempTotalPacketCount;
    this.TotalByteCount = TempTotalByteCount;
    this.FinishBaseClusterCt();

    // doing a second loop to update the contribution of each cluster relative the so far total
    // counts
    // Will see if we can skip this second loop
    if ((this.TotalPacketCount > 0) && (this.TotalByteCount > 0)) {
      Iterator<Entry<Long, TrafficCluster>> ClusterIterator = UniqueClusters.entrySet().iterator();
      TrafficCluster TempCluster;
      while (ClusterIterator.hasNext()) {
        Map.Entry<Long, TrafficCluster> Cluster =
            (Map.Entry<Long, TrafficCluster>) ClusterIterator.next();
        TempCluster = Cluster.getValue();
        TempCluster.CalculateContribution(this.TotalPacketCount, this.TotalByteCount);
        if (TempCluster.IsBaseType == true) {
          this.CopyFromCluster(TempCluster);
        }
      }
    }
  }
 public void CopyFromCluster(TrafficCluster TCluster) {
   if (TCluster.AddedToBase == false) {
     TrafficCluster NewBase =
         new TrafficCluster(
             new int[] {TCluster.SrcIPMatch, 4},
             new int[] {TCluster.DstIPMatch, 4},
             new short[] {TCluster.SrcPort},
             new short[] {TCluster.DstPort},
             TCluster.Protocol,
             this.BaseID);
     BaseClusters.put(NewBase.ClusterID, NewBase);
     TCluster.AddedToBase = true;
     TCluster.ParentClusterIDs.add(NewBase.ClusterID);
     this.BaseID++;
   }
 }