IpTablesVendorConfiguration: support immutable datamodel in builder
package org.batfish.representation.iptables;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import java.util.Collections;
import java.util.IdentityHashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -17,9 +18,7 @@ import org.batfish.datamodel.ConfigurationFormat;
import org.batfish.datamodel.Interface;
import org.batfish.datamodel.IpAccessList;
import org.batfish.datamodel.IpAccessListLine;
-import org.batfish.datamodel.IpWildcard;
import org.batfish.datamodel.LineAction;
-import org.batfish.datamodel.SubRange;
import org.batfish.vendor.VendorConfiguration;
public class IptablesVendorConfiguration extends IptablesConfiguration {
@@ -179,12 +178,11 @@ public class IptablesVendorConfiguration extends IptablesConfiguration {
switch (match.getMatchType()) {
case DESTINATION:
- IpWildcard dstWildCard = match.toIpWildcard();
- aclLine.getDstIps().add(dstWildCard);
+ aclLine.setDstIps(
+ Iterables.concat(aclLine.getDstIps(), Collections.singleton(match.toIpWildcard())));
break;
case DESTINATION_PORT:
- List<SubRange> dstPortRanges = match.toPortRanges();
- aclLine.getDstPorts().addAll(dstPortRanges);
+ aclLine.setDstPorts(Iterables.concat(aclLine.getDstPorts(), match.toPortRanges()));
break;
case IN_INTERFACE:
_lineInInterfaces.put(aclLine, vc.canonicalizeInterfaceName(match.toInterfaceName()));
@@ -195,15 +193,16 @@ public class IptablesVendorConfiguration extends IptablesConfiguration {
anyInterface = false;
break;
case PROTOCOL:
- aclLine.getIpProtocols().add(match.toIpProtocol());
+ aclLine.setIpProtocols(
+ Iterables.concat(
+ aclLine.getIpProtocols(), Collections.singleton(match.toIpProtocol())));
break;
case SOURCE:
- IpWildcard srcWildCard = match.toIpWildcard();
- aclLine.getSrcIps().add(srcWildCard);
+ aclLine.setSrcIps(
+ Iterables.concat(aclLine.getSrcIps(), Collections.singleton(match.toIpWildcard())));
break;
case SOURCE_PORT:
- List<SubRange> srcPortRanges = match.toPortRanges();
- aclLine.getSrcPorts().addAll(srcPortRanges);
+ aclLine.setSrcPorts(Iterables.concat(aclLine.getSrcPorts(), match.toPortRanges()));
break;
default:
throw new BatfishException("Unknown match type: " + match.getMatchType());
