You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
20 years ago
|
// disorderSet.java
|
||
|
// -----------------------
|
||
17 years ago
|
// (C) by Michael Peter Christen; mc@yacy.net
|
||
20 years ago
|
// first published on http://www.anomic.de
|
||
|
// Frankfurt, Germany, 2004
|
||
14 years ago
|
//
|
||
|
// $LastChangedDate$
|
||
|
// $LastChangedRevision$
|
||
|
// $LastChangedBy$
|
||
20 years ago
|
//
|
||
|
// This program is free software; you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation; either version 2 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
|
||
12 years ago
|
package net.yacy.utils;
|
||
20 years ago
|
|
||
14 years ago
|
import java.util.Arrays;
|
||
20 years ago
|
import java.util.HashSet;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.Set;
|
||
20 years ago
|
|
||
17 years ago
|
public class disorderSet extends HashSet<String> implements Set<String> {
|
||
20 years ago
|
|
||
19 years ago
|
private static final long serialVersionUID = 1L;
|
||
15 years ago
|
private disorderHeap dh;
|
||
20 years ago
|
|
||
|
public disorderSet() {
|
||
17 years ago
|
super();
|
||
|
dh = null;
|
||
20 years ago
|
}
|
||
|
|
||
|
public boolean hasAny() {
|
||
15 years ago
|
return !this.isEmpty();
|
||
20 years ago
|
}
|
||
|
|
||
17 years ago
|
public String any() {
|
||
17 years ago
|
// return just any element
|
||
15 years ago
|
if (dh == null || dh.isEmpty()) {
|
||
|
if (this.isEmpty()) return null;
|
||
17 years ago
|
// fill up the queue
|
||
|
dh = new disorderHeap();
|
||
17 years ago
|
final Iterator<String> elements = this.iterator();
|
||
17 years ago
|
while (elements.hasNext()) dh.add(elements.next());
|
||
|
}
|
||
|
return dh.remove();
|
||
20 years ago
|
}
|
||
|
|
||
17 years ago
|
public static void main(final String[] args) {
|
||
|
final disorderSet ds = new disorderSet();
|
||
14 years ago
|
ds.addAll(Arrays.asList(args));
|
||
17 years ago
|
for (int i = 0; i < args.length * 3; i++) System.out.print(ds.any() + " ");
|
||
17 years ago
|
System.out.println();
|
||
20 years ago
|
}
|
||
|
|
||
|
}
|