Example usage for com.google.common.collect Multimaps index

List of usage examples for com.google.common.collect Multimaps index

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps index.

Prototype

public static <K, V> ImmutableListMultimap<K, V> index(Iterator<V> values, Function<? super V, K> keyFunction) 

Source Link

Document

Creates an index ImmutableListMultimap that contains the results of applying a specified function to each item in an Iterator of values.

Usage

From source file:org.opentestsystem.authoring.testauth.publish.BasePublisherHelper.java

private List<ItemReferenceGroup> buildItemReferenceGroups(final String bankKey,
        final Map<String, Segment> segmentMap, final Assessment assessment, final List<Item> itemList,
        final String locationId, final boolean processSegmentLevel) {

    // find any/all existing itemGroups by segmentId/formPartitionId, build into multimap keyed by itemGroupId
    final List<ItemGroup> itemGroupList = processSegmentLevel
            ? this.itemGroupService.getItemGroupsBySegment(locationId)
            : this.itemGroupService.getItemGroupsFormPartition(locationId);
    final ListMultimap<String, ItemGroup> existingItemGroupMap = Multimaps.index(itemGroupList,
            ITEMGROUPID_KEY_TRANSFORMER);

    // returns map w/ key of segmentId/formPartitionId and value of item list
    final Map<String, List<Item>> itemsMap = processSegmentLevel
            ? retrieveScopedItems(assessment.getId(), itemList, locationId, false)
            : retrieveScopedItems(assessment.getId(), itemList, null, true);
    // scope by just location Id (instead of summed partitions per segment)
    final List<Item> flattenedItemList = processSegmentLevel
            ? Lists.newArrayList(Iterables.concat(itemsMap.values()))
            : itemsMap.get(locationId);//from  w w w .j a  v  a  2  s.  co m

    // item can belong to more than one group or 'NO_GROUP'; attempt to invert the relationship to construct
    // a) map w/ key of item group & value of list of items
    // b) list of lone-wolf 'NO_GROUP' items for which an ItemReferenceGroup will be later fabricated
    final Multimap<List<String>, Item> groupedMultiMap = Multimaps.index(flattenedItemList,
            ITEM_ITEMGROUPIDLIST_TRANSFORMER);

    final Map<ItemGroup, List<Item>> groupedItemMap = Maps.newHashMap();
    final Set<Item> ungroupedItemSet = Sets.newHashSet();
    for (final Entry<List<String>, Item> itemGrouping : groupedMultiMap.entries()) {
        for (final String itemGroupingKey : itemGrouping.getKey()) {
            if (StringUtils.equals(itemGroupingKey, Item.SKIP_GROUP_KEY)) {

            } else if (!StringUtils.equals(itemGroupingKey, Item.NO_GROUP_KEY)) {
                ItemGroup itemGroup = null;
                if (!CollectionUtils.isEmpty(existingItemGroupMap.get(itemGroupingKey))) {
                    itemGroup = existingItemGroupMap.get(itemGroupingKey).get(0);
                }
                if (itemGroup != null) {
                    if (CollectionUtils.isEmpty(groupedItemMap.get(itemGroup))) {
                        final List<Item> itemsPerItemGroupList = Lists.newArrayList();
                        groupedItemMap.put(itemGroup, itemsPerItemGroupList);
                    }
                    groupedItemMap.get(itemGroup).add(itemGrouping.getValue());
                }
            } else if (Iterables.any(itemGrouping.getValue().getAdaptiveAndFixedItemLocations(),
                    PublisherUtil.ITEM_LOCATION_MATCHER.getInstance(Item.NO_GROUP_KEY, locationId,
                            processSegmentLevel ? ItemGroupLocationType.SEGMENT
                                    : ItemGroupLocationType.FORM_PARTITION))) {
                ungroupedItemSet.add(itemGrouping.getValue());
            }
        }
    }

    // transform grouped
    // note that segmentMap parameter is null in case processSegmentLevel parameter was true

    final List<ItemReferenceGroup> groupedItems = nullsafeListTransform(groupedItemMap.entrySet(),
            ITEMLIST_ITEMGROUP_TRANSFORMER.getInstance(bankKey, segmentMap, this.serverUniqueNumber,
                    assessment.getVersion()));

    // transform ungrouped
    final List<ItemReferenceGroup> ungroupedItems = nullsafeListTransform(ungroupedItemSet,
            ITEM_ITEMGROUP_TRANSFORMER.getInstance(processSegmentLevel, locationId, bankKey,
                    this.serverUniqueNumber, assessment.getVersion()));

    return Lists.newArrayList(Iterables.concat(ungroupedItems, groupedItems));
}

From source file:org.opentestsystem.authoring.testauth.publish.BasePublisherHelper.java

protected Map<String, Collection<TestComputationRule>> buildScoringRuleReferenceMap(
        final List<TestComputationRule> testComputationRuleList) {
    return Multimaps.index(testComputationRuleList, COMPRULE_MULTIMAP_TRANSFORMER).asMap();
}

From source file:org.opencms.configuration.CmsWorkplaceConfiguration.java

/**
 * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
 *//*from  ww  w.j av  a  2 s.co  m*/
public Element generateXml(Element parent) {

    // generate workplace node and subnodes
    Element workplaceElement = parent.addElement(N_WORKPLACE);
    // add default locale
    workplaceElement.addElement(N_DEFAULTLOCALE).setText(m_workplaceManager.getDefaultLocale().toString());

    // add <localizedfolders> subnode
    Element localizedElement = workplaceElement.addElement(N_LOCALIZEDFOLDERS);
    Iterator<String> localizedIterator = m_workplaceManager.getLocalizedFolders().iterator();
    while (localizedIterator.hasNext()) {
        // add <resource uri=""/> element(s)
        localizedElement.addElement(N_RESOURCE).addAttribute(A_URI, localizedIterator.next());
    }

    // add <dialoghandlers> subnode
    Element dialogElement = workplaceElement.addElement(N_DIALOGHANDLERS);
    Map<String, I_CmsDialogHandler> dialogs = m_workplaceManager.getDialogHandler();
    String[] keys = dialogs.keySet().toArray(new String[0]);
    Arrays.sort(keys);
    for (int j = 0; j < keys.length; j++) {
        String name = keys[j];
        // add <dialoghandler> subnode with class attribute
        Element dialogHandler = dialogElement.addElement(N_DIALOGHANDLER).addAttribute(A_CLASS,
                dialogs.get(name).getClass().getName());
        I_CmsDialogHandler daialogHandlerConfig = dialogs.get(name);
        CmsParameterConfiguration handlerConfig = daialogHandlerConfig.getConfiguration();
        if (handlerConfig != null) {
            handlerConfig.appendToXml(dialogHandler);
        }
    }

    // add miscellaneous editor subnodes
    workplaceElement.addElement(N_EDITORHANDLER).addAttribute(A_CLASS,
            m_workplaceManager.getEditorHandler().getClass().getName());
    workplaceElement.addElement(N_EDITORACTION).addAttribute(A_CLASS,
            m_workplaceManager.getEditorActionHandler().getClass().getName());

    if (m_workplaceManager.getEditorCssHandlers().size() > 0) {
        Element editorCssHandlers = workplaceElement.addElement(N_EDITORCSSHANDLERS);
        Iterator<I_CmsEditorCssHandler> it = m_workplaceManager.getEditorCssHandlers().iterator();
        while (it.hasNext()) {
            I_CmsEditorCssHandler current = it.next();
            Element handler = editorCssHandlers.addElement(N_EDITORCSSHANDLER);
            handler.addAttribute(A_CLASS, current.getClass().getName());
        }
    }

    if (m_workplaceManager.getPreEditorConditionDefinitions().size() > 0) {
        Element editorPreActions = workplaceElement.addElement(N_EDITORPRECONDITIONS);
        Iterator<I_CmsPreEditorActionDefinition> it = m_workplaceManager.getPreEditorConditionDefinitions()
                .iterator();
        while (it.hasNext()) {
            I_CmsPreEditorActionDefinition current = it.next();
            Element action = editorPreActions.addElement(N_EDITORPRECONDITION);
            action.addAttribute(A_NAME, current.getResourceTypeName());
            action.addAttribute(A_CLASS, current.getClass().getName());
            // get the configuration parameters
            CmsParameterConfiguration config = current.getConfiguration();
            if ((config != null) && (config.size() > 0)) {
                // append the configuration parameters
                config.appendToXml(action);
            }
        }
    }

    I_CmsConfigurationParameterHandler deProvider = m_workplaceManager.getDirectEditProvider();
    Element deProviderNode = workplaceElement.addElement(N_DIRECTEDITPROVIDER).addAttribute(A_CLASS,
            deProvider.getClass().getName());
    CmsParameterConfiguration deProviderConfig = deProvider.getConfiguration();
    if (deProviderConfig != null) {
        deProviderConfig.appendToXml(deProviderNode);
    }

    // add <exportpoints> subnode
    Element resourceloadersElement = workplaceElement.addElement(N_EXPORTPOINTS);
    Set<CmsExportPoint> points = m_workplaceManager.getExportPoints();
    Iterator<CmsExportPoint> exportPoints = points.iterator();
    while (exportPoints.hasNext()) {
        CmsExportPoint point = exportPoints.next();
        resourceloadersElement.addElement(N_EXPORTPOINT).addAttribute(A_URI, point.getUri())
                .addAttribute(A_DESTINATION, point.getConfiguredDestination());
    }

    // add miscellaneous configuration nodes
    workplaceElement.addElement(N_AUTOLOCK).setText(String.valueOf(m_workplaceManager.autoLockResources()));
    String acaciaUnlock = m_workplaceManager.getAcaciaUnlock();
    if (acaciaUnlock != null) {
        workplaceElement.addElement(N_ACACIA_UNLOCK).setText(acaciaUnlock);
    }

    workplaceElement.addElement(N_XMLCONTENTAUTOCORRECTION)
            .setText(String.valueOf(m_workplaceManager.isXmlContentAutoCorrect()));
    workplaceElement.addElement(N_ENABLEUSERMGMT)
            .setText(String.valueOf(m_workplaceManager.showUserGroupIcon()));
    workplaceElement.addElement(N_DEFAULTPROPERTIESONSTRUCTURE)
            .setText(String.valueOf(m_workplaceManager.isDefaultPropertiesOnStructure()));
    workplaceElement.addElement(N_ENABLEADVANCEDPROPERTYTABS)
            .setText(String.valueOf(m_workplaceManager.isEnableAdvancedPropertyTabs()));

    // add <categoryfolder> node
    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_workplaceManager.getCategoryFolder())
            && !CmsCategoryService.REPOSITORY_BASE_FOLDER.equals(m_workplaceManager.getCategoryFolder())) {
        workplaceElement.addElement(N_CATEGORYFOLDER)
                .setText(String.valueOf(m_workplaceManager.getCategoryFolder()));
    }

    String groupTranslationClass = m_workplaceManager.getGroupTranslationClass();
    if (groupTranslationClass != null) {
        Element groupTranslationElement = workplaceElement.addElement(N_GROUP_TRANSLATION);
        groupTranslationElement.addAttribute(A_CLASS, groupTranslationClass);
    }

    workplaceElement.addElement(N_MAXUPLOADSIZE)
            .setText(String.valueOf(m_workplaceManager.getFileMaxUploadSize()));

    // add <labeledfolders> resource list
    Element labeledElement = workplaceElement.addElement(N_LABELEDFOLDERS);
    Iterator<String> sitesFolders = m_workplaceManager.getLabelSiteFolders().iterator();
    while (sitesFolders.hasNext()) {
        labeledElement.addElement(N_RESOURCE).addAttribute(A_URI, sitesFolders.next());
    }
    // add the <galleryupload> node
    workplaceElement.addElement(N_REPOSITORY_FOLDER).addAttribute(A_CLASS,
            m_workplaceManager.getRepositoryFolderHandler().getClass().getName());

    // add <rfsfileviewsettings> node
    CmsRfsFileViewer viewSettings = m_workplaceManager.getFileViewSettings();
    Element fileViewElement = workplaceElement.addElement(N_RFSFILEVIEWESETTINGS);
    String rootPath = viewSettings.getRootPath();
    if (rootPath != null) {
        fileViewElement.addElement(N_ROOTPATH).setText(rootPath);
    }
    String filePath = viewSettings.getFilePath();
    if (filePath != null) {
        fileViewElement.addElement(N_FILEPATH).setText(filePath);
    }
    fileViewElement.addElement(N_ENABLED).setText(String.valueOf(viewSettings.isEnabled()));
    fileViewElement.addElement(N_FILEENCODING).setText(viewSettings.getFileEncoding());
    fileViewElement.addElement(N_ISLOGFILE).setText(String.valueOf(viewSettings.getIsLogfile()));
    fileViewElement.addElement(N_WINDOWSIZE).setText(String.valueOf(viewSettings.getWindowSize()));

    // add <explorertypes> node
    Element explorerTypesElement = workplaceElement.addElement(N_EXPLORERTYPES);
    List<CmsExplorerTypeSettings> explorerTypes = m_workplaceManager.getExplorerTypeSettings();
    generateExplorerTypesXml(explorerTypesElement, explorerTypes, false);

    // add the <defaultaccesscontrol> node
    Element defaultAccessControlElement = explorerTypesElement.addElement(N_DEFAULTACCESSCONTROL);
    // create subnode <accesscontrol>
    List<String> accessEntries = new ArrayList<String>();
    // sort accessEntries
    CmsExplorerTypeAccess access = m_workplaceManager.getDefaultAccess();
    Iterator<String> iter = access.getAccessEntries().keySet().iterator();
    while (iter.hasNext()) {
        accessEntries.add(iter.next());
    }
    Collections.sort(accessEntries);

    if (accessEntries.size() > 0) {
        Element accessControlElement = defaultAccessControlElement.addElement(N_ACCESSCONTROL);
        Iterator<String> k = accessEntries.iterator();

        while (k.hasNext()) {
            String key = k.next();
            String value = m_workplaceManager.getDefaultAccess().getAccessEntries().get(key);
            Element accessEntryElement = accessControlElement.addElement(N_ACCESSENTRY);
            accessEntryElement.addAttribute(A_PRINCIPAL, key);
            accessEntryElement.addAttribute(A_PERMISSIONS, value);
        }
    }

    // add the <multicontextmenu> node
    Iterator<CmsExplorerContextMenuItem> menuEntries = m_workplaceManager.getMultiContextMenu().getAllEntries()
            .iterator();
    if (menuEntries.hasNext()) {
        // only generate the node if entries are defined
        Element contextMenuElement = explorerTypesElement.addElement(N_MULTICONTEXTMENU);
        // get the menu rule translator to eliminate eventual legacy menu rules
        CmsMenuRuleTranslator menuRuleTranslator = new CmsMenuRuleTranslator();
        while (menuEntries.hasNext()) {
            CmsExplorerContextMenuItem item = menuEntries.next();
            generateContextMenuItemXml(contextMenuElement, menuRuleTranslator, item);
        }
    }

    // add <menurules> node and subnodes
    if (m_workplaceManager.getMenuRules().size() > 0) {
        Element rulesElement = explorerTypesElement.addElement(N_MENURULES);
        Iterator<CmsMenuRule> menuRules = m_workplaceManager.getMenuRules().iterator();
        while (menuRules.hasNext()) {
            // create a <menurule> element for each rule set
            CmsMenuRule rule = menuRules.next();
            Element ruleElement = rulesElement.addElement(N_MENURULE);
            ruleElement.addAttribute(A_NAME, rule.getName());
            Iterator<I_CmsMenuItemRule> it = rule.getMenuItemRules().iterator();
            while (it.hasNext()) {
                // create a <menuitemrule> element for each configured item rule
                I_CmsMenuItemRule itemRule = it.next();
                Element itemRuleElement = ruleElement.addElement(N_MENUITEMRULE);
                itemRuleElement.addAttribute(A_CLASS, itemRule.getClass().getName());
            }
        }
    }

    // add the user-infos node
    if (m_workplaceManager.getUserInfoManager() != null) {
        Element userInfosElement = workplaceElement.addElement(N_USERINFOS);
        Iterator<CmsWorkplaceUserInfoBlock> infoBlocks = m_workplaceManager.getUserInfoManager().getBlocks()
                .iterator();
        while (infoBlocks.hasNext()) {
            CmsWorkplaceUserInfoBlock block = infoBlocks.next();
            Element infoBlockElement = userInfosElement.addElement(N_INFOBLOCK);
            infoBlockElement.addAttribute(A_NAME, block.getTitle());

            Iterator<CmsWorkplaceUserInfoEntry> itEntries = block.getEntries().iterator();
            while (itEntries.hasNext()) {
                CmsWorkplaceUserInfoEntry entry = itEntries.next();
                Element userInfoElement = infoBlockElement.addElement(N_USERINFO);
                userInfoElement.addAttribute(A_KEY, entry.getKey());
                if (entry.getType() != null) {
                    userInfoElement.addAttribute(A_TYPE, entry.getType());
                }
                if (entry.getWidget() != null) {
                    userInfoElement.addAttribute(A_WIDGET, entry.getWidget());
                }
                if (entry.getParams() != null) {
                    userInfoElement.addAttribute(A_PARAMS, entry.getParams());
                }
                if (entry.getOptional() != null) {
                    userInfoElement.addAttribute(A_OPTIONAL, entry.getOptional());
                }
            }
        }
    }

    List<CmsAccountInfo> accountInfos = m_workplaceManager.getConfiguredAccountInfos();
    if (accountInfos != null) {
        Element infosElement = workplaceElement.addElement(N_ACCOUNTINFOS);
        for (CmsAccountInfo info : accountInfos) {
            Element infoElement = infosElement.addElement(N_ACCOUNTINFO);
            infoElement.addAttribute(A_FIELD, info.getField().name());
            if (info.isAdditionalInfo()) {
                infoElement.addAttribute(A_ADD_INFO_KEY, info.getAddInfoKey());
            }
            infoElement.addAttribute(A_EDITABLE, Boolean.toString(info.isEditable()));
        }
    }

    // add the <default-preferences> user settings main node
    Element defaultPreferences = workplaceElement.addElement(N_DEFAULTPREFERENCES);

    Multimap<String, I_CmsPreference> prefsByTab = Multimaps.index(
            m_workplaceManager.getDefaultUserSettings().getPreferences().values(),
            new Function<I_CmsPreference, String>() {

                public String apply(I_CmsPreference input) {

                    return input.getTab();
                }
            });

    for (String tabName : new String[] { CmsGwtConstants.TAB_BASIC, CmsGwtConstants.TAB_EXTENDED,
            CmsGwtConstants.TAB_HIDDEN }) {
        Element preferenceTab = defaultPreferences.addElement(N_PREFERENCE_TAB).addAttribute("name", tabName);
        for (I_CmsPreference pref : prefsByTab.get(tabName)) {
            Element elem = pref.createConfigurationItem();
            if (elem != null) {
                preferenceTab.add(elem);
            }
        }
    }

    if (m_workplaceManager.getCustomFoot() != null) {
        // add the <workplace-footcustom> node
        Element workplaceFootCustom = workplaceElement.addElement(N_WORKPLACECUSTOMFOOT);
        workplaceFootCustom.addElement(N_COLOR).setText(m_workplaceManager.getCustomFoot().getColor());
        workplaceFootCustom.addElement(N_BACKGROUNDCOLOR)
                .setText(m_workplaceManager.getCustomFoot().getBackgroundColor());
        Element textElement = workplaceFootCustom.addElement(N_TEXT);
        textElement.addAttribute(A_REPLACE,
                Boolean.toString(m_workplaceManager.getCustomFoot().isReplaceDefault()));
        textElement.setText(m_workplaceManager.getCustomFoot().getText());
    }

    // add the tool-manager node
    Element toolManagerElement = workplaceElement.addElement(N_TOOLMANAGER);
    Element rootsElement = toolManagerElement.addElement(N_ROOTS);
    Iterator<CmsToolRootHandler> it = m_workplaceManager.getToolManager().getToolRoots().iterator();
    while (it.hasNext()) {
        CmsToolRootHandler root = it.next();
        Element rootElement = rootsElement.addElement(N_ROOT);
        rootElement.addElement(N_KEY).addText(root.getKey());
        rootElement.addElement(N_URI).addText(root.getUri());
        rootElement.addElement(N_NAME).addText(root.getName());
        rootElement.addElement(N_HELPTEXT).addText(root.getHelpText());
    }
    String userListsMode = m_workplaceManager.getUserListModeString();
    if (userListsMode != null) {
        Element userListsElem = workplaceElement.addElement(N_USER_LISTS);
        userListsElem.addAttribute(A_MODE, userListsMode);
    }

    Boolean keepAlive = m_workplaceManager.isKeepAlive(false);
    if (keepAlive != null) {
        workplaceElement.addElement(N_KEEP_ALIVE).setText(keepAlive.toString());
    }

    String defaultScope = m_workplaceManager.getGalleryDefaultScopeString();
    if (defaultScope != null) {
        workplaceElement.addElement(N_GALLERY_DEFAULT_SCOPE).setText(defaultScope);
    }
    ElementDeleteMode deleteMode = m_workplaceManager.getElementDeleteMode();
    if (deleteMode != null) {
        workplaceElement.addElement(N_ELEMENT_DELETE_MODE).setText(deleteMode.name());
    }

    // return the configured node
    return workplaceElement;
}

