Example usage for org.apache.commons.collections FastHashMap FastHashMap

List of usage examples for org.apache.commons.collections FastHashMap FastHashMap

Introduction

In this page you can find the example usage for org.apache.commons.collections FastHashMap FastHashMap.

Prototype

public FastHashMap() 

Source Link

Document

Construct an empty map.

Usage

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

/**
 * <p>//w  ww.  j a v a  2s.com
 * Retrieve the property descriptor for the specified property of the
 * specified bean, or return <code>null</code> if there is no such
 * descriptor. This method resolves indexed and nested property references
 * in the same manner as other methods in this class, except that if the
 * last (or only) name element is indexed, the descriptor for the last
 * resolved property itself is returned.
 * </p>
 *
 * <p>
 * <strong>FIXME</strong> - Does not work with DynaBeans.
 * </p>
 *
 * <p>
 * Note that for Java 8 and above, this method no longer return
 * IndexedPropertyDescriptor for {@link List}-typed properties, only for
 * properties typed as native array. (BEANUTILS-492).
 *
 * @param bean
 *            Bean for which a property descriptor is requested
 * @param name
 *            Possibly indexed and/or nested name of the property for which
 *            a property descriptor is requested
 * @return the property descriptor
 *
 * @throws IllegalAccessException
 *             if the caller does not have access to the property accessor
 *             method
 * @throws IllegalArgumentException
 *             if <code>bean</code> or <code>name</code> is null
 * @throws IllegalArgumentException
 *             if a nested reference to a property returns null
 * @throws InvocationTargetException
 *             if the property accessor method throws an exception
 * @throws NoSuchMethodException
 *             if an accessor method for this propety cannot be found
 */
public PropertyDescriptor getPropertyDescriptor(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Resolve nested references
    while (resolver.hasNested(name)) {
        final String next = resolver.next(name);
        final Object nestedBean = getProperty(bean, next);
        if (nestedBean == null) {
            throw new NestedNullException(
                    "Null property value for '" + next + "' on bean class '" + bean.getClass() + "'");
        }
        bean = nestedBean;
        name = resolver.remove(name);
    }

    // Remove any subscript from the final name value
    name = resolver.getProperty(name);

    // Look up and return this property from our cache
    // creating and adding it to the cache if not found.
    if (name == null) {
        return null;
    }

    final BeanIntrospectionData data = getIntrospectionData(bean.getClass());
    PropertyDescriptor result = data.getDescriptor(name);
    if (result != null) {
        return result;
    }

    FastHashMap mappedDescriptors = getMappedPropertyDescriptors(bean);
    if (mappedDescriptors == null) {
        mappedDescriptors = new FastHashMap();
        mappedDescriptors.setFast(true);
        mappedDescriptorsCache.put(bean.getClass(), mappedDescriptors);
    }
    result = (PropertyDescriptor) mappedDescriptors.get(name);
    if (result == null) {
        // not found, try to create it
        try {
            result = new MappedPropertyDescriptor(name, bean.getClass());
        } catch (final IntrospectionException ie) {
            /*
             * Swallow IntrospectionException TODO: Why?
             */
        }
        if (result != null) {
            mappedDescriptors.put(name, result);
        }
    }

    return result;

}

From source file:org.apache.cocoon.forms.DefaultCacheManager.java

public DefaultCacheManager() {
    this.cache = new FastHashMap();
}

From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoPropertyUtilsBean.java

/**
 * <p>// w w  w  .ja  v  a2 s  .com
 * Retrieve the property descriptor for the specified property of the specified bean, or return <code>null</code> if there is
 * no such descriptor. This method resolves indexed and nested property references in the same manner as other methods in this
 * class, except that if the last (or only) name element is indexed, the descriptor for the last resolved property itself is
 * returned.
 * </p>
 *
 * <p>
 * <strong>FIXME </strong>- Does not work with DynaBeans.
 * </p>
 *
 * @param bean Bean for which a property descriptor is requested
 * @param name Possibly indexed and/or nested name of the property for which a property descriptor is requested
 *
 * @exception IllegalAccessException if the caller does not have access to the property accessor method
 * @exception IllegalArgumentException if <code>bean</code> or <code>name</code> is null
 * @exception IllegalArgumentException if a nested reference to a property returns null
 * @exception InvocationTargetException if the property accessor method throws an exception
 * @exception NoSuchMethodException if an accessor method for this propety cannot be found
 */
