Example usage for com.google.common.collect Lists newArrayListWithExpectedSize

List of usage examples for com.google.common.collect Lists newArrayListWithExpectedSize

Introduction

In this page you can find the example usage for com.google.common.collect Lists newArrayListWithExpectedSize.

Prototype

@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayListWithExpectedSize(int estimatedSize) 

Source Link

Document

Creates an ArrayList instance to hold estimatedSize elements, plus an unspecified amount of padding; you almost certainly mean to call #newArrayListWithCapacity (see that method for further advice on usage).

Usage

From source file:com.romeikat.datamessie.core.base.util.DateUtil.java

public static List<LocalDate> getLocalDatesBetween(final LocalDate localDate1, final LocalDate localDate2) {
    if (localDate1 == null || localDate2 == null) {
        return Collections.emptyList();
    }/*w ww  . j  a  v a2  s .c om*/

    if (localDate1.equals(localDate2)) {
        return Lists.newArrayList(localDate1);
    }

    final int daysBetween = (int) Math.abs(ChronoUnit.DAYS.between(localDate1, localDate2));
    final List<LocalDate> localDatesBetween = Lists.newArrayListWithExpectedSize(daysBetween + 1);

    // Add first date
    localDatesBetween.add(localDate1);
    // Add further dates
    final boolean ascending = localDate1.isBefore(localDate2);
    for (int i = 1; i <= daysBetween; i++) {
        final int offset = ascending ? i : -i;
        final LocalDate localDate = localDate1.plusDays(offset);
        localDatesBetween.add(localDate);
    }

    return localDatesBetween;
}

From source file:org.eclipse.xtext.common.types.xtext.ui.JdtBasedSimpleTypeScope.java

@Override
protected Iterable<IEObjectDescription> internalGetAllElements() {
    IJavaProject javaProject = getTypeProvider().getJavaProject();
    if (javaProject == null)
        return Collections.emptyList();
    final List<IEObjectDescription> allScopedElements = Lists.newArrayListWithExpectedSize(25000);
    try {/*from   w w w. java  2  s .  co m*/
        IJavaSearchScope searchScope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
        for (Class<?> clazz : Primitives.ALL_PRIMITIVE_TYPES) {
            IEObjectDescription primitive = createScopedElement(clazz.getName());
            if (primitive != null)
                allScopedElements.add(primitive);
        }
        TypeNameRequestor nameMatchRequestor = new TypeNameRequestor() {
            @Override
            public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                    char[][] enclosingTypeNames, String path) {
                StringBuilder fqName = new StringBuilder(packageName.length + simpleTypeName.length + 1);
                if (packageName.length != 0) {
                    fqName.append(packageName);
                    fqName.append('.');
                }
                for (char[] enclosingType : enclosingTypeNames) {
                    fqName.append(enclosingType);
                    fqName.append('.');
                }
                fqName.append(simpleTypeName);
                String fullyQualifiedName = fqName.toString();
                InternalEObject proxy = createProxy(fullyQualifiedName);
                Map<String, String> userData = null;
                if (enclosingTypeNames.length == 0) {
                    userData = ImmutableMap.of("flags", String.valueOf(modifiers));
                } else {
                    userData = ImmutableMap.of("flags", String.valueOf(modifiers), "inner", "true");
                }
                IEObjectDescription eObjectDescription = EObjectDescription.create(
                        getQualifiedNameConverter().toQualifiedName(fullyQualifiedName), proxy, userData);
                if (eObjectDescription != null)
                    allScopedElements.add(eObjectDescription);
            }
        };
        collectContents(searchScope, nameMatchRequestor);
    } catch (JavaModelException e) {
        // ignore
    }
    return allScopedElements;
}

From source file:tachyon.client.keyvalue.hadoop.KeyValueOutputCommitter.java

