java.util.ArrayList#trimToSize ( )源码实例Demo

下面列出了java.util.ArrayList#trimToSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: APICloud-Studio   文件: JSIndexQueryHelper.java
/**
 * Gets all the functions and properties for the given types.
 * 
 * @param typeNames
 * @return
 */
public Collection<PropertyElement> getTypeMembers(List<String> typeNames)
{
	if (CollectionsUtil.isEmpty(typeNames))
	{
		return Collections.emptyList();
	}
	ArrayList<PropertyElement> properties = new ArrayList<PropertyElement>();
	// FIXME Can we search both functions and properties at the same time?
	// FIXME What about "sub-types" that aren't hung explicitly off owning type? i.e. "Global.console"
	for (Index index : indices)
	{
		properties.addAll(_reader.getFunctions(index, typeNames));
		properties.addAll(_reader.getProperties(index, typeNames));
	}
	properties.trimToSize();
	return properties;
}
 
源代码2 项目: OSPREY3   文件: MSKStarDoer.java
private void listAllSeqsHelper(ArrayList<ArrayList<String>> subStateAATypeOptions, 
		ArrayList<ArrayList<String>> stateOutput, String[] wt, String[] buf, int depth, int dist){
	//List all sequences for the subset of mutable positions with max distance
	//from wt starting at depth=0 and going to the last mutable position
	if(depth==numMutRes){
		//String[] seq = new String[numTreeLevels];
		//System.arraycopy(buf, 0, seq, 0, numTreeLevels);
		ArrayList<String> seq = new ArrayList<String>(Arrays.asList(buf));
		seq.trimToSize();
		stateOutput.add(seq);
		return;
	}

	for(int aaIndex=0;aaIndex<subStateAATypeOptions.get(depth).size();++aaIndex){
		buf[depth]=subStateAATypeOptions.get(depth).get(aaIndex);
		int nDist=buf[depth].equalsIgnoreCase(wt[depth]) ? dist : dist+1;
		if(nDist>numMaxMut) continue;
		listAllSeqsHelper(subStateAATypeOptions, stateOutput, wt, buf, depth+1, nDist);
	}
}
 
源代码3 项目: openjdk-jdk8u   文件: TypeLibrary.java
public static Type createAnnotationType(Class<? extends Annotation> a) {
    if (shouldPersist(a)) {
        Type type = defineType(a, Type.SUPER_TYPE_ANNOTATION, false);
        if (type != null) {
            SecuritySupport.makeVisibleToJFR(a);
            for (Method method : a.getDeclaredMethods()) {
                type.add(PrivateAccess.getInstance().newValueDescriptor(method.getReturnType(), method.getName()));
            }
            ArrayList<AnnotationElement> aes = new ArrayList<>();
            for (Annotation annotation : resolveRepeatedAnnotations(a.getAnnotations())) {
                AnnotationElement ae = createAnnotation(annotation);
                if (ae != null) {
                    aes.add(ae);
                }
            }
            aes.trimToSize();
            type.setAnnotations(aes);
        }
        return getType(a);
    }
    return null;
}
 
源代码4 项目: pcgen   文件: Globals.java
/**
 * Finds all PObjects that match the passed in type.  All the types listed
 * in aType must match for the object to be returned.
 * @param aPObjectList List of PObjects to search
 * @param aType A "." separated list of TYPEs to match
 * @return List of PObjects matching all TYPEs
 */
public static <T extends CDOMObject> List<T> getPObjectsOfType(final Collection<T> aPObjectList, final String aType)
{
	final ArrayList<T> ret = new ArrayList<>(aPObjectList.size());

	final List<String> typeList = new ArrayList<>();
	final StringTokenizer tok = new StringTokenizer(aType, ".");
	while (tok.hasMoreTokens())
	{
		typeList.add(tok.nextToken());
	}

	for (final T anObject : aPObjectList)
	{
		if (isMatch(typeList, anObject))
		{
			ret.add(anObject);
		}
	}
	ret.trimToSize();
	return ret;
}
 
源代码5 项目: flink   文件: MasterHooks.java
/**
 * Triggers all given master hooks and returns state objects for each hook that
 * produced a state.
 *
 * @param hooks The hooks to trigger
 * @param checkpointId The checkpoint ID of the triggering checkpoint
 * @param timestamp The (informational) timestamp for the triggering checkpoint
 * @param executor An executor that can be used for asynchronous I/O calls
 * @param timeout The maximum time that a hook may take to complete
 *
 * @return A list containing all states produced by the hooks
 *
 * @throws FlinkException Thrown, if the hooks throw an exception, or the state+
 *                        deserialization fails.
 */
