Example usage for java.util IdentityHashMap IdentityHashMap

List of usage examples for java.util IdentityHashMap IdentityHashMap

Introduction

In this page you can find the example usage for java.util IdentityHashMap IdentityHashMap.

Prototype

public IdentityHashMap() 

Source Link

Document

Constructs a new, empty identity hash map with a default expected maximum size (21).

Usage

From source file:pcgen.io.PCGVer2Parser.java

/**
 * ###############################################################
 * EquipSet Temp Bonuses//from  w  w  w  . j  a v  a 2  s.  c  o m
 * ###############################################################
 * @param line
 **/
private void parseEquipSetTempBonusLine(final String line) {
    PCGTokenizer tokens;

    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String msg = LanguageBundle.getFormattedString("Warnings.PCGenParser.IllegalEquipSetTempBonus", //$NON-NLS-1$
                line, pcgpex.getMessage());
        warnings.add(msg);

        return;
    }

    String tag;
    String tagString = null;

    for (PCGElement element : tokens.getElements()) {
        tag = element.getName();

        if (IOConstants.TAG_EQSETBONUS.equals(tag)) {
            tagString = EntityEncoder.decode(element.getText());
        }
    }

    if (tagString == null) {
        final String msg = LanguageBundle.getFormattedString("Warnings.PCGenParser.InvalidEquipSetTempBonus", //$NON-NLS-1$
                line);
        warnings.add(msg);

        return;
    }

    final EquipSet eSet = thePC.getEquipSetByIdPath(tagString);

    if (eSet == null) {
        return;
    }

    //# EquipSet Temp Bonuses
    //EQSETBONUS:0.2|TEMPBONUS:NAME=Haste|TBTARGET:PC|TEMPBONUS:SPELL=Shield of Faith|TBTARGET:PC
    final Map<BonusObj, BonusManager.TempBonusInfo> aList = new IdentityHashMap<>();

    for (final PCGElement element : tokens.getElements()) {
        tag = element.getName();

        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            final String aString = EntityEncoder.decode(element.getText());

            // Parse aString looking for
            // TEMPBONUS and TBTARGET pairs
            StringTokenizer aTok = new StringTokenizer(aString, IOConstants.TAG_SEPARATOR);

            if (aTok.countTokens() < 2) {
                continue;
            }

            String sName = aTok.nextToken();
            String tName = aTok.nextToken();
            aList.putAll(getBonusFromName(sName, tName));
        }
    }

    eSet.setTempBonusList(aList);
}

From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java