public PropertyDescriptor getPropertyDescriptor(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    if (bean == null) {
        if (LOG.isDebugEnabled())
            LOG.debug("No bean specified, name = " + name);
        return null;
    }
    if (name == null) {
        throw new IllegalArgumentException("No name specified");
    }
    try {
        // Resolve nested references
        Object propBean = null;
        while (true) {
            int delim = findNextNestedIndex(name);
            //int delim = name.indexOf(PropertyUtils.NESTED_DELIM);
            if (delim < 0) {
                break;
            }
            String next = name.substring(0, delim);
            int indexOfINDEXED_DELIM = next.indexOf(PropertyUtils.INDEXED_DELIM);
            int indexOfMAPPED_DELIM = next.indexOf(PropertyUtils.MAPPED_DELIM);
            if (indexOfMAPPED_DELIM >= 0
                    && (indexOfINDEXED_DELIM < 0 || indexOfMAPPED_DELIM < indexOfINDEXED_DELIM)) {
                propBean = getMappedProperty(bean, next);
            } else {
                if (indexOfINDEXED_DELIM >= 0) {
                    propBean = getIndexedProperty(bean, next);
                } else {
                    propBean = getSimpleProperty(bean, next);
                }
            }
            if (ObjectUtils.isNull(propBean)) {
                Class propertyType = getPropertyType(bean, next);
                if (propertyType != null) {
                    Object newInstance = ObjectUtils.createNewObjectFromClass(propertyType);
                    setSimpleProperty(bean, next, newInstance);
                    propBean = getSimpleProperty(bean, next);
                }
            }
            bean = propBean;
            name = name.substring(delim + 1);
        }

        // Remove any subscript from the final name value
        int left = name.indexOf(PropertyUtils.INDEXED_DELIM);
        if (left >= 0) {
            name = name.substring(0, left);
        }
        left = name.indexOf(PropertyUtils.MAPPED_DELIM);
        if (left >= 0) {
            name = name.substring(0, left);
        }

        // Look up and return this property from our cache
        // creating and adding it to the cache if not found.
        if ((bean == null) || (name == null)) {
            return (null);
        }

        PropertyDescriptor descriptors[] = getPropertyDescriptors(bean);
        if (descriptors != null) {

            for (int i = 0; i < descriptors.length; i++) {
                if (name.equals(descriptors[i].getName()))
                    return (descriptors[i]);
            }
        }

        PropertyDescriptor result = null;
        FastHashMap mappedDescriptors = getMappedPropertyDescriptors(bean);
        if (mappedDescriptors == null) {
            mappedDescriptors = new FastHashMap();
            mappedDescriptors.setFast(true);
        }
        result = (PropertyDescriptor) mappedDescriptors.get(name);
        if (result == null) {
            // not found, try to create it
            try {
                result = new MappedPropertyDescriptor(name, bean.getClass());
            } catch (IntrospectionException ie) {
            }
            if (result != null) {
                mappedDescriptors.put(name, result);
            }
        }

        return result;
    } catch (RuntimeException ex) {
        LOG.error("Unable to get property descriptor for " + bean.getClass().getName() + " . " + name + "\n"
                + ex.getClass().getName() + ": " + ex.getMessage());
        throw ex;
    }
}

From source file:org.opencms.main.CmsDefaultSessionStorageProvider.java

/**
 * @see org.opencms.main.I_CmsSessionStorageProvider#initialize()
 *///from   w  w  w .j a v a2  s . c o m
public void initialize() {

    // create a map for all sessions, these will be mapped using their session id
    m_sessions = new FastHashMap();
    // set to "fast" mode (will be reset for write access)
    m_sessions.setFast(true);
}

From source file:org.opencms.xml.CmsXmlContentTypeManager.java

/**
 * Creates a new content type manager.<p> 
 *//*from   w  w w.  j  a  va 2s.c  o m*/
@SuppressWarnings("unchecked")
public CmsXmlContentTypeManager() {

    // use the fast hash map implementation since there will be far more read then write accesses

    m_registeredTypes = new HashMap<String, I_CmsXmlSchemaType>();
    m_defaultWidgets = new HashMap<String, I_CmsWidget>();
    m_registeredWidgets = new HashMap<String, I_CmsWidget>();
    m_widgetAliases = new HashMap<String, String>();
    m_widgetDefaultConfigurations = new HashMap<String, String>();

    FastHashMap fastMap = new FastHashMap();
    fastMap.setFast(true);
    m_contentHandlers = fastMap;

    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_START_CONTENT_CONFIG_0));
    }
}

From source file:org.seasar.struts.bean.SuppressPropertyUtilsBean.java

/**
 * ?????????/*from   w ww .j  a v a 2s. c o  m*/
 * 
 * @param suppressedBeanClasses
 *            ????
 */
public SuppressPropertyUtilsBean(Collection suppressedBeanClasses) {
    if (suppressedBeanClasses == null) {
        this.suppressedBeanClasses = Collections.EMPTY_SET;
    } else {
        this.suppressedBeanClasses = Collections.unmodifiableSet(new HashSet(suppressedBeanClasses));
    }
    descriptorsCache = new FastHashMap();
    descriptorsCache.setFast(true);
}

From source file:org.wso2.identity.cloud.manager.ldap.LDAPUserStoreManager.java

public Map<String, Object> getUserAttributes(String username, AttributeList attributeList) throws IOException {
    Map<String, Object> userAttributes = new FastHashMap();
    connection = LDAPConnector.getConnector().getConnection();
    Filter userNameFilter = FilterBuilder.equalTo(
            new Name(LDAPConstants.UID + "=" + username + "," + LDAPConstants.UserStoreProperties.SEARCH_BASE));

    ResultsHandler handler = new ResultsHandler() {
        public boolean handle(ConnectorObject obj) {
            connectorObject = obj;//from ww w . j ava2 s.  com
            return true;
        }
    };

    connection.search(ObjectClass.ACCOUNT, userNameFilter, handler, null);

    if (connectorObject != null) {
        Attribute attribute;
        userAttributes.put(LDAPConstants.USER_NAME, username);
        for (String attributeName : attributeList.getAttributes()) {
            attribute = connectorObject.getAttributeByName(attributeName);
            if (attribute != null) {
                userAttributes.put(attribute.getName(), attribute.getValue());
            }
        }
    }
    return userAttributes;
}

From source file:org.wso2.identity.cloud.resources.Authenticate.java

@POST
@Produces(MediaType.APPLICATION_JSON)//w ww.j  a v a2  s .com
@Consumes(MediaType.APPLICATION_JSON)
public JSONObject authenticate(Credentials credentials) {
    Boolean isAuthenticated = false;
    Map<String, Boolean> returnMap = new FastHashMap();
    try {
        UserStoreManager ldapUserStoreManager = new LDAPUserStoreManager();
        isAuthenticated = ldapUserStoreManager.authenticate(credentials);
    } catch (IOException e) {
        isAuthenticated = false;
    }
    returnMap.put("authenticated", isAuthenticated);
    return new JSONObject(returnMap);
}