Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

In this page you can find the example usage for java.util List stream.

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.jaredrummler.android.devices.Main.java

private static void createPopularDevicesJsonFile(List<String[]> devices) throws IOException {
    List<DeviceInfo> deviceInfos = new ArrayList<>();
    List<String[]> commonDevices = new ArrayList<>();
    for (String name : POPULAR_DEVICES) {
        devices.stream().filter(arr -> arr[1].equals(name)).forEach(arr -> {
            deviceInfos.add(new DeviceInfo(arr[0], arr[1], arr[2], arr[3]));
            commonDevices.add(arr);//  w  w w  . j  a v a  2  s . c o  m
        });
    }
    FileUtils.write(new File(OUTPUT_DIR, "popular-devices.json"), PRETTY_GSON.toJson(deviceInfos));
    FileUtils.write(new File(OUTPUT_DIR, "popular-devices-min.json"), GSON.toJson(deviceInfos));
    FileUtils.write(new File(OUTPUT_DIR, "common-devices.json"), PRETTY_GSON.toJson(commonDevices));
    FileUtils.write(new File(OUTPUT_DIR, "common-devices-min.json"), GSON.toJson(commonDevices));
}

From source file:com.uber.hoodie.common.util.CompactionUtils.java

/**
 * Get all file-ids with pending Compaction operations and their target compaction instant time
 *
 * @param metaClient Hoodie Table Meta Client
 *//*from ww  w .j  a va  2  s. c o m*/
public static Map<String, Pair<String, HoodieCompactionOperation>> getAllPendingCompactionOperations(
        HoodieTableMetaClient metaClient) {
    List<Pair<HoodieInstant, HoodieCompactionPlan>> pendingCompactionPlanWithInstants = getAllPendingCompactionPlans(
            metaClient);

    Map<String, Pair<String, HoodieCompactionOperation>> fileIdToPendingCompactionWithInstantMap = new HashMap<>();
    pendingCompactionPlanWithInstants.stream().flatMap(instantPlanPair -> {
        HoodieInstant instant = instantPlanPair.getKey();
        HoodieCompactionPlan compactionPlan = instantPlanPair.getValue();
        List<HoodieCompactionOperation> ops = compactionPlan.getOperations();
        if (null != ops) {
            return ops.stream().map(op -> {
                return Pair.of(op.getFileId(), Pair.of(instant.getTimestamp(), op));
            });
        } else {
            return Stream.empty();
        }
    }).forEach(pair -> {
        // Defensive check to ensure a single-fileId does not have more than one pending compaction
        if (fileIdToPendingCompactionWithInstantMap.containsKey(pair.getKey())) {
            String msg = "Hoodie File Id (" + pair.getKey()
                    + ") has more thant 1 pending compactions. Instants: " + pair.getValue() + ", "
                    + fileIdToPendingCompactionWithInstantMap.get(pair.getKey());
            throw new IllegalStateException(msg);
        }
        fileIdToPendingCompactionWithInstantMap.put(pair.getKey(), pair.getValue());
    });
    return fileIdToPendingCompactionWithInstantMap;
}

From source file:Main.java

/**
 * Gets the next or same closest date from the specified days in
 * {@code daysOfWeek List} at specified {@code hour} and {@code min}.
 * //from   ww w. java 2  s .co  m
 * @param daysOfWeek
 *          the days of week
 * @param hour
 *          the hour
 * @param min
 *          the min
 * @return the next or same date from the days of week at specified time
 * @throws IllegalArgumentException
 *           if the {@code daysOfWeek List} is empty.
 */
public static LocalDateTime getNextClosestDateTime(List<DayOfWeek> daysOfWeek, int hour, int min)
        throws IllegalArgumentException {
    if (daysOfWeek.isEmpty()) {
        throw new IllegalArgumentException("daysOfWeek should not be empty.");
    }

    final LocalDateTime dateNow = LocalDateTime.now();
    final LocalDateTime dateNowWithDifferentTime = dateNow.withHour(hour).withMinute(min).withSecond(0);

    // @formatter:off
    return daysOfWeek.stream().map(d -> dateNowWithDifferentTime.with(TemporalAdjusters.nextOrSame(d)))
            .filter(d -> d.isAfter(dateNow)).min(Comparator.naturalOrder())
            .orElse(dateNowWithDifferentTime.with(TemporalAdjusters.next(daysOfWeek.get(0))));
    // @formatter:on
}

From source file:com.diffplug.gradle.FileMisc.java

public static List<File> parseListFile(Project project, List<Object> inputs) {
    return inputs.stream().map(project::file).collect(Collectors.toList());
}