/**
* Collect all the object of the type ContextualDesignations instantiated in the Process Model
*
* @return a map, where the key is the reference to the object and the value is a textual
* description of the object location//www . j a v  a  2s  .co m
*/
private Map<ContextualDesignations, String> collectContextualDesignations() {
    Map<ContextualDesignations, String> map = new IdentityHashMap<ContextualDesignations, String>();
    Roles roles = processModel.getRolesEx();

    // Process Model Labels & Descriptions
    //
    map.put(processModel.getDescriptions(), "processModel: " + DESCRIPTIONS);
    map.put(processModel.getLabels(), "processModel: " + LABELS);

    // Role Labels & Descriptions
    //
    if (roles != null) {
        Iterator<Role> iterRole = roles.iterateRole();
        while (iterRole.hasNext()) {
            Role role = iterRole.next();
            map.put(role.getDescriptions(), "role: '" + role.getName() + "' : description");
            map.put(role.getLabels(), "role: '" + role.getName() + "' : label");
        }
    }

    // Presentation - titles
    //
    if (processModel.getPresentation() != null) {
        map.put(processModel.getPresentation().getTitles(),
                WorkflowDesignerSessionController.PRESENTATION + ": title");
    }

    // Participants
    //
    if (processModel.getParticipantsEx() != null) {
        Iterator<Participant> iterParticipant = processModel.getParticipantsEx().iterateParticipant();

        while (iterParticipant.hasNext()) {
            Participant participant = iterParticipant.next();
            map.put(participant.getDescriptions(),
                    "participant: '" + participant.getName() + "' : description");
            map.put(participant.getLabels(), "participant: '" + participant.getName() + "' : label");
        }
    }

    // States
    //
    if (processModel.getStatesEx() != null) {
        Iterator<State> iterState = processModel.getStatesEx().iterateState();
        while (iterState.hasNext()) {
            State state = iterState.next();
            map.put(state.getDescriptions(), "state: '" + state.getName() + "' : description");
            map.put(state.getLabels(), "state: '" + state.getName() + "' : label");
            map.put(state.getActivities(), "state: '" + state.getName() + "' : activity");
        }
    }

    // Actions
    //
    if (processModel.getActionsEx() != null) {
        Iterator<Action> iterAction = processModel.getActionsEx().iterateAction();
        while (iterAction.hasNext()) {
            Action action = iterAction.next();
            map.put(action.getDescriptions(), "action: '" + action.getName() + "' : description");
            map.put(action.getLabels(), "action: '" + action.getName() + "' : label");
        }
    }

    // UserInfos
    //
    if (processModel.getUserInfos() != null) {
        Iterator<Item> iterItem = processModel.getUserInfos().iterateItem();
        while (iterItem.hasNext()) {
            Item item = iterItem.next();
            map.put(item.getDescriptions(), "userInfos item: '" + item.getName() + "' : description");
            map.put(item.getLabels(), "userInfos item: '" + item.getName() + "' : label");
        }
    }

    // DataFolder
    //
    if (processModel.getDataFolder() != null) {
        Iterator<Item> iterItem = processModel.getDataFolder().iterateItem();
        while (iterItem.hasNext()) {
            Item item = iterItem.next();
            map.put(item.getDescriptions(), "dataFolder item: '" + item.getName() + "' : description");
            map.put(item.getLabels(), "dataFolder item: '" + item.getName() + "' : label");
        }
    }

    // Forms
    //
    if (processModel.getForms() != null) {
        Iterator<Form> iterForm = processModel.getForms().iterateForm();

        while (iterForm.hasNext()) {
            Form form = iterForm.next();
            String strFormId;
            if (form.getRole() == null) {
                strFormId = "form: '" + form.getName() + "'";
            } else {
                strFormId = "form [ name: '" + form.getName() + "', role: '" + form.getRole() + "' ]";
            }
            map.put(form.getTitles(), strFormId + " : title");
            Iterator<Input> iterInput = form.iterateInput();
            while (iterInput.hasNext()) {
                Input input = iterInput.next();
                map.put(input.getLabels(), strFormId + " : input"
                        + (input.getItem() == null ? ""
                                : (" " + "[ item: '" + input.getItem().getName() + "' ] : label"))
                        + (input.getValue() == null ? "" : (" [ value: '" + input.getValue() + "' ] : label")));
            }
        }
    }

    return map;
}

From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java

/**
* Collect all the objects of the type QalifiedUsers instantiated in the Process Model
*
* @return a map, where the key is the reference to the object and the value is a textual
* description of the object location/*from  w w w .  j a v  a  2  s  . c o  m*/
*/
private Map<QualifiedUsers, String> collectQualifiedUsers() {
    Map<QualifiedUsers, String> map = new IdentityHashMap<QualifiedUsers, String>();

    // States
    //
    if (processModel.getStatesEx() != null) {
        for (State state : processModel.getStatesEx().getStates()) {

            if (state.getWorkingUsersEx() != null) {
                map.put(state.getWorkingUsersEx(), "state: '" + state.getName() + "' : workingUsers");
            }

            if (state.getInterestedUsersEx() != null) {
                map.put(state.getInterestedUsersEx(), "state: '" + state.getName() + "' : interestedUsers");
            }
        }
    }

    // Actions
    //
    if (processModel.getActionsEx() != null) {
        Action action;
        Iterator<Action> iterAction = processModel.getActionsEx().iterateAction();

        while (iterAction.hasNext()) {
            action = iterAction.next();

            if (action.getAllowedUsers() != null) {
                map.put(action.getAllowedUsers(), "action: '" + action.getName() + "' : allowedUsers");
            }

            if (action.getConsequences() != null) {
                Iterator<Consequence> iterConsequence = action.getConsequences().iterateConsequence();

                while (iterConsequence.hasNext()) {
                    Consequence consequence = iterConsequence.next();

                    List<QualifiedUsers> qualifiedUsersList = consequence.getNotifiedUsers();
                    if (qualifiedUsersList != null && !qualifiedUsersList.isEmpty()) {
                        map.put(qualifiedUsersList.get(0),
                                "action: '" + action.getName() + "' : consequence: ["
                                        + (consequence.getItem() == null ? "Default"
                                                : (" item: '" + consequence.getItem() + "', operator: '"
                                                        + consequence.getOperator() + "', value: '"
                                                        + consequence.getValue() + "'"))
                                        + " ]");
                    }
                }
            }
        }
    }

    return map;
}