From source file:com.facebook.presto.AbstractTestQueries.java

@Test
public void testShowFunctions() throws Exception {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedTuple> functions = Multimaps.index(result.getMaterializedTuples(),
            new Function<MaterializedTuple, String>() {
                @Override//w ww.jav a  2 s . c  o m
                public String apply(MaterializedTuple input) {
                    assertEquals(input.getFieldCount(), 5);
                    return (String) input.getField(0);
                }
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 2);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar (non-deterministic)");

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar, varchar, bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");
}

From source file:com.netxforge.netxstudio.common.model.StudioUtils.java

/**
 * Get hourly timestamps in weekly chunks.
 * //from  w ww  .j av  a2  s  .  co  m
 * @param dtr
 * @return
 */
public static Multimap<Integer, XMLGregorianCalendar> hourlyTimeStampsByWeekFor(DateTimeRange dtr) {

    List<XMLGregorianCalendar> tses = transformPeriodToHourlyTimestamps(dtr);

    Function<XMLGregorianCalendar, Integer> weekNumFunction = new Function<XMLGregorianCalendar, Integer>() {
        Calendar cal = Calendar.getInstance();

        public Integer apply(XMLGregorianCalendar from) {
            // convert to a regular calendar to get the time.
            cal.setTime(from.toGregorianCalendar().getTime());
            return cal.get(Calendar.WEEK_OF_YEAR);
        }
    };
    return Multimaps.index(tses, weekNumFunction);
}

From source file:com.facebook.presto.tests.AbstractTestQueries.java

@Test
public void testShowFunctions() throws Exception {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(),
            input -> {/*  w  w w.j  ava  2 s .  c  o  m*/
                assertEquals(input.getFieldCount(), 6);
                return (String) input.getField(0);
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 2);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("abs").asList().get(0).getField(4), true);

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("rand").asList().get(0).getField(4), false);

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar, varchar, bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");

    assertFalse(functions.containsKey("like"),
            "Expected function names " + functions + " not to contain 'like'");
}