From source file:com.thinkbiganalytics.metadata.jpa.support.GenericQueryDslFilter.java

public static BooleanBuilder buildOrFilter(EntityPathBase basePath, String filterString) {
    List<SearchCriteria> searchCriterias = parseFilterString(filterString);
    searchCriterias.stream().forEach(searchCriteria -> searchCriteria.setAndOr(SearchCriteria.AND_OR.OR));
    return buildFilter(basePath, searchCriterias);
}

From source file:de.pixida.logtest.automatondefinitions.AutomatonDefinitionToJsonConverter.java

private static JSONArray convertNodes(final List<? extends INodeDefinition> definedNodes,
        final List<? extends IEdgeDefinition> definedEdges) {
    final JSONArray nodes = new JSONArray();
    for (final INodeDefinition definedNode : definedNodes) {
        final JSONObject node = convertNode(definedNode);

        final JSONArray outgoingEdges = new JSONArray();
        definedEdges.stream().filter(edge -> edge.getSource() == definedNode)
                .map(definedOutgoingEdge -> convertEdge(definedOutgoingEdge))
                .forEach(convertedDefinedOutgoingEdge -> outgoingEdges.put(convertedDefinedOutgoingEdge));
        if (outgoingEdges.length() > 0) {
            node.put(JsonKey.NODE_OUTGOING_EDGES.getKey(), outgoingEdges);
        }//from   ww w  .j  av a 2  s.co  m

        nodes.put(node);
    }
    return nodes;
}

From source file:com.wrmsr.nativity.x86.DisImpl.java