public static List<MasterState> triggerMasterHooks(
		Collection<MasterTriggerRestoreHook<?>> hooks,
		long checkpointId,
		long timestamp,
		Executor executor,
		Time timeout) throws FlinkException {

	final ArrayList<MasterState> states = new ArrayList<>(hooks.size());

	for (MasterTriggerRestoreHook<?> hook : hooks) {
		MasterState state = triggerHook(hook, checkpointId, timestamp, executor, timeout);
		if (state != null) {
			states.add(state);
		}
	}

	states.trimToSize();
	return states;
}
 
源代码6 项目: jdk8u-dev-jdk   文件: Package.java
public void trimToSize() {
    super.trimToSize();
    for (int isM = 0; isM <= 1; isM++) {
        ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
        if (members == null)  continue;
        members.trimToSize();
        for (Member m : members) {
            m.trimToSize();
        }
    }
    if (innerClasses != null) {
        innerClasses.trimToSize();
    }
}
 
源代码7 项目: openjdk-jdk9   文件: Package.java
public void trimToSize() {
    super.trimToSize();
    for (int isM = 0; isM <= 1; isM++) {
        ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
        if (members == null)  continue;
        members.trimToSize();
        for (Member m : members) {
            m.trimToSize();
        }
    }
    if (innerClasses != null) {
        innerClasses.trimToSize();
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: TraceHandler.java
private Type createType(Attributes attributes, boolean eventType, long typeId, boolean contantPool) {
    String labelAttribute = ATTRIBUTE_LABEL;
    String id = attributes.getValue(ATTRIBUTE_ID);
    String path = attributes.getValue(ATTRIBUTE_PATH);
    String builtInType = attributes.getValue(ATTRIBUTE_BUILTIN_TYPE);
    String jvmType = attributes.getValue(ATTRIBUTE_JVM_TYPE);

    String typeName = makeTypeName(id, path);
    Type t;
    if (eventType) {
        t = new PlatformEventType(typeName, typeId, false, true);
    } else {
        t = new Type(typeName, null, typeId, contantPool);
    }
    typedef.put(id, typeName);
    if (contantPool) {
        labelAttribute = ATTRIBUTE_HR_NAME; // not "label" for some reason?
        if (builtInType != null) {
            typedef.put(builtInType, typeName);
        }
        if (jvmType != null) {
            typedef.put(jvmType, typeName);
        }
    }
    ArrayList<AnnotationElement> aes = new ArrayList<>();
    if (path != null) {
        aes.add(new AnnotationElement(Category.class, makeCategory(path)));
    }
    String label = attributes.getValue(labelAttribute);
    if (label != null) {
        aes.add(new AnnotationElement(Label.class, label));
    }
    String description = attributes.getValue(ATTRIBUTE_DESCRIPTION);
    if (description != null) {
        aes.add(new AnnotationElement(Description.class, description));
    }
    aes.trimToSize();
    t.setAnnotations(aes);
    return t;
}
 
源代码9 项目: jdk8u_nashorn   文件: Parser.java
/**
 * Same as the other method of the same name - except that the end
 * token type expected is passed as argument to this method.
 *
 * FormalParameterList :
 *      Identifier
 *      FormalParameterList , Identifier
 *
 * See 13
 *
 * Parse function parameter list.
 * @return List of parameter nodes.
 */
private List<IdentNode> formalParameterList(final TokenType endType) {
    // Prepare to gather parameters.
    final ArrayList<IdentNode> parameters = new ArrayList<>();
    // Track commas.
    boolean first = true;

    while (type != endType) {
        // Comma prior to every argument except the first.
        if (!first) {
            expect(COMMARIGHT);
        } else {
            first = false;
        }

        // Get and add parameter.
        final IdentNode ident = getIdent();

        // ECMA 13.1 strict mode restrictions
        verifyStrictIdent(ident, "function parameter");

        parameters.add(ident);
    }

    parameters.trimToSize();
    return parameters;
}
 
源代码10 项目: openjdk-jdk8u   文件: Parser.java
private static <T> List<T> optimizeList(final ArrayList<T> list) {
    switch(list.size()) {
        case 0: {
            return Collections.emptyList();
        }
        case 1: {
            return Collections.singletonList(list.get(0));
        }
        default: {
            list.trimToSize();
            return list;
        }
    }
}
 
源代码11 项目: openjdk-8   文件: Parser.java
private static <T> List<T> optimizeList(ArrayList<T> list) {
    switch(list.size()) {
        case 0: {
            return Collections.emptyList();
        }
        case 1: {
            return Collections.singletonList(list.get(0));
        }
        default: {
            list.trimToSize();
            return list;
        }
    }
}
 
源代码12 项目: TencentKona-8   文件: Compiler.java
private static List<CompilationPhase> concatPhases(final CompilationPhases[] bases) {
    final ArrayList<CompilationPhase> l = new ArrayList<>();
    for(final CompilationPhases base: bases) {
        l.addAll(base.phases);
    }
    l.trimToSize();
    return l;
}
 
源代码13 项目: big-c   文件: UnpickleStack.java
public ArrayList<Object> pop_all_since_marker() {
	ArrayList<Object> result = new ArrayList<Object>();
	Object o = pop();
	while (o != this.MARKER) {
		result.add(o);
		o = pop();
	}
	result.trimToSize();
	Collections.reverse(result);
	return result;
}
 
源代码14 项目: scipio-erp   文件: CallClassMethod.java
public CallClassMethod(Element element, SimpleMethod simpleMethod) throws MiniLangException {
    super(element, simpleMethod);
    if (MiniLangValidate.validationOn()) {
        if (MiniLangValidate.deprecatedCommonOn()) { // SCIPIO
            MiniLangValidate.handleError("<call-class-method> element is deprecated (use <script>)", simpleMethod, element);
        }
        MiniLangValidate.attributeNames(simpleMethod, element, "class-name", "method-name", "ret-field");
        MiniLangValidate.constantAttributes(simpleMethod, element, "class-name", "method-name");
        MiniLangValidate.requiredAttributes(simpleMethod, element, "class-name", "method-name");
        MiniLangValidate.childElements(simpleMethod, element, "string", "field");
    }
    this.className = element.getAttribute("class-name");
    Class<?> methodClass = null;
    try {
        methodClass = ObjectType.loadClass(this.className);
    } catch (ClassNotFoundException e) {
        MiniLangValidate.handleError("Class not found with name " + this.className, simpleMethod, element);
    }
    this.methodClass = methodClass;
    this.methodName = element.getAttribute("method-name");
    this.retFieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("ret-field"));
    List<? extends Element> parameterElements = UtilXml.childElementList(element);
    if (parameterElements.size() > 0) {
        ArrayList<MethodObject<?>> parameterList = new ArrayList<MethodObject<?>>(parameterElements.size());
        for (Element parameterElement : parameterElements) {
            if ("string".equals(parameterElement.getNodeName())) {
                parameterList.add(new StringObject(parameterElement, simpleMethod));
            } else if ("field".equals(parameterElement.getNodeName())) {
                parameterList.add(new FieldObject<Object>(parameterElement, simpleMethod));
            }
        }
        parameterList.trimToSize();
        this.parameters = Collections.unmodifiableList(parameterList);
    } else {
        this.parameters = null;
    }
}
 
源代码15 项目: drftpd   文件: DiskSelectionFilter.java
/**
 * Parses config/diskselection.conf and load the filters.<br>
 * Filters classes MUST follow this naming scheme:<br>
 * First letter uppercase, and add the "Filter" in the end.<br>
 * For example: 'minfreespace' filter, class = MinfreespaceFilter.class<br>
 */
private void loadFilters(Properties p) {
    ArrayList<DiskFilter> filters = new ArrayList<>();
    int i = 1;

    logger.info("Loading DiskSelection filters...");

    for (; ; i++) {
        String filterName = p.getProperty(i + ".filter");

        if (filterName == null) {
            break;
        }

        if (!_filtersMap.containsKey(filterName)) {
            // if we can't find one filter that will be enought to brake the whole chain.
            throw new RuntimeException(filterName + " wasn't loaded.");
        }

        try {
            Class<? extends DiskFilter> clazz = _filtersMap.get(filterName);
            DiskFilter filter = clazz.getConstructor(SIG).newInstance(this, p, i);
            filters.add(filter);
        } catch (Exception e) {
            throw new RuntimeException(i + ".filter = " + filterName, e);
        }
    }

    filters.trimToSize();
    _filters = filters;
}
 
源代码16 项目: scipio-erp   文件: ModelEntity.java
/**
 * Modifies the given collections to be atomic and creates a new read-only instance from them.
 * <p>
 * WARN: Do not pass the collections from existing instance to this without making copy first.
 */
public static Fields optimizeAndCreate(ArrayList<ModelField> fieldsList, Map<String, ModelField> fieldsMap, ArrayList<String> pkFieldNames,
        ArrayList<ModelField> pks, ArrayList<ModelField> nopks) {
    fieldsList.trimToSize();
    pkFieldNames.trimToSize();
    pks.trimToSize();
    nopks.trimToSize();
    return new Fields(fieldsList, fieldsMap, pkFieldNames, pks, nopks);
}
 
源代码17 项目: jolt   文件: CardinalityCompositeSpec.java
public CardinalityCompositeSpec( String rawKey, Map<String, Object> spec ) {
    super( rawKey );

    Map<String, CardinalitySpec> literals = new HashMap<>();
    ArrayList<CardinalitySpec> computed = new ArrayList<>();

    specialChild = null;

    // self check
    if ( pathElement instanceof AtPathElement ) {
        throw new SpecException( "@ CardinalityTransform key, can not have children." );
    }

    List<CardinalitySpec> children = createChildren( spec );

    if ( children.isEmpty() ) {
        throw new SpecException( "Shift CardinalitySpec format error : CardinalitySpec line with empty {} as value is not valid." );
    }

    for ( CardinalitySpec child : children ) {
        literals.put( child.pathElement.getRawKey(), child );

        if ( child.pathElement instanceof LiteralPathElement ) {
            literals.put( child.pathElement.getRawKey(), child );
        }
        // special is it is "@"
        else if ( child.pathElement instanceof AtPathElement ) {
            if ( child instanceof CardinalityLeafSpec ) {
                specialChild = (CardinalityLeafSpec) child;
            } else {
                throw new SpecException( "@ CardinalityTransform key, can not have children." );
            }
        } else {   // star
            computed.add( child );
        }
    }

    // Only the computed children need to be sorted
    Collections.sort( computed, computedKeysComparator );

    computed.trimToSize();
    literalChildren = Collections.unmodifiableMap( literals );
    computedChildren = Collections.unmodifiableList( computed );
}
 
源代码18 项目: ironjacamar   文件: RaParser.java
private Messageadapter parseMessageAdapter(XMLStreamReader reader) throws XMLStreamException, ParserException
{
   ArrayList<MessageListener> messagelistener = new ArrayList<MessageListener>();
   String id = reader.getAttributeValue(null, XML.ATTRIBUTE_ID);

   while (reader.hasNext())
   {
      switch (reader.nextTag())
      {
         case END_ELEMENT : {
            if (XML.ELEMENT_MESSAGEADAPTER.equals(reader.getLocalName()))
            {
               //trimming collections
               messagelistener.trimToSize();

               //building and returning object
               return new MessageAdapterImpl(messagelistener, id);
            }
            else
            {
               switch (reader.getLocalName())
               {
                  case XML.ELEMENT_MESSAGELISTENER :
                     break;
                  default :
                     throw new ParserException(bundle.unexpectedEndTag(reader.getLocalName()));
               }
            }
            break;
         }
         case START_ELEMENT : {
            switch (reader.getLocalName())
            {
               case XML.ELEMENT_MESSAGELISTENER : {
                  messagelistener.add(parseMessageListener(reader));
                  break;
               }
               default :
                  throw new ParserException(bundle.unexpectedElement(reader.getLocalName()));
            }
            break;
         }
      }
   }
   throw new ParserException(bundle.unexpectedEndOfDocument());
}
 
源代码19 项目: TencentKona-8   文件: Compiler.java
private static <T> List<T> concat(final List<T> l1, final List<T> l2) {
    final ArrayList<T> l = new ArrayList<>(l1);
    l.addAll(l2);
    l.trimToSize();
    return l;
}
 
源代码20 项目: common-utils   文件: CollectionUtil.java
/**
 * 创建<code>ArrayList</code>实例
 * 
 * @param iter 迭代器 @see Iterable
 * @return <code>ArrayList</code>实例
 */
public static <E> ArrayList<E> createArrayList(Iterable<? extends E> iter) {

    if (iter instanceof Collection<?>) {
        return new ArrayList<E>((Collection<? extends E>) iter);
    }

    ArrayList<E> list = new ArrayList<E>();

    iterableToCollection(iter, list);

    list.trimToSize();

    return list;
}