mirror of
https://github.com/php/php-src.git
synced 2025-08-21 01:45:16 +02:00
update java example
This commit is contained in:
parent
8a63a99d2e
commit
734fe5508a
6 changed files with 427 additions and 124 deletions
47
tutorials/java/src/History.java
Normal file
47
tutorials/java/src/History.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement a simple history list for command input
|
||||
* @author krakjoe
|
||||
*/
|
||||
public class History extends ArrayList<String> {
|
||||
private Integer position = new Integer(0);
|
||||
|
||||
public History() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override public boolean add(String text) {
|
||||
String last = last();
|
||||
if (text != null) {
|
||||
if (last == null || !last.equals(text)) {
|
||||
if (super.add(text)) {
|
||||
position = size();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String last() {
|
||||
if (position >= 1) {
|
||||
position--;
|
||||
return get(position);
|
||||
} else return new String();
|
||||
}
|
||||
|
||||
public String next() {
|
||||
if (position+1 < size()) {
|
||||
position++;
|
||||
return get(position);
|
||||
} else return new String();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue