altos: Fix GPS test frameworks to handle shared ao_gps_new variable
[fw/altos] / altosui / AltosBTDeviceIterator.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19 import java.util.*;
20 import libaltosJNI.*;
21
22 public class AltosBTDeviceIterator implements Iterator<AltosBTDevice> {
23         AltosBTDevice   current;
24         boolean         done;
25         SWIGTYPE_p_altos_bt_list list;
26
27         public boolean hasNext() {
28                 if (list == null)
29                         return false;
30                 if (current != null)
31                         return true;
32                 if (done)
33                         return false;
34                 current = new AltosBTDevice();
35                 while (libaltos.altos_bt_list_next(list, current) != 0) {
36 //                      if (current.matchProduct(product))
37                                 return true;
38                 }
39                 current = null;
40                 done = true;
41                 return false;
42         }
43
44         public AltosBTDevice next() {
45                 if (hasNext()) {
46                         AltosBTDevice   next = current;
47                         current = null;
48                         return next;
49                 }
50                 return null;
51         }
52
53         public void remove() {
54                 throw new UnsupportedOperationException();
55         }
56
57         public AltosBTDeviceIterator(int inquiry_time) {
58                 done = false;
59                 current = null;
60                 list = libaltos.altos_bt_list_start(inquiry_time);
61         }
62 }