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

net.lenni0451.commandlib.Completion Maven / Gradle / Ivy

The newest version!
package net.lenni0451.commandlib;

import java.util.Objects;

/**
 * A completion for the user input suggesting what the user might want to type.
 */
public class Completion {

    private final int start;
    private final String completion;

    public Completion(final int start, final String completion) {
        this.start = start;
        this.completion = completion;
    }

    /**
     * The start of a completion is the index in the input where the completion starts.
* To fill the completion into the input you could do something like this: *

* // The input the user types
* String input = "test inp";
* // Get the completion from somewhere
* Completion completion = new Completion(5, "input");
* input = input.substring(0, completion.getStart()) + completion.getCompletion(); *


* In this example the input would be "test input" after the completion was applied. * * @return The start of the completion */ public int getStart() { return this.start; } /** * @return The completion itself */ public String getCompletion() { return this.completion; } @Override public String toString() { return "Completion{" + "start=" + start + ", completion='" + completion + '\'' + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Completion that = (Completion) o; return start == that.start && Objects.equals(completion, that.completion); } @Override public int hashCode() { return Objects.hash(start, completion); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy