Java Code Examples for org.apache.commons.collections.FastHashMap#setFast()
The following examples show how to use
org.apache.commons.collections.FastHashMap#setFast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidatorUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Makes a deep copy of a <code>FastHashMap</code> if the values * are <code>Msg</code>, <code>Arg</code>, * or <code>Var</code>. Otherwise it is a shallow copy. * * @param map <code>FastHashMap</code> to copy. * @return FastHashMap A copy of the <code>FastHashMap</code> that was * passed in. * @deprecated This method is not part of Validator's public API. Validator * will use it internally until FastHashMap references are removed. Use * copyMap() instead. */ @Deprecated public static FastHashMap copyFastHashMap(FastHashMap map) { FastHashMap results = new FastHashMap(); @SuppressWarnings("unchecked") // FastHashMap is not generic Iterator<Entry<String, ?>> i = map.entrySet().iterator(); while (i.hasNext()) { Entry<String, ?> entry = i.next(); String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof Msg) { results.put(key, ((Msg) value).clone()); } else if (value instanceof Arg) { results.put(key, ((Arg) value).clone()); } else if (value instanceof Var) { results.put(key, ((Var) value).clone()); } else { results.put(key, value); } } results.setFast(true); return results; }
Example 2
Source File: InstitutionPortlet.java From olat with Apache License 2.0 | 4 votes |
/** * initializes the institution portlet config */ public void init() { final File configurationFile = new File(WebappHelper.getContextRoot() + CONFIG_FILE); XMLConfiguration instConfigSection = null; try { instConfigSection = new XMLConfiguration(configurationFile); } catch (final ConfigurationException ce) { throw new StartupException("Error loading institution portlet configuration file!", ce); } if (instConfigSection == null) { throw new StartupException("Error loading institution portlet configuration file!"); } institutions = new FastHashMap(); for (final Iterator iter = instConfigSection.getChildren("institution").iterator(); iter.hasNext();) { final Configuration instConfigEntry = (Configuration) iter.next(); // the institutions config entry final String shortName = instConfigEntry.getAttribute("shortname"); // short name of inst if (shortName == null) { throw new StartupException("Institution portlet startup: No shortname given for one entry!"); } try { final List<InstitutionPortletSupervisorEntry> supervisors = new ArrayList<InstitutionPortletSupervisorEntry>(1); // there may be more than one supervisor for (final Iterator it = instConfigEntry.getChildren(SUPERVISOR).iterator(); it.hasNext();) { final Configuration supervisorElement = (Configuration) it.next(); // one supervisor element final InstitutionPortletSupervisorEntry ipse = new InstitutionPortletSupervisorEntry( getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PERSON)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PHONE)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_EMAIL)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_URL)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_BLOG))); supervisors.add(ipse); // save it } // get polymorph links final List<Configuration> polymorphConfs = instConfigEntry.getChildren(POLYMORPHLINK); final List<PolymorphLink> polyList = new ArrayList<PolymorphLink>(); if (polymorphConfs != null && polymorphConfs.size() > 0) { for (final Configuration polymorphConf : polymorphConfs) { final List<PolymorphLinkElement> elemList = new ArrayList<PolymorphLinkElement>(); for (final Iterator<Configuration> it = polymorphConf.getChildren(POLYMORPHLINK_ELEMENT).iterator(); it.hasNext();) { final Configuration tmp = it.next(); elemList.add(new PolymorphLinkElement(tmp.getAttribute(POLYMORPHLINK_ELEMENT_ATTRIBUT), tmp.getAttribute(POLYMORPHLINK_ELEMENT_VALUE), tmp .getAttribute(POLYMORPHLINK_ELEMENT_ID), tmp.getAttribute(POLYMORPHLINK_ELEMENT_CONDITION))); } final PolymorphLink polyLink = new PolymorphLink(polymorphConf.getAttribute(POLYMORPHLINK_TARGETID), polymorphConf.getAttribute(POLYMORPHLINK_TYPE), polymorphConf.getAttribute(POLYMORPHLINK_TEXT), elemList); polyList.add(polyLink); } } final InstitutionPortletEntry ipe = new InstitutionPortletEntry(instConfigEntry.getChild(INSTITUTION_NAME).getAttribute(VALUE), instConfigEntry.getChild( INSTITUTION_URL).getAttribute(VALUE), instConfigEntry.getChild(INSTITUTION_LOGO).getAttribute(VALUE), supervisors, polyList); institutions.put(shortName.toLowerCase(), ipe); // save inst entry } catch (final Exception e) { e.printStackTrace(); throw new StartupException(e.getMessage(), e); } } // from now on optimize for non-synchronized read access institutions.setFast(true); }
Example 3
Source File: InstitutionPortlet.java From olat with Apache License 2.0 | 4 votes |
/** * initializes the institution portlet config */ public void init() { final File configurationFile = new File(WebappHelper.getContextRoot() + CONFIG_FILE); XMLConfiguration instConfigSection = null; try { instConfigSection = new XMLConfiguration(configurationFile); } catch (final ConfigurationException ce) { throw new StartupException("Error loading institution portlet configuration file!", ce); } if (instConfigSection == null) { throw new StartupException("Error loading institution portlet configuration file!"); } institutions = new FastHashMap(); for (final Iterator iter = instConfigSection.getChildren("institution").iterator(); iter.hasNext();) { final Configuration instConfigEntry = (Configuration) iter.next(); // the institutions config entry final String shortName = instConfigEntry.getAttribute("shortname"); // short name of inst if (shortName == null) { throw new StartupException("Institution portlet startup: No shortname given for one entry!"); } try { final List<InstitutionPortletSupervisorEntry> supervisors = new ArrayList<InstitutionPortletSupervisorEntry>(1); // there may be more than one supervisor for (final Iterator it = instConfigEntry.getChildren(SUPERVISOR).iterator(); it.hasNext();) { final Configuration supervisorElement = (Configuration) it.next(); // one supervisor element final InstitutionPortletSupervisorEntry ipse = new InstitutionPortletSupervisorEntry( getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PERSON)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PHONE)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_EMAIL)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_URL)), getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_BLOG))); supervisors.add(ipse); // save it } // get polymorph links final List<Configuration> polymorphConfs = instConfigEntry.getChildren(POLYMORPHLINK); final List<PolymorphLink> polyList = new ArrayList<PolymorphLink>(); if (polymorphConfs != null && polymorphConfs.size() > 0) { for (final Configuration polymorphConf : polymorphConfs) { final List<PolymorphLinkElement> elemList = new ArrayList<PolymorphLinkElement>(); for (final Iterator<Configuration> it = polymorphConf.getChildren(POLYMORPHLINK_ELEMENT).iterator(); it.hasNext();) { final Configuration tmp = it.next(); elemList.add(new PolymorphLinkElement(tmp.getAttribute(POLYMORPHLINK_ELEMENT_ATTRIBUT), tmp.getAttribute(POLYMORPHLINK_ELEMENT_VALUE), tmp .getAttribute(POLYMORPHLINK_ELEMENT_ID), tmp.getAttribute(POLYMORPHLINK_ELEMENT_CONDITION))); } final PolymorphLink polyLink = new PolymorphLink(polymorphConf.getAttribute(POLYMORPHLINK_TARGETID), polymorphConf.getAttribute(POLYMORPHLINK_TYPE), polymorphConf.getAttribute(POLYMORPHLINK_TEXT), elemList); polyList.add(polyLink); } } final InstitutionPortletEntry ipe = new InstitutionPortletEntry(instConfigEntry.getChild(INSTITUTION_NAME).getAttribute(VALUE), instConfigEntry.getChild( INSTITUTION_URL).getAttribute(VALUE), instConfigEntry.getChild(INSTITUTION_LOGO).getAttribute(VALUE), supervisors, polyList); institutions.put(shortName.toLowerCase(), ipe); // save inst entry } catch (final Exception e) { e.printStackTrace(); throw new StartupException(e.getMessage(), e); } } // from now on optimize for non-synchronized read access institutions.setFast(true); }