
com.path.android.jobqueue.CopyOnWriteGroupSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android-priority-jobqueue Show documentation
Show all versions of android-priority-jobqueue Show documentation
a Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.
package com.path.android.jobqueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.TreeSet;
/**
* a util class that holds running jobs sorted by name and uniq.
* it behaves like CopyOnWriteLists
*/
public class CopyOnWriteGroupSet {
private ArrayList publicClone;
private final TreeSet internalSet;
public CopyOnWriteGroupSet() {
internalSet = new TreeSet();
}
public synchronized Collection getSafe() {
if(publicClone == null) {
publicClone = new ArrayList(internalSet);
}
return publicClone;
}
public synchronized void add(String group) {
if(internalSet.add(group)) {
publicClone = null;//invalidate
}
}
public synchronized void remove(String group) {
if(internalSet.remove(group)) {
publicClone = null;
}
}
public synchronized void clear() {
internalSet.clear();
publicClone = null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy