I'm creating a content provider for an Android app in Java and have a String array of constants and separate names for the index of each string in this array, as follows:
private static final String[] FILM_PROJECTION = {
FilmContract.FilmEntry.COLUMN_FILM_ID,
FilmContract.FilmEntry.COLUMN_TITLE,
FilmContract.FilmEntry.COLUMN_POSTER_URL,
FilmContract.FilmEntry.COLUMN_OVERVIEW,
FilmContract.FilmEntry.COLUMN_RATING,
FilmContract.FilmEntry.COLUMN_DATE,
FilmContract.FilmEntry.COLUMN_POPULARITY,
FilmContract.FilmEntry.COLUMN_VIDEOS,
FilmContract.FilmEntry.COLUMN_REVIEWS
};
private static final int COLUMN_FILM_ID_INDEX = 0;
private static final int COLUMN_TITLE_INDEX = 1;
private static final int COLUMN_POSTER_URL_INDEX = 2;
private static final int COLUMN_OVERVIEW_INDEX = 3;
private static final int COLUMN_RATING_INDEX = 4;
private static final int COLUMN_DATE_INDEX = 5;
private static final int COLUMN_POPULARITY_INDEX = 6;
private static final int COLUMN_VIDEOS_INDEX = 7;
private static final int COLUMN_REVIEWS_INDEX = 8;
I'm thinking there's surely a better way to do this, and I tried it with enum
e.g:
private enum FILM_PROJECTION_INDICES {
FILM_PROJECTION
}
But Java doesn't unpack the String array so that doesn't work (despite all the values being constant). What I'm asking for is something like this:
index = FILM_PROJECTION.getIndexOf(FilmContract.FilmEntry.COLUMN_TITLE);
Is there any way to do this?