public static void run(ByteTrie<Entry> trie) {
    byte[] bytes;
    // = new byte[] {(byte) 0x55, (byte) 0x48, (byte) 0x89, (byte) 0xe5, (byte) 0x48, (byte) 0x8d, (byte) 0x3d, (byte) 0x35, (byte) 0x00, (byte) 0x00, (byte) 0x00,
    //               (byte) 0xe8, (byte) 0x4e, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x31, (byte) 0xc0, (byte) 0x5d, (byte) 0xc3, (byte) 0x66, (byte) 0x0f,
    //               (byte) 0x1f, (byte) 0x44, (byte) 0x00, (byte) 0x00, (byte) 0x66, (byte) 0x0f, (byte) 0x1f, (byte) 0x44, (byte) 0x00, (byte) 0x00};

    bytes = new byte[] { (byte) 0x64, (byte) 0x8b, (byte) 0x04, (byte) 0x25, (byte) 0xd4, (byte) 0x02,
            (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x8b, (byte) 0x34, (byte) 0x25, (byte) 0xd0,
            (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x85, (byte) 0xf6, (byte) 0x75, (byte) 0x2c,
            (byte) 0xb8, (byte) 0xba, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0f, (byte) 0x05,
            (byte) 0x89, (byte) 0xc6, (byte) 0x64, (byte) 0x89, (byte) 0x04, (byte) 0x25, (byte) 0xd0,
            (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x63, (byte) 0xd7, (byte) 0x48,
            (byte) 0x63, (byte) 0xf6, (byte) 0x48, (byte) 0x63, (byte) 0xf8, (byte) 0xb8, (byte) 0xea,
            (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0f, (byte) 0x05, (byte) 0x48, (byte) 0x3d,
            (byte) 0x00, (byte) 0xf0, (byte) 0xff, (byte) 0xff, (byte) 0x77, (byte) 0x15, (byte) 0xf3,
            (byte) 0xc3, (byte) 0x90, (byte) 0x85, (byte) 0xc0, (byte) 0x7f, (byte) 0xe1, (byte) 0xa9,
            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x7f, (byte) 0x75, (byte) 0x17, (byte) 0x89,
            (byte) 0xf0, (byte) 0x0f, (byte) 0x1f, (byte) 0x00, (byte) 0xeb, (byte) 0xd3, (byte) 0x48,
            (byte) 0x8b, (byte) 0x15, (byte) 0x2f, (byte) 0xf7, (byte) 0x34, (byte) 0x00, (byte) 0xf7,
            (byte) 0xd8, (byte) 0x64, (byte) 0x89, (byte) 0x02, (byte) 0x83, (byte) 0xc8, (byte) 0xff,
            (byte) 0xc3, (byte) 0xf7, (byte) 0xd8, (byte) 0xeb, (byte) 0xbf, (byte) 0x90, (byte) 0x90,
            (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90,
            (byte) 0x90 };

    List<Byte> byteList = newArrayList(Bytes.asList(bytes));

    Entry.Mode mode = Entry.Mode.E;/*  w ww.  ja  v a 2  s  . c  o m*/

    while (!byteList.isEmpty()) {
        byte[] b = new byte[byteList.size()];
        for (int i = 0; i < byteList.size(); ++i) {
            b[i] = byteList.get(i);
        }
        System.out.println(Hex.hexdump(b));
        System.out.println();

        List<Entry> keyEntries = newArrayList(trie.get(byteList.iterator()));
        Entry entry = null;

        if (keyEntries.size() > 1) {
            List<Entry> modeEntries = keyEntries.stream().filter(e -> e.mode == mode).collect(toList());
            if (modeEntries.size() == 1) {
                entry = modeEntries.get(0);
            }
        } else {
            entry = keyEntries.get(0);
        }

        if (entry == null) {
            throw new IllegalStateException();
        }

        System.out.println(entry);
        System.out.println();

        int len = 1;
        int modRMCount = 0;
        List<Ref.Syntax> syntaxes = newArrayList(entry.getSyntaxes());
        Ref.Syntax syntax = syntaxes.get(syntaxes.size() - 1);
        System.out.println(syntax);
        Iterable<Ref.Operand> operands = Iterables.concat(syntax.getSrcOperands(), syntax.getDstOperands());
        for (Ref.Operand operand : operands) {
            switch (operand.address) {
            case V:
            case G:
            case E:
            case M:
                ++modRMCount;
                break;
            case J:
                len += 4;
                break;
            case Z:
            case SC:
                break;
            default:
                throw new IllegalStateException();
            }
        }
        len += modRMCount;

        for (int i = 0; i < len; ++i) {
            byteList.remove(0);
        }

        System.out.println("\n");
    }
}

From source file:io.mindmaps.graql.GraqlShell.java

private static String loadQuery(String filePath) throws IOException {
    List<String> lines = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8);
    return lines.stream().collect(Collectors.joining("\n"));
}

From source file:se.uu.it.cs.recsys.dataloader.correction.CourseSelectionRecourseCorrecter.java

public static void correctCourseName(File file, Map<String, String> wrongToCorrect) throws IOException {
    List<String> processedLines = new ArrayList<>();

    try (FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr)) {

        br.lines().forEach(line -> {//w  w w  . j a  v  a 2 s.  co m
            String lineCopy = replaceWrongCourseNameWithCorrect(line, wrongToCorrect);
            processedLines.add(lineCopy);
        });
    }

    try (PrintWriter pw = new PrintWriter(file)) {
        processedLines.stream().forEach(line -> pw.println(line));
    }
}

From source file:controller.FeatureController.java

public static double[] computeFeatures(float[] y, FilterCoefficients filterCoefficients) {
    double[] x = Util.floatToDouble(y);

    TDoubleArrayList features = new TDoubleArrayList();

    int wlen = 100, noutput = 100;

    float[][] stft = new float[noutput][wlen];

    filtfilt(x, filterCoefficients);//from ww  w. ja  va 2  s  .c  o m

    features.add(FastMath.sqrt(StatUtils.variance(x)));
    Skewness skew = new Skewness();
    features.add(skew.evaluate(x));
    Kurtosis kurt = new Kurtosis();
    features.add(kurt.evaluate(x));

    x = Math2.zscore(x);

    double[] d = Math2.diff(Math2.diff(x));
    features.add(Doubles.max(Math2.abs(d)));

    List<float[]> wdec = Entropies.wavedecomposition(Util.doubleToFloat(x));

    features.add(wdec.stream().mapToDouble(e -> FastMath.log(DoubleMath.mean(Math2.abs(Util.floatToDouble(e)))))
            .toArray());

    features.add(Entropies.wpentropy(Util.doubleToFloat(x), 6, 1));
    features.add(wdec.stream().mapToDouble(e -> Entropies.wpentropy(e, 6, 1)).toArray());

    features.add(Signal.lineSpectralPairs(x, 10));
    features.add(Arrays.copyOf(
            Util.floatToDouble(tools.Signal.logAbsStft(Util.doubleToFloat(x), wlen, noutput, stft)), 10));

    double[] x_pos = new double[x.length];
    double[] x_neg = new double[x.length];
    for (int i = 0; i < x.length; i++) {
        x_pos[i] = (x[i] >= 0) ? x[i] : 0;
        x_neg[i] = (x[i] <= 0) ? x[i] : 0;
    }

    features.add(Arrays.copyOf(
            Util.floatToDouble(tools.Signal.logAbsStft(Util.doubleToFloat(x_pos), wlen, noutput, stft)), 10));

    features.add(Arrays.copyOf(
            Util.floatToDouble(tools.Signal.logAbsStft(Util.doubleToFloat(x_neg), wlen, noutput, stft)), 10));
    return features.toArray();
}