From source file:org.jspresso.framework.application.backend.AbstractBackendController.java

private IEntity refineEntity(IComponent target) {
    return refineEntity(target, new IdentityHashMap<IComponent, Object>());
}

From source file:org.rhq.core.pc.inventory.InventoryManager.java

@NotNull
Set<Resource> executeComponentDiscovery(ResourceType resourceType,
        ResourceDiscoveryComponent discoveryComponent, ResourceContainer parentContainer,
        List<ProcessScanResult> processScanResults) {

    ResourceContext parentResourceContext = parentContainer.getResourceContext();
    ResourceComponent parentComponent = parentContainer.getResourceComponent();
    Resource parentResource = parentContainer.getResource();

    long startTime = System.currentTimeMillis();
    log.debug("Executing discovery for [" + resourceType.getName() + "] Resources...");
    Set<Resource> newResources;
    try {/*  w  w w .  ja va 2 s . co  m*/
        ResourceDiscoveryContext context = new ResourceDiscoveryContext(resourceType, parentComponent,
                parentResourceContext, SystemInfoFactory.createSystemInfo(), processScanResults,
                Collections.EMPTY_LIST, this.configuration.getContainerName(),
                this.configuration.getPluginContainerDeployment());
        newResources = new HashSet<Resource>();
        try {
            Set<DiscoveredResourceDetails> discoveredResources = invokeDiscoveryComponent(parentContainer,
                    discoveryComponent, context);
            if ((discoveredResources != null) && (!discoveredResources.isEmpty())) {
                IdentityHashMap<Configuration, DiscoveredResourceDetails> pluginConfigObjects = new IdentityHashMap<Configuration, DiscoveredResourceDetails>();
                for (DiscoveredResourceDetails discoveredResource : discoveredResources) {
                    if (discoveredResource == null) {
                        throw new IllegalStateException(
                                "Plugin error: Discovery class " + discoveryComponent.getClass().getName()
                                        + " returned a Set containing one or more null items.");
                    }
                    if (!discoveredResource.getResourceType().equals(resourceType)) {
                        throw new IllegalStateException("Plugin error: Discovery class "
                                + discoveryComponent.getClass().getName()
                                + " returned a DiscoveredResourceDetails with an incorrect ResourceType (was "
                                + discoveredResource.getResourceType().getName() + " but should have been "
                                + resourceType.getName());
                    }
                    if (null != pluginConfigObjects.put(discoveredResource.getPluginConfiguration(),
                            discoveredResource)) {
                        throw new IllegalStateException("The plugin component "
                                + discoveryComponent.getClass().getName()
                                + " returned multiple resources that point to the same plugin configuration object on the "
                                + "resource type [" + resourceType + "]. This is not allowed, please use "
                                + "ResourceDiscoveryContext.getDefaultPluginConfiguration() "
                                + "for each discovered resource.");
                    }
                    Resource newResource = InventoryManager.createNewResource(discoveredResource);
                    newResources.add(newResource);
                }
            }
        } catch (DiscoverySuspendedException e) {
            //ok, the discovery is suspended for this resource type under this parent.
            //but we can continue the discovery in the child resource types of the existing resources.
            //we can therefore pretend that the discovery returned the existing resources so that
            //we can recurse into their children up in the call-chain.
            for (Resource existingResource : parentResource.getChildResources()) {
                if (resourceType.equals(existingResource.getResourceType())) {
                    newResources.add(existingResource);
                }
            }
        }
    } catch (Throwable e) {
        // TODO GH: Add server/parent - up/down semantics so this won't happen just because a server is not up
        long elapsedTime = System.currentTimeMillis() - startTime;
        log.warn("Failure during discovery for [" + resourceType.getName() + "] Resources - failed after "
                + elapsedTime + " ms.", e);
        return Collections.EMPTY_SET;
    }

    long elapsedTime = System.currentTimeMillis() - startTime;
    if (elapsedTime > 20000)
        log.info("Discovery for [" + resourceType.getName() + "] resources took [" + elapsedTime + "] ms");
    else
        log.debug("Discovery for [" + resourceType.getName() + "] resources completed in [" + elapsedTime
                + "] ms");
    return newResources;
}

