Example usage for org.apache.commons.lang ArrayUtils toObject

List of usage examples for org.apache.commons.lang ArrayUtils toObject

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toObject.

Prototype

public static Boolean[] toObject(boolean[] array) 

Source Link

Document

Converts an array of primitive booleans to objects.

Usage

From source file:v201109_1.GetRelatedKeywords.java

public static void main(String[] args) {
    try {/*from w  ww. j a va 2s . c  o  m*/
        // Log SOAP XML request and response.
        AdWordsServiceLogger.log();

        // Get AdWordsUser from "~/adwords.properties".
        AdWordsUser user = new AdWordsUser();

        // Get the TargetingIdeaService.
        TargetingIdeaServiceInterface targetingIdeaService = user
                .getService(AdWordsService.V201109_1.TARGETING_IDEA_SERVICE);

        // Create seed keyword.
        Keyword keyword = new Keyword();
        keyword.setText("mars cruise");
        keyword.setMatchType(KeywordMatchType.BROAD);

        // Create selector.
        TargetingIdeaSelector selector = new TargetingIdeaSelector();
        selector.setRequestType(RequestType.IDEAS);
        selector.setIdeaType(IdeaType.KEYWORD);
        selector.setRequestedAttributeTypes(
                new AttributeType[] { AttributeType.CRITERION, AttributeType.AVERAGE_TARGETED_MONTHLY_SEARCHES,
                        AttributeType.CATEGORY_PRODUCTS_AND_SERVICES });

        // Set selector paging (required for targeting idea service).
        Paging paging = new Paging();
        paging.setStartIndex(0);
        paging.setNumberResults(10);
        selector.setPaging(paging);

        // Create related to keyword search parameter.
        RelatedToKeywordSearchParameter relatedToKeywordSearchParameter = new RelatedToKeywordSearchParameter();
        relatedToKeywordSearchParameter.setKeywords(new Keyword[] { keyword });

        // Create keyword match type search parameter to ensure unique results.
        KeywordMatchTypeSearchParameter keywordMatchTypeSearchParameter = new KeywordMatchTypeSearchParameter();
        keywordMatchTypeSearchParameter.setKeywordMatchTypes(new KeywordMatchType[] { KeywordMatchType.BROAD });

        selector.setSearchParameters(
                new SearchParameter[] { relatedToKeywordSearchParameter, keywordMatchTypeSearchParameter });

        // Get related keywords.
        TargetingIdeaPage page = targetingIdeaService.get(selector);

        // Display related keywords.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            for (TargetingIdea targetingIdea : page.getEntries()) {
                Map<AttributeType, Attribute> data = MapUtils.toMap(targetingIdea.getData());
                keyword = (Keyword) ((CriterionAttribute) data.get(AttributeType.CRITERION)).getValue();
                IntegerSetAttribute categories = (IntegerSetAttribute) data
                        .get(AttributeType.CATEGORY_PRODUCTS_AND_SERVICES);
                String categoriesString = "(none)";
                if (categories != null && categories.getValue() != null) {
                    categoriesString = StringUtils.join(ArrayUtils.toObject(categories.getValue()), ", ");
                }
                Long averageMonthlySearches = ((LongAttribute) data
                        .get(AttributeType.AVERAGE_TARGETED_MONTHLY_SEARCHES)).getValue();
                System.out.println("Keyword with text '" + keyword.getText() + "', match type '"
                        + keyword.getMatchType() + "' and average monthly search volume '"
                        + averageMonthlySearches + "' was found with categories: " + categoriesString);
            }
        } else {
            System.out.println("No related keywords were found.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201208.creativesetservice.CreateCreativeSetExample.java

public static void main(String[] args) {
    try {/*from  w  ww.  j av a2  s  .  c  o  m*/
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201208.CREATIVE_SET_SERVICE);

        // Set the ID of the creatives to associate with this set.
        Long masterCreativeId = Long.parseLong("INSERT_MASTER_CREATIVE_ID_HERE");
        Long companionCreativeId = Long.parseLong("INSERT_COMPANION_CREATIVE_ID_HERE");

        CreativeSet creativeSet = new CreativeSet();
        creativeSet.setName("Creative set #" + new Random().nextLong());
        creativeSet.setMasterCreativeId(masterCreativeId);
        creativeSet.setCompanionCreativeIds(new long[] { companionCreativeId });

        // Create the creative set on the server.
        creativeSet = creativeSetService.createCreativeSet(creativeSet);

        if (creativeSet != null) {
            System.out.println("A creative set with ID \"" + creativeSet.getId() + "\", master creative ID \""
                    + creativeSet.getMasterCreativeId() + "\", and companion creative IDs {"
                    + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                    + "} was created.");
        } else {
            System.out.println("No creative sets created.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201208.creativesetservice.GetAllCreativeSetsExample.java

public static void main(String[] args) {
    try {//from   w w w  .j  a va  2s .c  om
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201208.CREATIVE_SET_SERVICE);

        // Set defaults for page and filterStatement.
        CreativeSetPage page = new CreativeSetPage();
        Statement filterStatement = new Statement();
        int offset = 0;

        do {
            // Create a statement to get all creative sets.
            filterStatement.setQuery("LIMIT 500 OFFSET " + offset);

            // Get creative sets by statement.
            page = creativeSetService.getCreativeSetsByStatement(filterStatement);

            if (page.getResults() != null) {
                int i = page.getStartIndex();
                for (CreativeSet creativeSet : page.getResults()) {
                    System.out.println(i + ") Creative set with ID \"" + creativeSet.getId()
                            + "\", master creative ID \"" + creativeSet.getMasterCreativeId()
                            + "\", and companion creative IDs {"
                            + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                            + "} was found.");
                    i++;
                }
            }

            offset += 500;
        } while (offset < page.getTotalResultSetSize());

        System.out.println("Number of results found: " + page.getTotalResultSetSize());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201208.creativesetservice.GetCreativeSetsByStatementExample.java

public static void main(String[] args) {
    try {//from w  w w.ja  v  a  2  s .c o m
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201208.CREATIVE_SET_SERVICE);

        // Set the ID of the master creative to get creative sets for.
        Long masterCreativeId = Long.parseLong("INSERT_MASTER_CREATIVE_ID_HERE");

        // Create statement object to only select creative sets that have the
        // given master creative.
        Statement filterStatement = new StatementBuilder("WHERE masterCreativeId = :masterCreativeId LIMIT 500")
                .putValue("masterCreativeId", masterCreativeId).toStatement();

        // Get creative sets by statement.
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(filterStatement);

        if (page.getResults() != null) {
            int i = page.getStartIndex();
            for (CreativeSet creativeSet : page.getResults()) {
                System.out
                        .println(i + ") Creative set with ID \"" + creativeSet.getId()
                                + "\", master creative ID \"" + creativeSet.getMasterCreativeId()
                                + "\", and companion creative IDs {" + StringUtils
                                        .join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                                + "} was found.");
                i++;
            }
        }

        System.out.println("Number of results found: " + page.getTotalResultSetSize());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201208.creativesetservice.UpdateCreativeSetExample.java

public static void main(String[] args) {
    try {//from   w ww .j a v  a  2 s  .  co m
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201208.CREATIVE_SET_SERVICE);

        // Set the ID of the creative set to get and the companion creative to
        // add.
        Long creativeSetId = Long.parseLong("INSERT_CREATIVE_SET_ID_HERE");
        Long companionCreativeId = Long.parseLong("INSERT_COMPANION_CREATIVE_ID_HERE");

        // Get the creative set.
        CreativeSet creativeSet = creativeSetService.getCreativeSet(creativeSetId);

        // Add the companion creative to the creative set.
        creativeSet.setCompanionCreativeIds(
                ArrayUtils.add(creativeSet.getCompanionCreativeIds(), companionCreativeId));

        // Update the creative set on the server.
        creativeSet = creativeSetService.updateCreativeSet(creativeSet);

        // Display results.
        System.out.println("A creative set with ID \"" + creativeSet.getId() + "\", master creative ID \""
                + creativeSet.getMasterCreativeId() + "\", and companion creative IDs {"
                + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                + "} was updated.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201208.lineitemservice.TargetCustomCriteriaExample.java

/**
 * Gets a string representation of the custom criteria node. If it has
 * children, each child will be appended to the string recursively.
 *
 * @param root the root custom criteria node
 * @param level the level of the custom criteria tree
 * @return a string representation of the custom criteria node and its
 *     children/*  ww w .  j  ava 2 s .c  om*/
 */
private static String getCustomCriteriaSetString(CustomCriteriaNode root, int level) {
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.repeat("\t", level));
    if (root instanceof CustomCriteria) {
        CustomCriteria customCriteria = (CustomCriteria) root;
        sb.append(String.format("Custom criteria: operator: [%s] key: [%s] values: [%s]\n",
                customCriteria.getOperator(), customCriteria.getKeyId(),
                StringUtils.join(ArrayUtils.toObject(customCriteria.getValueIds()), ",")));
        return sb.toString();
    } else if (root instanceof CustomCriteriaSet) {
        CustomCriteriaSet customCriteriaSet = (CustomCriteriaSet) root;
        sb.append(String.format("Custom criteria set: operator: [%s] children: \n",
                customCriteriaSet.getLogicalOperator()));
        for (CustomCriteriaNode node : customCriteriaSet.getChildren()) {
            sb.append(getCustomCriteriaSetString(node, level + 1));
        }
        return sb.append("\n").toString();
    } else {
        throw new IllegalStateException("Unexpected node: " + root);
    }
}

From source file:v201211.creativesetservice.CreateCreativeSetExample.java

public static void main(String[] args) {
    try {/*from www.ja v a2 s .  c  o m*/
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201211.CREATIVE_SET_SERVICE);

        // Set the ID of the creatives to associate with this set.
        Long masterCreativeId = Long.parseLong("INSERT_MASTER_CREATIVE_ID_HERE");
        Long companionCreativeId = Long.parseLong("INSERT_COMPANION_CREATIVE_ID_HERE");

        CreativeSet creativeSet = new CreativeSet();
        creativeSet.setName("Creative set #" + new Random().nextLong());
        creativeSet.setMasterCreativeId(masterCreativeId);
        creativeSet.setCompanionCreativeIds(new long[] { companionCreativeId });

        // Create the creative set on the server.
        creativeSet = creativeSetService.createCreativeSet(creativeSet);

        if (creativeSet != null) {
            System.out.println("A creative set with ID \"" + creativeSet.getId() + "\", master creative ID \""
                    + creativeSet.getMasterCreativeId() + "\", and companion creative IDs {"
                    + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                    + "} was created.");
        } else {
            System.out.println("No creative sets created.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201211.creativesetservice.GetAllCreativeSetsExample.java

public static void main(String[] args) {
    try {//w  w  w  .ja va 2s  .  co  m
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201211.CREATIVE_SET_SERVICE);

        // Set defaults for page and filterStatement.
        CreativeSetPage page = new CreativeSetPage();
        Statement filterStatement = new Statement();
        int offset = 0;

        do {
            // Create a statement to get all creative sets.
            filterStatement.setQuery("LIMIT 500 OFFSET " + offset);

            // Get creative sets by statement.
            page = creativeSetService.getCreativeSetsByStatement(filterStatement);

            if (page.getResults() != null) {
                int i = page.getStartIndex();
                for (CreativeSet creativeSet : page.getResults()) {
                    System.out.println(i + ") Creative set with ID \"" + creativeSet.getId()
                            + "\", master creative ID \"" + creativeSet.getMasterCreativeId()
                            + "\", and companion creative IDs {"
                            + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                            + "} was found.");
                    i++;
                }
            }

            offset += 500;
        } while (offset < page.getTotalResultSetSize());

        System.out.println("Number of results found: " + page.getTotalResultSetSize());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201211.creativesetservice.GetCreativeSetsByStatementExample.java

public static void main(String[] args) {
    try {//ww  w  . ja v a2s.  c o m
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201211.CREATIVE_SET_SERVICE);

        // Set the ID of the master creative to get creative sets for.
        Long masterCreativeId = Long.parseLong("INSERT_MASTER_CREATIVE_ID_HERE");

        // Create statement object to only select creative sets that have the
        // given master creative.
        Statement filterStatement = new StatementBuilder("WHERE masterCreativeId = :masterCreativeId LIMIT 500")
                .putValue("masterCreativeId", masterCreativeId).toStatement();

        // Get creative sets by statement.
        CreativeSetPage page = creativeSetService.getCreativeSetsByStatement(filterStatement);

        if (page.getResults() != null) {
            int i = page.getStartIndex();
            for (CreativeSet creativeSet : page.getResults()) {
                System.out
                        .println(i + ") Creative set with ID \"" + creativeSet.getId()
                                + "\", master creative ID \"" + creativeSet.getMasterCreativeId()
                                + "\", and companion creative IDs {" + StringUtils
                                        .join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                                + "} was found.");
                i++;
            }
        }

        System.out.println("Number of results found: " + page.getTotalResultSetSize());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:v201211.creativesetservice.UpdateCreativeSetExample.java

public static void main(String[] args) {
    try {//w  ww . ja v a 2  s  .  com
        // Log SOAP XML request and response.
        DfpServiceLogger.log();

        // Get DfpUser from "~/dfp.properties".
        DfpUser user = new DfpUser();

        // Get the CreativeSetService.
        CreativeSetServiceInterface creativeSetService = user
                .getService(DfpService.V201211.CREATIVE_SET_SERVICE);

        // Set the ID of the creative set to get and the companion creative to
        // add.
        Long creativeSetId = Long.parseLong("INSERT_CREATIVE_SET_ID_HERE");
        Long companionCreativeId = Long.parseLong("INSERT_COMPANION_CREATIVE_ID_HERE");

        // Get the creative set.
        CreativeSet creativeSet = creativeSetService.getCreativeSet(creativeSetId);

        // Add the companion creative to the creative set.
        creativeSet.setCompanionCreativeIds(
                ArrayUtils.add(creativeSet.getCompanionCreativeIds(), companionCreativeId));

        // Update the creative set on the server.
        creativeSet = creativeSetService.updateCreativeSet(creativeSet);

        // Display results.
        System.out.println("A creative set with ID \"" + creativeSet.getId() + "\", master creative ID \""
                + creativeSet.getMasterCreativeId() + "\", and companion creative IDs {"
                + StringUtils.join(ArrayUtils.toObject(creativeSet.getCompanionCreativeIds()), ',')
                + "} was updated.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}