List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize
@GwtCompatible(serializable = true) public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize)
From source file:com.google.appinventor.server.ProjectServiceImpl.java
/** * Returns a list with pairs of project id and name. * * @return list of pairs of project IDs names found by backend *///from w w w. j av a 2s . c o m @Override public List<UserProject> getProjectInfos() { String userId = userInfoProvider.getUserId(); List<Long> projectIds = storageIo.getProjects(userId); List<UserProject> projectInfos = Lists.newArrayListWithExpectedSize(projectIds.size()); for (Long projectId : projectIds) { projectInfos.add(makeUserProject(userId, projectId)); } return projectInfos; }
From source file:com.basistech.rosette.dm.ConvertFromPreAdm11.java
static void doResolvedConversion(ListAttribute<Entity> newResolved, ListAttribute<EntityMention> oldMentions, ListAttribute<ResolvedEntity> oldResolved, ImmutableMap.Builder<String, BaseAttribute> builder) { if (oldMentions == null) { doNoMentionConversion(oldResolved, builder); return;/*from w w w . j a v a 2s . c o m*/ } int maxChainId = -1; for (EntityMention oldMention : oldMentions) { if (oldMention.getCoreferenceChainId() != null) { maxChainId = Math.max(maxChainId, oldMention.getCoreferenceChainId()); } } maxChainId = Math.max(maxChainId, oldMentions.size()); ResolvedEntity[] resolvedByChainId = new ResolvedEntity[maxChainId + 1]; if (oldResolved != null) { for (ResolvedEntity resolvedEntity : oldResolved) { if (resolvedEntity.getCoreferenceChainId() != null) { resolvedByChainId[resolvedEntity.getCoreferenceChainId()] = resolvedEntity; } else { throw new RosetteRuntimeException("Resolved entity with no coref chain id."); } } } // Note that indoc chain ids can be sparse, or altogether absent. // Absent is important, as it means that no indoc happened. // If any indoc happened, all the mentions have indoc chains. boolean indocPresent = !oldMentions.isEmpty() && oldMentions.get(0).getCoreferenceChainId() != null; int[] newIndices = new int[maxChainId + 1]; //chain ids cannot be larger than the count of mentions. int[] chainToIndex = new int[maxChainId + 1]; Arrays.fill(chainToIndex, -1); int newEntityCount = 0; for (int oldIndex = 0; oldIndex < oldMentions.size(); oldIndex++) { EntityMention em = oldMentions.get(oldIndex); if (em.getCoreferenceChainId() != null && em.getCoreferenceChainId() != -1) { if (chainToIndex[em.getCoreferenceChainId()] == -1) { chainToIndex[em.getCoreferenceChainId()] = newEntityCount++; } newIndices[oldIndex] = chainToIndex[em.getCoreferenceChainId()]; } else { newIndices[oldIndex] = newEntityCount++; } } List<List<EntityMention>> mentionsByEntities = Lists.newArrayListWithExpectedSize(newEntityCount); for (int x = 0; x < newEntityCount; x++) { mentionsByEntities.add(Lists.<EntityMention>newArrayList()); } /* For each coref chain, the head is the entity whose index in the old mentions * is equal to the chain id. */ int[] heads = new int[newEntityCount]; for (int oldIndex = 0; oldIndex < oldMentions.size(); oldIndex++) { EntityMention em = oldMentions.get(oldIndex); int newIndex = newIndices[oldIndex]; mentionsByEntities.get(newIndex).add(em); if (em.getCoreferenceChainId() != null && em.getCoreferenceChainId() == oldIndex) { heads[newIndex] = mentionsByEntities.get(newIndex).size() - 1; } } ListAttribute.Builder<Entity> elBuilder = buildEntities(newResolved, oldMentions, resolvedByChainId, indocPresent, mentionsByEntities, heads); builder.put(AttributeKey.ENTITY.key(), elBuilder.build()); }
From source file:com.google.template.soy.jssrc.internal.JsSrcUtils.java
public static String getJsTypeExpr(SoyType type, boolean addParensIfNeeded, boolean addRequiredIfNeeded) { String nonNullablePrefix = addRequiredIfNeeded ? "!" : ""; switch (type.getKind()) { case ANY:/*from ww w . j av a 2s. c o m*/ return "*"; case UNKNOWN: // Add parens to avoid confusion w/ the leading ? of a nullable type return "(?)"; case NULL: return "null"; case BOOL: return "boolean"; case STRING: return "string"; case INT: case FLOAT: return "number"; case LIST: { ListType listType = (ListType) type; if (listType.getElementType().getKind() == SoyType.Kind.ANY) { return nonNullablePrefix + "Array"; } return nonNullablePrefix + "Array<" + getJsTypeExpr(listType.getElementType(), false, true) + ">"; } case MAP: { MapType mapType = (MapType) type; if (mapType.getKeyType().getKind() == SoyType.Kind.ANY && mapType.getValueType().getKind() == SoyType.Kind.ANY) { return nonNullablePrefix + "Object<?,?>"; } String keyTypeName = getJsTypeExpr(mapType.getKeyType(), false, true); String valueTypeName = getJsTypeExpr(mapType.getValueType(), false, true); return nonNullablePrefix + "Object<" + keyTypeName + "," + valueTypeName + ">"; } case RECORD: { RecordType recordType = (RecordType) type; if (recordType.getMembers().isEmpty()) { return "!Object"; } List<String> members = Lists.newArrayListWithExpectedSize(recordType.getMembers().size()); for (Map.Entry<String, SoyType> member : recordType.getMembers().entrySet()) { members.add(member.getKey() + ": " + getJsTypeExpr(member.getValue(), true, true)); } return "{" + Joiner.on(", ").join(members) + "}"; } case UNION: { UnionType unionType = (UnionType) type; SortedSet<String> typeNames = Sets.newTreeSet(); boolean isNullable = unionType.isNullable(); boolean hasNullableMember = false; for (SoyType memberType : unionType.getMembers()) { if (memberType.getKind() == SoyType.Kind.NULL) { continue; } if (memberType instanceof SanitizedType) { typeNames.add(getJsTypeName(memberType)); typeNames.add("string"); hasNullableMember = true; continue; } if (JsSrcUtils.isDefaultOptional(memberType)) { hasNullableMember = true; } String typeExpr = getJsTypeExpr(memberType, false, !isNullable); if (typeExpr.equals("?")) { throw new IllegalStateException("Type: " + unionType + " contains an unknown"); } typeNames.add(typeExpr); } if (isNullable && !hasNullableMember) { typeNames.add("null"); } if (isNullable) { typeNames.add("undefined"); } if (typeNames.size() != 1) { String result = Joiner.on("|").join(typeNames); if (addParensIfNeeded) { result = "(" + result + ")"; } return result; } else { return typeNames.first(); } } default: if (type instanceof SanitizedType) { String result = NodeContentKinds .toJsSanitizedContentCtorName(((SanitizedType) type).getContentKind()) + "|string"; if (addParensIfNeeded) { result = "(" + result + ")"; } return result; } return getJsTypeName(type); } }
From source file:com.zimbra.cs.account.DistributionList.java
/** * Keep in sync with BasicInfo.getAllAddrsAsGroupMember *//*from w w w.j av a 2 s. c om*/ @Override public String[] getAllAddrsAsGroupMember() throws ServiceException { String aliases[] = getAliases(); List<String> addrs = Lists.newArrayListWithExpectedSize(aliases.length + 1); String myName = getName(); addrs.add(myName); for (String alias : aliases) { /* the name is usually a zimbraMailAlias too */ if (!alias.equals(myName)) { addrs.add(alias); } } return addrs.toArray(new String[0]); }
From source file:eu.interedition.collatex.nmerge.graph.VariantGraph.java
/** * Get the data of the specified version * * @param version the id of the version to read * @return the version's data as a byte array *//*w ww .j a va 2s . co m*/ List<T> getVersion(Witness version) { VariantGraphNode<T> temp = start; int len = 0; while (temp != null && !temp.equals(end)) { VariantGraphArc<T> a = temp.pickOutgoingArc(version); len += a.dataLen(); temp = a.to; } final List<T> versionData = Lists.newArrayListWithExpectedSize(len); temp = start; while (temp != null && !temp.equals(end)) { VariantGraphArc<T> a = temp.pickOutgoingArc(version); versionData.addAll(a.getData()); temp = a.to; } return versionData; }
From source file:org.eclipse.xtext.ui.editor.syntaxcoloring.MergingHighlightedPositionAcceptor.java
@SuppressWarnings("null") private void mergePositions(int listIdx, int exclusiveEndOffset, int timestamp, IntToStringArray[] ids) { int i = listIdx; List<LightweightPosition> newPositions = null; LightweightPosition prev = null;/*from www. j a v a 2 s. c o m*/ while (i < getPositions().size()) { LightweightPosition next = getPositions().get(i); if (next.getOffset() >= exclusiveEndOffset) { newPositions = addPendingPosition(prev, exclusiveEndOffset, timestamp, ids, newPositions); partialSortPositions(listIdx, exclusiveEndOffset, i, newPositions); return; } if (prev != null) { int prevEnd = prev.getOffset() + prev.getLength(); if (prevEnd < next.getOffset()) { if (newPositions == null) newPositions = Lists.newArrayListWithExpectedSize(4); newPositions.add(new LightweightPosition(prevEnd, next.getOffset() - prevEnd, timestamp, ids)); } } if (next.getOffset() + next.getLength() <= exclusiveEndOffset) { next.merge(ids); } else { int oldLength = next.getLength(); next.setLength(exclusiveEndOffset - next.getOffset()); if (newPositions == null) newPositions = Lists.newArrayListWithExpectedSize(4); newPositions.add(new LightweightPosition(next.getOffset() + next.getLength(), oldLength - next.getLength(), next.getTimestamp(), next.getIds())); next.merge(ids); } i++; prev = next; } newPositions = addPendingPosition(prev, exclusiveEndOffset, timestamp, ids, newPositions); partialSortPositions(listIdx, exclusiveEndOffset, i, newPositions); }
From source file:com.romeikat.datamessie.core.processing.service.fulltext.query.QueryUtil.java
public List<String> getIndexTerms(final FullTextSession fullTextSession, final int luceneDocumentId, final Class<?> clazz, final String field) { final IndexReader indexReader = fullTextSession.getSearchFactory().getIndexReaderAccessor().open(clazz); try {/*from w w w. j a v a 2 s.co m*/ final Terms terms = indexReader.getTermVector(luceneDocumentId, field); final List<String> termsList = Lists.newArrayListWithExpectedSize((int) terms.size()); final TermsEnum termsEnum = terms.iterator(); BytesRef text; while ((text = termsEnum.next()) != null) { final String term = text.utf8ToString(); termsList.add(term); } return termsList; } catch (final IOException e) { LOG.error("Could not determine index terms", e); return null; } }
From source file:org.eclipse.xtext.nodemodel.impl.RootNode.java
/** * <p>Computes the line breaks in the given text and returns an array of offsets. * A line break is either <code>\r\n</code>, <code>\n</code>, or a single <code>\r</code>.</p> * This implementation was heavily adapted from <code>org.eclipse.jface.text.DefaultLineTracker</code>. * @param text the text whose line-breaks should be computed. May not be <code>null</code>. * @return the array of line-break offsets in the given text. May be empty but is never <code>null</code>. * @since 2.0//from w w w.ja v a 2 s . co m */ protected int[] computeLineBreaks(String text) { List<Integer> list = Lists.newArrayListWithExpectedSize(50); char ch; int length = text.length(); for (int i = 0; i < length; i++) { ch = text.charAt(i); if (ch == '\r') { list.add(i); if (i + 1 < length) { if (text.charAt(i + 1) == '\n') { i++; } } } else if (ch == '\n') { list.add(i); } } int[] result = new int[list.size()]; for (int i = 0; i < result.length; i++) { result[i] = list.get(i).intValue(); } return result; }
From source file:org.artifactory.webapp.actionable.model.LocalRepoActionableItem.java
@Override public List<ActionableItem> getChildren(AuthorizationService authService) { boolean childrenCacheUpToDate = childrenCacheUpToDate(); if (!childrenCacheUpToDate) { RepositoryService repoService = getRepoService(); List<ItemInfo> items = repoService.getChildren(getRepoPath()); children = Lists.newArrayListWithExpectedSize(items.size()); for (ItemInfo pathItem : items) { RepoPath repoPath = pathItem.getRepoPath(); if (!repoService.isRepoPathVisible(repoPath)) { continue; }/*from w ww . j a va 2s. c o m*/ //No need to check for null as children is set before the iteration //noinspection ConstantConditions children.add(getChildItem(pathItem, pathItem.getRelPath(), compactAllowed)); } } return children; }
From source file:ei.ne.ke.cassandra.cql3.template.DeleteStatementBuilder.java
/** * Adds a relation for the given identifier and values for an IN clause. * @param identifier the identifier./*from w w w . j a v a 2 s . c o m*/ * @param in the values used in the IN clause * @return this builder. */ public DeleteStatementBuilder where(String identifier, Collection<String> ins) { Collection<Term> terms = Lists.newArrayListWithExpectedSize(ins.size()); for (String in : ins) { terms.add(new Term(in)); } relations.add(new In(new Identifier(identifier), terms)); return this; }