private List<TachyonURI> getTaskTemporaryStores(JobConf conf) throws IOException {
    TachyonURI taskOutputURI = KeyValueOutputFormat.getTaskOutputURI(conf);
    Path taskOutputPath = new Path(taskOutputURI.toString());
    FileSystem fs = taskOutputPath.getFileSystem(conf);
    FileStatus[] subDirs = fs.listStatus(taskOutputPath);
    List<TachyonURI> temporaryStores = Lists.newArrayListWithExpectedSize(subDirs.length);
    for (FileStatus subDir : subDirs) {
        temporaryStores.add(taskOutputURI.join(subDir.getPath().getName()));
    }// w ww  .ja  v  a2s  . c  o m
    return temporaryStores;
}

From source file:com.romeikat.datamessie.core.base.util.CollectionUtil.java

public List<Integer> createIntegerList(Integer min, final int max) {
    final List<Integer> result = Lists.newArrayListWithExpectedSize(max);
    if (min == null) {
        min = 0;//  ww  w.  j a  v a 2 s .  c om
    }
    for (int i = 0; i < max; i++) {
        result.add(i);
    }
    return result;
}

From source file:ru.codeinside.gses.webui.components.HistoricTaskInstancesQuery.java

@Override
public List<Item> loadItems(final int startIndex, final int count) {
    List<HistoricTaskInstance> histories = Functions
            .withHistory(new Function<HistoryService, List<HistoricTaskInstance>>() {
                public List<HistoricTaskInstance> apply(HistoryService srv) {
                    return srv.createHistoricTaskInstanceQuery().processInstanceId(processDefinitionId)
                            .listPage(startIndex, count);
                }//  w ww . j  a v  a 2s . c om
            });
    List<Item> items = Lists.newArrayListWithExpectedSize(histories.size());
    for (final HistoricTaskInstance i : histories) {
        String startTime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(i.getStartTime());
        String endTime = (i.getEndTime() != null)
                ? new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(i.getEndTime())
                : "";
        Bid bid = AdminServiceProvider.get().getBidByTask(taskId);
        String bidId = bid != null ? bid.getId().toString() : "";
        PropertysetItem item = new PropertysetItem();
        item.addItemProperty("id", new ObjectProperty<String>(bidId));
        item.addItemProperty("hid", new ObjectProperty<HistoricTaskInstance>(i));
        item.addItemProperty("name", new ObjectProperty<String>(i.getName()));
        item.addItemProperty("startDate", new ObjectProperty<String>(startTime));
        item.addItemProperty("endDate", new ObjectProperty<String>(endTime));
        item.addItemProperty("assignee",
                new ObjectProperty<String>(i.getAssignee() != null ? i.getAssignee() : ""));
        Date time = i.getEndTime() == null ? i.getStartTime() : i.getEndTime();
        Button button = new Button("?",
                new ArchiveFactory.ShowClickListener(i.getTaskDefinitionKey(), bidId, time));
        button.setEnabled(i.getAssignee() != null);
        item.addItemProperty("form", new ObjectProperty<Component>(button));
        items.add(item);
    }
    return items;
}

From source file:org.apache.phoenix.pig.hadoop.PhoenixInputSplit.java

@Override
public void readFields(DataInput input) throws IOException {
    int count = WritableUtils.readVInt(input);
    scans = Lists.newArrayListWithExpectedSize(count);
    for (int i = 0; i < count; i++) {
        byte[] protoScanBytes = new byte[WritableUtils.readVInt(input)];
        input.readFully(protoScanBytes);
        ClientProtos.Scan protoScan = ClientProtos.Scan.parseFrom(protoScanBytes);
        Scan scan = ProtobufUtil.toScan(protoScan);
        scans.add(scan);//from w w  w . ja  v  a  2  s . co m
    }
    init();
}

From source file:org.sonatype.nexus.configuration.ModelloUtils.java

/**
 * {@link Map} to {@link List} of {@link CProps} converter, to ease handling of these thingies.
 *///from   ww w  . j av  a  2  s .  c  o  m
public static List<CProps> getConfigListFromMap(final Map<String, String> map) {
    final List<CProps> result = Lists.newArrayListWithExpectedSize(map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        final CProps cprop = new CProps();
        cprop.setKey(entry.getKey());
        cprop.setValue(entry.getValue());
        result.add(cprop);
    }
    return result;
}

From source file:co.cask.cdap.data.format.StructuredRecordDatumReader.java

