Back to project page Save-the-Planet.
The source code is released under:
Copyright (c) 2002 JSON.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software ...
If you think the Android project Save-the-Planet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.karolmajta.stp.models; /*from w w w. j a v a 2 s .c om*/ import java.util.ArrayList; import com.karolmajta.stp.exception.NoTasksInProgressQueueException; public class SyncProgress implements IProgress { private class TaskWeightPair { public ITask task; public int weight; public TaskWeightPair(ITask task, int weight) { this.task = task; this.weight = weight; } } private ArrayList<TaskWeightPair> tasks; private int addPointer; private int processPointer; private int weightsTotal; private int weightsProcessed; public SyncProgress() { tasks = new ArrayList<TaskWeightPair>(); addPointer = 0; processPointer = 0; weightsTotal = 0; weightsProcessed = 0; } @Override public int addTask(ITask task, int weight) { tasks.add(addPointer, new TaskWeightPair(task, weight)); addPointer++; weightsTotal+=weight; return addPointer-1; } @Override public int getTotal() { return weightsTotal; } @Override public int getProcessed() { return weightsProcessed; } @Override public void markAsProcessed(int id) { weightsProcessed += tasks.get(id).weight; } @Override public boolean hasNextTask() { return processPointer <= tasks.size()-1 ? true : false; } @Override public boolean doNext() throws NoTasksInProgressQueueException { if(!hasNextTask()){ throw new NoTasksInProgressQueueException(); } ITask t = tasks.get(processPointer).task; t.launch(); markAsProcessed(processPointer); processPointer++; return hasNextTask(); } }