Example usage for java.util ArrayList trimToSize

List of usage examples for java.util ArrayList trimToSize

Introduction

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

Prototype

public void trimToSize() 

Source Link

Document

Trims the capacity of this ArrayList instance to be the list's current size.

Usage

From source file:com.l2jfree.gameserver.Announcements.java

public void addEventAnnouncement(DateRange validDateRange, String[] msg) {
    ArrayList<Object> entry = new ArrayList<Object>();
    entry.add(validDateRange);/*from   w  ww. j  a v  a  2s  .c  om*/
    entry.add(msg);
    entry.trimToSize();
    _eventAnnouncements.add(entry);
}

From source file:ru.jts_dev.gameserver.handlers.HandlerManager.java

protected List<Method> getAnnotatedMethods(Class<? extends ICommandHandler<TCommandType>> handlerClass,
        Class<? extends Annotation> annotationClass) {
    ArrayList<Method> methods = new ArrayList<>();
    for (Method method : handlerClass.getDeclaredMethods()) {
        if (method.isAnnotationPresent(annotationClass)) {
            methods.add(method);//from   www .  ja va2 s .c  om
        }
    }
    methods.trimToSize();
    return methods;
}

From source file:de.uniba.wiai.kinf.pw.projects.lillytab.terms.impl.AbstractFixedTermList.java

/**
 *
 * Construct a new {@link AbstractFixedTermList} using an {@link ArrayList} for backend storage. The list will be
 * filled with {@literal null}s up to the desired number of elements.
 *
 *
 * @param size The desired size of the term list.
 *///from www  . j ava 2s .  c om
protected AbstractFixedTermList(final int size) {
    ArrayList<Term> backendList = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        backendList.add(null);
    }
    backendList.trimToSize();
    _modifiableBackend = backendList;
}

From source file:com.icesoft.faces.webapp.parser.Parser.java

/**
 * This member mimicks the JSP tag processing lifecyle across the tag
 * processing tree to produce the JSF component tree.
 *
 * @param wire         The tag's wire/*from w w w  . java  2  s . c  o m*/
 * @param pageContext  The page context
 * @param facesContext The faces context
 * @param componentIds
 * @throws JspException
 */
public void executeJspLifecycle(TagWire wire, PageContext pageContext, FacesContext facesContext,
        Set componentIds) throws JspException {
    // Start of lifecycle;
    boolean processingViewTag = false;
    Tag tag = wire.getTag();
    tag.setPageContext(pageContext);
    // Start tag processing;
    tag.doStartTag();

    UIComponent myComponent = null; // reference will be used after doEndTag
    if (tag instanceof UIComponentTag) {
        UIComponentTag compTag = (UIComponentTag) tag;
        myComponent = compTag.getComponentInstance();

        if (myComponent != null) {
            if (myComponent instanceof UIViewRoot) {
                myComponent.setId("_view");
                processingViewTag = true;
            }

            String componentId = myComponent.getClientId(facesContext);
            if (componentIds.contains(componentId))
                throw new IllegalStateException("Duplicate component ID : " + componentId);
            componentIds.add(componentId);
        }
    }

    // Now process tag children;
    Iterator children = wire.getChildren().iterator();
    while (children.hasNext()) {
        TagWire childWire = (TagWire) children.next();
        executeJspLifecycle(childWire, pageContext, facesContext, componentIds);
    }
    //Do tag body processing. This is not full-fledged body processing. It only calls the doAfterBody() member
    if (!processingViewTag && tag instanceof UIComponentBodyTag) {
        UIComponentBodyTag bodyTag = (UIComponentBodyTag) tag;
        if (bodyTag.getBodyContent() == null) {
            //body content of custom tag should not be null, so create one in here to satisfy the
            //checking in jsf 1.0 impl.
            JspWriter jspWriter = new JspWriterImpl(new PrintWriter(System.out));
            BodyContentImpl imp = new BodyContentImpl(jspWriter);
            bodyTag.setBodyContent(imp);
        }
        bodyTag.doAfterBody();
    }
    // Do end tag processing;
    tag.doEndTag();

    // ICE-3443: to save memory, trim the COMPONENT_IDS list capacity
    // to its actual size
    if (null != myComponent) {
        Map attributes = myComponent.getAttributes();
        ArrayList idsList = (ArrayList) attributes.get("javax.faces.webapp.COMPONENT_IDS");
        if (null != idsList) {
            idsList.trimToSize();
        }
    }
}