From source file:io.prestosql.tests.AbstractTestQueries.java

@Test
public void testShowFunctions() {
    MaterializedResult result = computeActual("SHOW FUNCTIONS");
    ImmutableMultimap<String, MaterializedRow> functions = Multimaps.index(result.getMaterializedRows(),
            input -> {//from  w w w  . j av  a  2  s.  co  m
                assertEquals(input.getFieldCount(), 6);
                return (String) input.getField(0);
            });

    assertTrue(functions.containsKey("avg"), "Expected function names " + functions + " to contain 'avg'");
    assertEquals(functions.get("avg").asList().size(), 6);
    assertEquals(functions.get("avg").asList().get(0).getField(1), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(2), "decimal(p,s)");
    assertEquals(functions.get("avg").asList().get(0).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(1).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(1).getField(2), "bigint");
    assertEquals(functions.get("avg").asList().get(1).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(2).getField(1), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(2), "double");
    assertEquals(functions.get("avg").asList().get(2).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(3).getField(1), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(2), "interval day to second");
    assertEquals(functions.get("avg").asList().get(3).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(4).getField(1), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(2), "interval year to month");
    assertEquals(functions.get("avg").asList().get(4).getField(3), "aggregate");
    assertEquals(functions.get("avg").asList().get(5).getField(1), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(2), "real");
    assertEquals(functions.get("avg").asList().get(5).getField(3), "aggregate");

    assertTrue(functions.containsKey("abs"), "Expected function names " + functions + " to contain 'abs'");
    assertEquals(functions.get("abs").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("abs").asList().get(0).getField(4), true);

    assertTrue(functions.containsKey("rand"), "Expected function names " + functions + " to contain 'rand'");
    assertEquals(functions.get("rand").asList().get(0).getField(3), "scalar");
    assertEquals(functions.get("rand").asList().get(0).getField(4), false);

    assertTrue(functions.containsKey("rank"), "Expected function names " + functions + " to contain 'rank'");
    assertEquals(functions.get("rank").asList().get(0).getField(3), "window");

    assertTrue(functions.containsKey("rank"),
            "Expected function names " + functions + " to contain 'split_part'");
    assertEquals(functions.get("split_part").asList().get(0).getField(1), "varchar(x)");
    assertEquals(functions.get("split_part").asList().get(0).getField(2), "varchar(x), varchar(y), bigint");
    assertEquals(functions.get("split_part").asList().get(0).getField(3), "scalar");

    assertFalse(functions.containsKey("like"),
            "Expected function names " + functions + " not to contain 'like'");
}