jdk/src/share/classes/javax/swing/SpinnerListModel.java
author darcy
Thu, 03 Jul 2014 15:24:27 -0700
changeset 25568 b906a74c6882
parent 23697 e556a715949f
permissions -rw-r--r--
8043550: Fix raw and unchecked lint warnings in javax.swing.* Reviewed-by: pchelko, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A simple implementation of <code>SpinnerModel</code> whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * values are defined by an array or a <code>List</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * For example to create a model defined by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * an array of the names of the days of the week:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * String[] days = new DateFormatSymbols().getWeekdays();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * SpinnerModel model = new SpinnerListModel(Arrays.asList(days).subList(1, 8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class only stores a reference to the array or <code>List</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * so if an element of the underlying sequence changes, it's up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * to the application to notify the <code>ChangeListeners</code> by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>fireStateChanged</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This model inherits a <code>ChangeListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The <code>ChangeListener</code>s are notified whenever the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * model's <code>value</code> or <code>list</code> properties changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see JSpinner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see SpinnerModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see AbstractSpinnerModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see SpinnerNumberModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see SpinnerDateModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    59
@SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
25568
b906a74c6882 8043550: Fix raw and unchecked lint warnings in javax.swing.*
darcy
parents: 23697
diff changeset
    62
    private List<?> list;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Constructs a <code>SpinnerModel</code> whose sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * values is defined by the specified <code>List</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * The initial value (<i>current element</i>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * of the model will be <code>values.get(0)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * If <code>values</code> is <code>null</code> or has zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * size, an <code>IllegalArugmentException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param values the sequence this model represents
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    75
     * @throws IllegalArgumentException if <code>values</code> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *    <code>null</code> or zero size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public SpinnerListModel(List<?> values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (values == null || values.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new IllegalArgumentException("SpinnerListModel(List) expects non-null non-empty List");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this.list = values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Constructs a <code>SpinnerModel</code> whose sequence of values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * is defined by the specified array.  The initial value of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * will be <code>values[0]</code>.  If <code>values</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <code>null</code> or has zero length, an
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    92
     * <code>IllegalArgumentException</code> is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param values the sequence this model represents
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 5506
diff changeset
    95
     * @throws IllegalArgumentException if <code>values</code> is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *    <code>null</code> or zero length
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public SpinnerListModel(Object[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (values == null || values.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new IllegalArgumentException("SpinnerListModel(Object[]) expects non-null non-empty Object[]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.list = Arrays.asList(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs an effectively empty <code>SpinnerListModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * The model's list will contain a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>"empty"</code> string element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public SpinnerListModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this(new Object[]{"empty"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the <code>List</code> that defines the sequence for this model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return the value of the <code>list</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see #setList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public List<?> getList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Changes the list that defines this sequence and resets the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * of the models <code>value</code> to zero.  Note that <code>list</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * is not copied, the model just stores a reference to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * This method fires a <code>ChangeEvent</code> if <code>list</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * not equal to the current list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @param list the sequence that this model represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @throws IllegalArgumentException if <code>list</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *    <code>null</code> or zero length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see #getList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public void setList(List<?> list) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if ((list == null) || (list.size() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new IllegalArgumentException("invalid list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (!list.equals(this.list)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            this.list = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns the current element of the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return the <code>value</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see SpinnerModel#getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return list.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Changes the current element of the sequence and notifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <code>ChangeListeners</code>.  If the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * value is not equal to an element of the underlying sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * then an <code>IllegalArgumentException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * In the following example the <code>setValue</code> call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * would cause an exception to be thrown:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * String[] values = {"one", "two", "free", "four"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * SpinnerModel model = new SpinnerListModel(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * model.setValue("TWO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param elt the sequence element that will be model's current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @throws IllegalArgumentException if the specified value isn't allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see SpinnerModel#setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void setValue(Object elt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int index = list.indexOf(elt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw new IllegalArgumentException("invalid sequence element");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        else if (index != this.index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            fireStateChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Returns the next legal value of the underlying sequence or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <code>null</code> if value is already the last element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the next legal value of the underlying sequence or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *     <code>null</code> if value is already the last element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see SpinnerModel#getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @see #getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Object getNextValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return (index >= (list.size() - 1)) ? null : list.get(index + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Returns the previous element of the underlying sequence or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>null</code> if value is already the first element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return the previous element of the underlying sequence or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *     <code>null</code> if value is already the first element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see SpinnerModel#getPreviousValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see #getNextValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public Object getPreviousValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return (index <= 0) ? null : list.get(index - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Returns the next object that starts with <code>substring</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param substring the string to be matched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    Object findNextMatch(String substring) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        int max = list.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (max == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        int counter = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            Object value = list.get(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            String string = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            if (string != null && string.startsWith(substring)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            counter = (counter + 1) % max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } while (counter != index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}