package org.batfish.representation.juniper;

import org.batfish.datamodel.Ip;
import org.batfish.datamodel.LineAction;
import org.batfish.datamodel.Prefix;
import org.batfish.datamodel.RouteFilterList;
import org.batfish.datamodel.SubRange;

public final class Route4FilterLineThrough extends Route4FilterLine {

  private static final long serialVersionUID = 1L;

  private final Prefix _throughPrefix;

  public Route4FilterLineThrough(Prefix prefix, Prefix throughPrefix) {
    super(prefix);
    _throughPrefix = throughPrefix;
  }

  @Override
  public void applyTo(RouteFilterList rfl) {
    int low = _prefix.getPrefixLength();
    int high = _throughPrefix.getPrefixLength();
    for (int i = low; i <= high; i++) {
      Ip currentNetworkAddress = _throughPrefix.getStartIp().getNetworkAddress(i);
      Prefix currentPrefix = Prefix.create(currentNetworkAddress, i);
      org.batfish.datamodel.RouteFilterLine line =
          new org.batfish.datamodel.RouteFilterLine(
              LineAction.PERMIT, currentPrefix, new SubRange(i, i));
      rfl.addLine(line);
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    } else if (!(o instanceof Route4FilterLineThrough)) {
      return false;
    }

    Route4FilterLineThrough rhs = (Route4FilterLineThrough) o;
    return _prefix.equals(rhs._prefix) && _throughPrefix.equals(rhs._throughPrefix);
  }

  public Prefix getThroughPrefix() {
    return _throughPrefix;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + _throughPrefix.hashCode();
    result = prime * result + _prefix.hashCode();
    return result;
  }
}

@@ -685,126 +685,89 @@
     
-for (int i = low; i %3C= high; i++) %7B%0A      Ip currentNetworkAddress = _throughPrefix.getStartIp().getNetworkAddress(i);
+Ip startIp = _throughPrefix.getStartIp();%0A    for (int i = low; i %3C= high; i++) %7B
 %0A   
@@ -810,29 +810,15 @@
 ate(
-currentNetworkAddress
+startIp
 , i)

delete unnecessary getNetworkAddress (#3875)