mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-10 01:45:50 +01:00
dd9864015d
This commit fixes the following compilation error: ``` :app:compileDebugJavaWithJavac /home/bob/dev/Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/LimitedQueue.java:26: error: incomparable types: Object and int if (pair.first == id) { ^ Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error :app:compileDebugJavaWithJavac FAILED FAILURE: Build failed with an exception. ```
41 lines
947 B
Java
41 lines
947 B
Java
package nodomain.freeyourgadget.gadgetbridge.util;
|
|
|
|
import android.util.Pair;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
|
|
public class LimitedQueue {
|
|
private final int limit;
|
|
private LinkedList<Pair> list = new LinkedList<>();
|
|
|
|
public LimitedQueue(int limit) {
|
|
this.limit = limit;
|
|
}
|
|
|
|
public void add(int id, Object obj) {
|
|
if (list.size() > limit - 1) {
|
|
list.removeFirst();
|
|
}
|
|
list.add(new Pair<>(id, obj));
|
|
}
|
|
|
|
public void remove(int id) {
|
|
for (Iterator<Pair> iter = list.iterator(); iter.hasNext(); ) {
|
|
Pair pair = iter.next();
|
|
if ((Integer) pair.first == id) {
|
|
iter.remove();
|
|
}
|
|
}
|
|
}
|
|
|
|
public Object lookup(int id) {
|
|
for (Pair entry : list) {
|
|
if (id == (Integer) entry.first) {
|
|
return entry.second;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|