Move chunk trigger constants into Chunk.

This commit is contained in:
Oliver Woodman 2015-04-11 02:09:40 +01:00
parent a17ffa66f2
commit 265adf9a8f
2 changed files with 24 additions and 20 deletions

View file

@ -34,6 +34,27 @@ import java.io.IOException;
*/ */
public abstract class Chunk implements Loadable { public abstract class Chunk implements Loadable {
/**
* Value of {@link #trigger} for a load whose reason is unspecified.
*/
public static final int TRIGGER_UNSPECIFIED = 0;
/**
* Value of {@link #trigger} for a load triggered by an initial format selection.
*/
public static final int TRIGGER_INITIAL = 1;
/**
* Value of {@link #trigger} for a load triggered by a user initiated format selection.
*/
public static final int TRIGGER_MANUAL = 2;
/**
* Value of {@link #trigger} for a load triggered by an adaptive format selection.
*/
public static final int TRIGGER_ADAPTIVE = 3;
/**
* Implementations may define custom {@link #trigger} codes greater than or equal to this value.
*/
public static final int TRIGGER_CUSTOM_BASE = 10000;
/** /**
* The format associated with the data being loaded. * The format associated with the data being loaded.
*/ */

View file

@ -25,23 +25,6 @@ import java.util.Random;
*/ */
public interface FormatEvaluator { public interface FormatEvaluator {
/**
* The trigger for the initial format selection.
*/
static final int TRIGGER_INITIAL = 0;
/**
* The trigger for a format selection that was triggered by the user.
*/
static final int TRIGGER_MANUAL = 1;
/**
* The trigger for an adaptive format selection.
*/
static final int TRIGGER_ADAPTIVE = 2;
/**
* Implementations may define custom trigger codes greater than or equal to this value.
*/
static final int TRIGGER_CUSTOM_BASE = 10000;
/** /**
* Enables the evaluator. * Enables the evaluator.
*/ */
@ -93,7 +76,7 @@ public interface FormatEvaluator {
public Format format; public Format format;
public Evaluation() { public Evaluation() {
trigger = TRIGGER_INITIAL; trigger = Chunk.TRIGGER_INITIAL;
} }
} }
@ -147,7 +130,7 @@ public interface FormatEvaluator {
Format[] formats, Evaluation evaluation) { Format[] formats, Evaluation evaluation) {
Format newFormat = formats[random.nextInt(formats.length)]; Format newFormat = formats[random.nextInt(formats.length)];
if (evaluation.format != null && !evaluation.format.id.equals(newFormat.id)) { if (evaluation.format != null && !evaluation.format.id.equals(newFormat.id)) {
evaluation.trigger = TRIGGER_ADAPTIVE; evaluation.trigger = Chunk.TRIGGER_ADAPTIVE;
} }
evaluation.format = newFormat; evaluation.format = newFormat;
} }
@ -268,7 +251,7 @@ public interface FormatEvaluator {
ideal = current; ideal = current;
} }
if (current != null && ideal != current) { if (current != null && ideal != current) {
evaluation.trigger = FormatEvaluator.TRIGGER_ADAPTIVE; evaluation.trigger = Chunk.TRIGGER_ADAPTIVE;
} }
evaluation.format = ideal; evaluation.format = ideal;
} }