All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.pires.obd.commands.ObdMultiCommand Maven / Gradle / Ivy

There is a newer version: 1.0
Show newest version
package com.github.pires.obd.commands;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;

/**
 * Container for multiple {@link com.github.pires.obd.commands.ObdMultiCommand} instances.
 *
 * @author pires
 * @version $Id: $Id
 */
public class ObdMultiCommand {

    private ArrayList commands;

    /**
     * Default ctor.
     */
    public ObdMultiCommand() {
        this.commands = new ArrayList();
    }

    /**
     * Add ObdCommand to list of ObdCommands.
     *
     * @param command a {@link com.github.pires.obd.commands.ObdCommand} object.
     */
    public void add(ObdCommand command) {
        this.commands.add(command);
    }

    /**
     * Removes ObdCommand from the list of ObdCommands.
     *
     * @param command a {@link com.github.pires.obd.commands.ObdCommand} object.
     */
    public void remove(ObdCommand command) {
        this.commands.remove(command);
    }

    /**
     * Iterate all commands, send them and read response.
     *
     * @param in  a {@link java.io.InputStream} object.
     * @param out a {@link java.io.OutputStream} object.
     * @throws java.io.IOException            if any.
     * @throws java.lang.InterruptedException if any.
     */
    public void sendCommands(InputStream in, OutputStream out)
            throws IOException, InterruptedException {
        for (ObdCommand command : commands)
            command.run(in, out);
    }

    /**
     * 

getFormattedResult.

* * @return a {@link java.lang.String} object. */ public String getFormattedResult() { StringBuilder res = new StringBuilder(); for (ObdCommand command : commands) res.append(command.getFormattedResult()).append(","); return res.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy