Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added addEarly() method to TranslatorRegistry.
  • Loading branch information
stickfigure committed Dec 28, 2013
commit bbd55536e8738371160dc9507c62f63dfe0c80a5
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class TranslatorRegistry

/** Where we should insert new translators */
int insertPoint;

/** Where we should insert new early translators */
int earlyInsertPoint;

/**
* Initialize the default set of converters in the proper order.
Expand All @@ -41,6 +44,10 @@ public TranslatorRegistry(ObjectifyFactory fact)

// The order is CRITICAL!
this.translators.add(new TranslateTranslatorFactory(true)); // Early translators get first shot at everything

// Magic inflection point at which we want to prioritize added EARLY translators
this.earlyInsertPoint = this.translators.size();

this.translators.add(new SerializeTranslatorFactory()); // Serialize has priority over everything
this.translators.add(new ByteArrayTranslatorFactory());
this.translators.add(new ArrayTranslatorFactory()); // AFTER byte array otherwise we will occlude it
Expand Down Expand Up @@ -77,6 +84,16 @@ public void add(TranslatorFactory<?> trans) {
this.translators.add(insertPoint, trans);
insertPoint++;
}

/**
* <p>Add a new translator to the beginning of the list, before all other translators
* except other translators that have been added early.</p>
*/
public void addEarly(TranslatorFactory<?> trans) {
this.translators.add(earlyInsertPoint, trans);
earlyInsertPoint++;
insertPoint++;
}

/**
* Goes through our list of known translators and returns the first one that succeeds
Expand Down