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:org.apache.druid.query.metadata.metadata.ListColumnIncluderator.java
@Override public byte[] getCacheKey() { int size = 1; List<byte[]> columns = Lists.newArrayListWithExpectedSize(this.columns.size()); for (String column : this.columns) { final byte[] bytes = StringUtils.toUtf8(column); columns.add(bytes);/*from ww w . jav a 2s .com*/ size += bytes.length + 1; } final ByteBuffer bytes = ByteBuffer.allocate(size).put(LIST_CACHE_PREFIX); for (byte[] column : columns) { bytes.put(column); bytes.put((byte) 0xff); } return bytes.array(); }
From source file:co.cask.cdap.data2.dataset2.lib.table.SplitsUtil.java
/** * Simplest possible implementation of getSplits. Takes the given start and end and divides the key space in * between into (almost) even partitions, using a long integer approximation of the keys. *//*from w ww . jav a2 s .c o m*/ static List<KeyRange> primitiveGetSplits(int numSplits, byte[] start, byte[] stop) { // if the range is empty, return no splits if (start != null && stop != null && Bytes.compareTo(start, stop) >= 0) { return Collections.emptyList(); } if (numSplits <= 0) { numSplits = DEFAULT_NUMBER_OF_SPLITS; } // for simplicity, we construct a long from the begin and end, divide the resulting long range into approximately // even splits, and convert the boundaries back to nyte array keys. long begin = longForKey(start, false); long end = longForKey(stop, true); double splitSize = ((double) (end - begin)) / ((double) numSplits); // each range will start with the stop key of the previous range. // start key of the first range is either the given start, or the least possible key {0}; List<KeyRange> ranges = Lists.newArrayListWithExpectedSize(numSplits); byte[] current = start == null ? new byte[] { 0x00 } : start; for (int i = 1; i < numSplits; i++) { long bound = begin + (long) (splitSize * i); byte[] next = keyForBound(bound); // due to rounding and truncation, we may get a bound that is the same as the previous (or if the previous is // the start key, less than that). We may also get a bound that exceeds the stop key. In both cases we want to // ignore this bound and continue. if (Bytes.compareTo(current, next) < 0 && (stop == null || Bytes.compareTo(next, stop) < 0)) { ranges.add(new KeyRange(current, next)); current = next; } } // end of the last range is always the given stop of the range to cover ranges.add(new KeyRange(current, stop)); return ranges; }
From source file:com.tysanclan.site.projectewok.event.handlers.ResetGroupLeaderOnTermination.java
@Override public EventResult onEvent(MembershipTerminatedEvent event) { User user = event.getSubject();/*from www . jav a 2 s.co m*/ List<Group> leaderless = groupService.clearGroupLeaderStatus(user); List<Event<?>> events = Lists.newArrayListWithExpectedSize(leaderless.size()); for (Group g : leaderless) { events.add(new GroupWithoutLeaderEvent(g)); } return EventResult.ok(events); }
From source file:org.apache.bookkeeper.clients.utils.NetUtils.java
/** * Get the list of endpoints from an endpoint string. * * @param endpointStr an endpoint string. * @return list of endpoints./* ww w. ja v a2 s . c o m*/ */ public static List<Endpoint> parseEndpoints(String endpointStr) { String[] endpointParts = StringUtils.split(endpointStr, ','); checkArgument(endpointParts.length > 0, "Invalid endpoint strings %s", endpointStr); List<Endpoint> endpoints = Lists.newArrayListWithExpectedSize(endpointParts.length); for (String endpointPart : endpointParts) { endpoints.add(parseEndpoint(endpointPart)); } return endpoints; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.BytecodeInvocable.java
@Override public GambitCreator.Invocable prefix(List<BytecodeExpression> arguments) { if (arguments.isEmpty()) { return this; }//from www . ja v a 2 s .co m Preconditions.checkState(arguments.size() <= argTypes.size(), "Invocable passed too many arguments to prefix"); List<BytecodeExpression> prefixed = Lists.newArrayListWithExpectedSize(arguments.size()); prefixed.addAll(arguments); return new PrefixedBytecodeInvocable(returnType, prefixed, argTypes.subList(prefixed.size(), argTypes.size()), this); }
From source file:org.summer.dsl.xbase.typesystem.override.ParameterizedResolvedFeatures.java
protected List<JvmFeature> computeAllFeatures(List<JvmFeature> unfiltered) { List<JvmFeature> result = Lists.newArrayListWithExpectedSize(unfiltered.size()); Multimap<String, AbstractResolvedOperation> processed = HashMultimap.create(); computeAllFeatures(unfiltered, processed, result); return Collections.unmodifiableList(result); }
From source file:ru.codeinside.gses.webui.declarant.ServiceQuery.java
@Override public List<Item> loadItems(final int start, final int count) { final List<Item> items = Lists.newArrayListWithExpectedSize(services.size()); List<Service> serviceList = showActive ? Flash.flash().getDeclarantService().selectActiveServices(type, start, count) : DeclarantUtils.sublist(services, start, count); for (Service s : serviceList) { final PropertysetItem item = new PropertysetItem(); item.addItemProperty("id", new ObjectProperty<Long>(s.getId())); item.addItemProperty("name", new ObjectProperty<String>(s.getName())); items.add(item);// w w w . ja v a 2 s . c o m } return items; }
From source file:com.cloudera.exhibit.sql.ResultSetTable.java
public static RelProtoDataType fromMetadata(ResultSetMetaData metadata) throws SQLException { int cols = metadata.getColumnCount(); List<String> names = Lists.newArrayListWithExpectedSize(cols); List<Class> javaTypes = Lists.newArrayListWithExpectedSize(cols); for (int i = 1; i <= cols; i++) { names.add(metadata.getColumnLabel(i)); javaTypes.add(TypeUtils.getJavaClassForSQLType(metadata.getColumnType(i))); }//from w w w . j av a 2s . c om return new SQLTypeProtoDataType(names, javaTypes); }
From source file:org.eclipse.xtext.validation.FeatureBasedDiagnostic.java
@Override public List<?> getData() { List<Object> result = Lists.newArrayListWithExpectedSize(3); result.add(getSourceEObject());//ww w . j av a 2s . c o m if (feature != null) { result.add(feature); result.add(index); } if (getIssueData() != null) { result.add(getIssueData()); } return result; }
From source file:com.cloudera.science.ml.client.params.CentersParameters.java
public List<Centers> getCenters() throws IOException { List<MLCenters> centers = AvroIO.read(MLCenters.class, new File(centersFile)); if (!centerIds.isEmpty()) { List<MLCenters> filter = Lists.newArrayListWithExpectedSize(centerIds.size()); for (Integer centerId : centerIds) { filter.add(centers.get(centerId)); }//from w w w .j a v a 2 s .c om centers = filter; } return Lists.transform(centers, VectorConvert.TO_CENTERS); }