From source file:com.flexive.faces.FxJsfUtils.java

/**
 * Gets all faces messages (optional: for the given client id).
 *
 * @param clientId the client id to work on, or null to remove all messages.
 * @return a array holding all messages/*  ww w . ja  v  a 2 s .  c  om*/
 */
@SuppressWarnings("unchecked")
public static ArrayList<FacesMessage> getMessages(String clientId) {
    ArrayList<FacesMessage> result = new ArrayList<FacesMessage>(25);
    try {
        //noinspection unchecked
        Iterator<FacesMessage> it = (clientId == null || clientId.length() == 0)
                ? getCurrentInstance().getMessages()
                : getCurrentInstance().getMessages(clientId);

        while (it.hasNext()) {
            result.add(it.next());
        }
    } catch (Throwable t) {
        result.add(new FacesMessage("Failed to build message list: " + t.getMessage()));
    }
    result.trimToSize();
    return result;
}

From source file:com.silverwrist.dynamo.security.AuditReadOps_mysql.java

private final List runListStatement(PreparedStatement stmt) throws SQLException {
    ResultSet rs = null;//from   w  w  w . j a  va2  s .c  o  m
    try { // get the list of record IDs (long integers)
        rs = stmt.executeQuery();
        if (!(rs.next()))
            return Collections.EMPTY_LIST; // no results
        ArrayList rc = new ArrayList();
        do { // add each entry to the list
            rc.add(new Long(rs.getLong(1)));

        } while (rs.next()); // end do

        rc.trimToSize();
        return Collections.unmodifiableList(rc);

    } // end try
    finally { // shut down the result set before we go
        SQLUtils.shutdown(rs);

    } // end finally

}

From source file:org.lockss.config.TdbPublisher.java

/**
 * Return the collection of TdbTitles for this publisher
 * with a name like (starts with) the specified title name.
 * /*from w  w  w  .  j  a  va 2  s.  co  m*/
 * @param titleName the title name
 * @return the set of TdbTitles with the specified title name
 */
public Collection<TdbTitle> getTdbTitlesLikeName(String titleName) {
    ArrayList<TdbTitle> matchTitles = new ArrayList<TdbTitle>();
    getTdbTitlesLikeName(titleName, matchTitles);
    matchTitles.trimToSize();
    return matchTitles;
}

From source file:org.parosproxy.paros.network.ConnectionParam.java

private static List<ProxyExcludedDomainMatcher> convertOldSkipNameOption(String skipNames) {
    if (skipNames == null || skipNames.isEmpty()) {
        return Collections.emptyList();
    }/*from   w  ww  .j a  v a2 s  .c om*/

    ArrayList<ProxyExcludedDomainMatcher> excludedDomains = new ArrayList<>();
    String[] names = skipNames.split(";");
    for (String name : names) {
        String excludedDomain = name.trim();
        if (!excludedDomain.isEmpty()) {
            if (excludedDomain.contains("*")) {
                excludedDomain = excludedDomain.replace(".", "\\.").replace("*", ".*?");
                try {
                    Pattern pattern = Pattern.compile(name, Pattern.CASE_INSENSITIVE);
                    excludedDomains.add(new ProxyExcludedDomainMatcher(pattern));
                } catch (IllegalArgumentException e) {
                    log.error("Failed to migrate the excluded domain name: " + name, e);
                }
            } else {
                excludedDomains.add(new ProxyExcludedDomainMatcher(excludedDomain));
            }
        }
    }
    excludedDomains.trimToSize();
    return excludedDomains;
}

From source file:org.lockss.config.TdbProvider.java

/**
 * Return the TdbAus for this provider like the specified TdbAu volume.
 * //  www.j a  v a 2 s .  c o m
 * @param tdbAuName the name of the AU to select
 * @return the TdbAu like the specified name
 */
public Collection<TdbAu> getTdbAusByName(String tdbAuName) {
    ArrayList<TdbAu> aus = new ArrayList<TdbAu>();
    getTdbAusByName(tdbAuName, aus);
    aus.trimToSize();
    return aus;
}

From source file:phex.host.CaughtHostsContainer.java

public List<CaughtHost> getFreeLeafSlotHosts() {
    synchronized (freeLeafSlotSet) {
        ArrayList<CaughtHost> freeHosts = new ArrayList<>(freeLeafSlotSet);
        freeHosts.trimToSize();
        return freeHosts;
    }/*ww w  .j a  v  a 2s.co  m*/
}