@Override public QueryTemplatePacket and(UnionTemplatePacket template){
  LinkedList<QueryTemplatePacket> optimizedPackets=new LinkedList<QueryTemplatePacket>();
  for (  QueryTemplatePacket packet : getPackets()) {
    for (    QueryTemplatePacket packet2 : template.getPackets()) {
      QueryTemplatePacket newPacket=new QueryTemplatePacket(packet);
      newPacket.intersectRanges(packet2);
      newPacket.intersectUids(packet2);
      if (!newPacket.isAlwaysEmpty())       optimizedPackets.add(newPacket);
    }
  }
  setPackets(optimizedPackets);
  if (optimizedPackets.isEmpty())   setAlwaysEmpty(true);
  return this;
}

@ Override public QueryTemplatePacket and ( UnionTemplatePacket template ) { LinkedList < QueryTemplatePacket > optimizedPackets = new LinkedList < QueryTemplatePacket > ( ) ; for ( QueryTemplatePacket packet : getPackets ( ) ) { for ( QueryTemplatePacket packet2 : template . getPackets ( ) ) { QueryTemplatePacket newPacket = new QueryTemplatePacket ( packet ) ; newPacket . intersectRanges ( packet2 ) ; newPacket . intersectUids ( packet2 ) ; if ( ! newPacket . isAlwaysEmpty ( ) ) optimizedPackets . add ( newPacket ) ; } } setPackets ( optimizedPackets ) ; if ( optimizedPackets . isEmpty ( ) ) setAlwaysEmpty ( true ) ; return this ; }
merge given templates into one template . for example : ( w = 3 or x = 5 ) and ( y = 5 or z = 8 ) = = > ( w = 3 and ( y = 5 or z = 8 ) ) or ( x = 5 and ( y = 5 or z = 8 ) ) = = > ( ( w = 3 and y = 5 ) or ( w = 3 and z = 8 ) ) or ( ( x = 5 and y = 5 ) or ( x = 5 or z = 8 ) )
