src/jdk.internal.le/share/classes/jdk/internal/org/jline/reader/Candidate.java
author pliden
Fri, 13 Sep 2019 08:40:09 +0200
changeset 58125 9b4717ca9bd1
parent 52938 5ff7480c9e28
child 58903 eeb1c0da2126
permissions -rw-r--r--
8230878: ZGC: Use THREAD_LOCAL instead of __thread Reviewed-by: kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     1
/*
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2002-2018, the original author or authors.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     3
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     4
 * This software is distributable under the BSD license. See the terms of the
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     5
 * BSD license in the documentation provided with this software.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     6
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     7
 * http://www.opensource.org/licenses/bsd-license.php
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     8
 */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
     9
package jdk.internal.org.jline.reader;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    10
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    11
import java.util.Objects;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    12
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    13
/**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    14
 * A completion candidate.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    15
 *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    16
 * @author <a href="mailto:gnodet@gmail.com">Guillaume Nodet</a>
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    17
 */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    18
public class Candidate implements Comparable<Candidate> {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    19
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    20
    private final String value;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    21
    private final String displ;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    22
    private final String group;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    23
    private final String descr;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    24
    private final String suffix;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    25
    private final String key;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    26
    private final boolean complete;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    27
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    28
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    29
     * Simple constructor with only a single String as an argument.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    30
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    31
     * @param value the candidate
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    32
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    33
    public Candidate(String value) {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    34
        this(value, value, null, null, null, null, true);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    35
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    36
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    37
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    38
     * Constructs a new Candidate.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    39
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    40
     * @param value the value
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    41
     * @param displ the display string
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    42
     * @param group the group
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    43
     * @param descr the description
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    44
     * @param suffix the suffix
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    45
     * @param key the key
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    46
     * @param complete the complete flag
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    47
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    48
    public Candidate(String value, String displ, String group, String descr, String suffix, String key, boolean complete) {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    49
        Objects.requireNonNull(value);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    50
        this.value = value;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    51
        this.displ = displ;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    52
        this.group = group;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    53
        this.descr = descr;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    54
        this.suffix = suffix;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    55
        this.key = key;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    56
        this.complete = complete;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    57
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    58
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    59
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    60
     * The value that will be used for the actual completion.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    61
     * This string should not contain ANSI sequences.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    62
     * @return the value
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    63
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    64
    public String value() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    65
        return value;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    66
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    67
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    68
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    69
     * The string that will be displayed to the user.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    70
     * This string may contain ANSI sequences.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    71
     * @return the display string
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    72
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    73
    public String displ() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    74
        return displ;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    75
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    76
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    77
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    78
     * The group name for this candidate.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    79
     * Candidates can be grouped together and this string is used
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    80
     * as a key for the group and displayed to the user.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    81
     * @return the group
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    82
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    83
     * @see LineReader.Option#GROUP
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    84
     * @see LineReader.Option#AUTO_GROUP
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    85
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    86
    public String group() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    87
        return group;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    88
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    89
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    90
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    91
     * Description of this candidate, usually a small help message
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    92
     * to understand the meaning of this candidate.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    93
     * This string may contain ANSI sequences.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    94
     * @return the description
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    95
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    96
    public String descr() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    97
        return descr;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    98
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
    99
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   100
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   101
     * The suffix is added when this candidate is displayed.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   102
     * However, if the next character entered does not match,
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   103
     * the suffix will be automatically removed.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   104
     * This string should not contain ANSI sequences.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   105
     * @return the suffix
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   106
     *
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   107
     * @see LineReader.Option#AUTO_REMOVE_SLASH
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   108
     * @see LineReader#REMOVE_SUFFIX_CHARS
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   109
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   110
    public String suffix() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   111
        return suffix;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   112
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   113
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   114
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   115
     * Candidates which have the same key will be merged together.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   116
     * For example, if a command has multiple aliases, they can be merged
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   117
     * if they are using the same key.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   118
     * @return the key
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   119
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   120
    public String key() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   121
        return key;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   122
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   123
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   124
    /**
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   125
     * Boolean indicating whether this candidate is complete or
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   126
     * if the completer may further expand the candidate value
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   127
     * after this candidate has been selected.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   128
     * This can be the case when completing folders for example.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   129
     * If the candidate is complete and is selected, a space
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   130
     * separator will be added.
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   131
     * @return the completion flag
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   132
     */
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   133
    public boolean complete() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   134
        return complete;
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   135
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   136
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   137
    @Override
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   138
    public int compareTo(Candidate o) {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   139
        return value.compareTo(o.value);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   140
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents:
diff changeset
   141
}