/**
   * Gets the set of feed item IDs from the function if it is of the form: <code>
   * IN(FEED_ITEM_ID,{xxx,xxx})</code>. Otherwise, returns an empty set.
   */
  private static Set<Long> getFeedItemIdsFromArgument(Function function) {
    Set<Long> feedItemIds = Sets.newHashSet();

    if (function.getLhsOperand().length == 1
        && function.getLhsOperand(0) instanceof RequestContextOperand) {
      RequestContextOperand requestContextOperand =
          (RequestContextOperand) function.getLhsOperand(0);
      if (RequestContextOperandContextType.FEED_ITEM_ID.equals(
              requestContextOperand.getContextType())
          && FunctionOperator.IN.equals(function.getOperator())) {
        for (FunctionArgumentOperand argument : function.getRhsOperand()) {
          if (argument instanceof ConstantOperand) {
            feedItemIds.add(((ConstantOperand) argument).getLongValue());
          }
        }
      }
    }

    return feedItemIds;
  }
  /** Gets the platform restrictions for sitelinks in a campaign. */
  private static ExtensionSettingPlatform getPlatformRestictionsForCampaign(
      CampaignFeed campaignFeed) {
    String platformRestrictions = ExtensionSettingPlatform.NONE.getValue();

    if (FunctionOperator.AND.equals(campaignFeed.getMatchingFunction().getOperator())) {
      for (FunctionArgumentOperand argument : campaignFeed.getMatchingFunction().getLhsOperand()) {
        if (argument instanceof FunctionOperand) {
          FunctionOperand operand = (FunctionOperand) argument;
          if (FunctionOperator.EQUALS.equals(operand.getValue().getOperator())
              && (operand.getValue().getLhsOperand(0) instanceof RequestContextOperand)) {
            RequestContextOperand requestContextOperand =
                (RequestContextOperand) operand.getValue().getLhsOperand(0);
            if (RequestContextOperandContextType.DEVICE_PLATFORM.equals(
                requestContextOperand.getContextType())) {
              platformRestrictions =
                  ((ConstantOperand) operand.getValue().getRhsOperand(0)).getStringValue();
            }
          }
        }
      }
    }
    return ExtensionSettingPlatform.fromString(platformRestrictions.toUpperCase());
  }