@Override
protected Object newArray(Object old, int size, org.apache.avro.Schema schema) {
    if (old instanceof Collection) {
        ((Collection) old).clear();
        return old;
    } else {/*  w w w.j  ava  2s . c o  m*/
        return Lists.newArrayListWithExpectedSize(size);
    }
}

From source file:org.apache.crunch.impl.mr.plan.Edge.java

public Map<NodePath, PCollectionImpl> getSplitPoints(boolean breakpointsOnly) {
    List<NodePath> np = Lists.newArrayList(paths);
    List<PCollectionImpl<?>> smallestOverallPerPath = Lists.newArrayListWithExpectedSize(np.size());
    Map<PCollectionImpl<?>, Set<Integer>> pathCounts = Maps.newTreeMap(PCOL_CMP);
    Map<NodePath, PCollectionImpl> splitPoints = Maps.newHashMap();
    for (int i = 0; i < np.size(); i++) {
        long bestSize = Long.MAX_VALUE;
        boolean breakpoint = false;
        PCollectionImpl<?> best = null;
        for (PCollectionImpl<?> pc : np.get(i)) {
            if (!(pc instanceof BaseGroupedTable) && (!breakpointsOnly || pc.isBreakpoint())) {
                if (pc.isBreakpoint()) {
                    if (!breakpoint || pc.getSize() < bestSize) {
                        best = pc;/*from   w  ww. j av a 2s.  com*/
                        bestSize = pc.getSize();
                        breakpoint = true;
                    }
                } else if (!breakpoint && pc.getSize() < bestSize) {
                    best = pc;
                    bestSize = pc.getSize();
                }
                Set<Integer> cnts = pathCounts.get(pc);
                if (cnts == null) {
                    cnts = Sets.newHashSet();
                    pathCounts.put(pc, cnts);
                }
                cnts.add(i);
            }
        }
        smallestOverallPerPath.add(best);
        if (breakpoint) {
            splitPoints.put(np.get(i), best);
        }
    }

    Set<Integer> missing = Sets.newHashSet();
    for (int i = 0; i < np.size(); i++) {
        if (!splitPoints.containsKey(np.get(i))) {
            missing.add(i);
        }
    }

    if (breakpointsOnly && missing.size() > 0) {
        // We can't create new splits in this mode
        return ImmutableMap.of();
    } else if (missing.isEmpty()) {
        return splitPoints;
    } else {
        // Need to either choose the smallest collection from each missing path,
        // or the smallest single collection that is on all paths as the split target.
        Set<PCollectionImpl<?>> smallest = Sets.newHashSet();
        long smallestSize = 0;
        for (Integer id : missing) {
            PCollectionImpl<?> s = smallestOverallPerPath.get(id);
            if (!smallest.contains(s)) {
                smallest.add(s);
                smallestSize += s.getSize();
            }
        }

        PCollectionImpl<?> singleBest = null;
        long singleSmallestSize = Long.MAX_VALUE;
        for (Map.Entry<PCollectionImpl<?>, Set<Integer>> e : pathCounts.entrySet()) {
            if (Sets.difference(missing, e.getValue()).isEmpty() && e.getKey().getSize() < singleSmallestSize) {
                singleBest = e.getKey();
                singleSmallestSize = singleBest.getSize();
            }
        }

        if (smallestSize < singleSmallestSize) {
            for (Integer id : missing) {
                splitPoints.put(np.get(id), smallestOverallPerPath.get(id));
            }
        } else {
            for (Integer id : missing) {
                splitPoints.put(np.get(id), singleBest);
            }
        }
    }
    return splitPoints;
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.BytecodeInvocable.java

@Override
public final BytecodeExpression invoke(final Location loc, List<BytecodeExpression> args) {
    final List<BytecodeExpression> argsCopy = Lists.newArrayListWithExpectedSize(args.size());
    for (BytecodeExpression arg : args) {
        Preconditions.checkNotNull(arg);
        argsCopy.add(arg);/*from  w w  w  .j  ava  2s .c  o m*/
    }
    return new BaseTypeExpression(returnType) {
        @Override
        public void generate(CodeEmitter code) {
            BytecodeInvocable.this.generate(loc, code, argsCopy);
        }
    };
}