From source file:pcgen.io.PCGVer2Parser.java

private void resolveLanguages() {
    CNAbility langbonus = thePC.getBonusLanguageAbility();
    int currentBonusLang = thePC.getDetailedAssociationCount(langbonus);
    boolean foundLang = currentBonusLang > 0;

    Set<Language> foundLanguages = new HashSet<>(thePC.getLanguageSet());
    //Captures Auto (AUTO:LANG) and Persistent choices (ADD ex ability and CHOOSE)
    cachedLanguages.removeAll(foundLanguages);

    HashMapToList<Language, Object> langSources = new HashMapToList<>();
    Map<Object, Integer> actorLimit = new IdentityHashMap<>();
    Map<PersistentTransitionChoice, CDOMObject> ptcSources = new IdentityHashMap<>();

    List<? extends CDOMObject> abilities = thePC.getCDOMObjectList();
    for (CDOMObject a : abilities) {
        List<PersistentTransitionChoice<?>> addList = a.getListFor(ListKey.ADD);
        if (addList != null) {
            for (PersistentTransitionChoice<?> ptc : addList) {
                SelectableSet<?> ss = ptc.getChoices();
                if (ss.getName().equals("LANGUAGE") && LANGUAGE_CLASS.equals(ss.getChoiceClass())) {
                    Collection<Language> selected = (Collection<Language>) ss.getSet(thePC);
                    for (Language l : selected) {
                        if (cachedLanguages.contains(l)) {
                            String source = SourceFormat.getFormattedString(a, Globals.getSourceDisplay(),
                                    true);
                            int choiceCount = ptc.getCount().resolve(thePC, source).intValue();
                            if (choiceCount > 0) {
                                langSources.addToListFor(l, ptc);
                                ptcSources.put(ptc, a);
                                actorLimit.put(ptc, choiceCount);
                            }/*from  www.  j a v  a 2s .c  o m*/
                        }
                    }
                }
            }
        }
    }
    if (!foundLang) {
        Set<Language> bonusAllowed = thePC.getLanguageBonusSelectionList();
        int count = thePC.getBonusLanguageCount();
        int choiceCount = count - currentBonusLang;
        if (choiceCount > 0) {
            for (Language l : bonusAllowed) {
                if (cachedLanguages.contains(l)) {
                    langSources.addToListFor(l, langbonus);
                    actorLimit.put(langbonus, choiceCount);
                }
            }
        }
    }
    //Try to match them up as best as possible (this matches things with only one possible location...)
    boolean acted = !cachedLanguages.isEmpty();
    while (acted) {
        acted = false;
        for (Language l : langSources.getKeySet()) {
            List<Object> actors = langSources.getListFor(l);
            if ((actors != null) && (actors.size() == 1)) {
                Object actor = actors.get(0);
                acted = true;
                processRemoval(langbonus, langSources, actorLimit, ptcSources, l, actor);
            }
        }
        if (!acted && !langSources.isEmpty() && !actorLimit.isEmpty()) {
            //pick one
            Language l = langSources.getKeySet().iterator().next();
            Object source = langSources.getListFor(l).get(0);
            processRemoval(langbonus, langSources, actorLimit, ptcSources, l, source);
            acted = true;
        }
    }

    for (Language l : cachedLanguages) {
        warnings.add("Unable to find source: " + "Character no longer speaks language: " + l.getDisplayName());
    }
}