Skip to content

Commit

Permalink
Add final to make fields immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Jun 12, 2018
1 parent 73c1315 commit a0fda89
Show file tree
Hide file tree
Showing 73 changed files with 174 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class AllWidgetsFormTest {
private static final String FORMS_DIRECTORY = "/odk/forms/";

private final Random random = new Random();
private ActivityResult okResult = new ActivityResult(RESULT_OK, new Intent());
private final ActivityResult okResult = new ActivityResult(RESULT_OK, new Intent());

@ClassRule
public static final LocaleTestRule localeTestRule = new LocaleTestRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private static Object[] ei(String formName, String... expectedIndices) {
return new Object[] {formName, expectedIndices};
}

private String formName;
private String[] expectedIndices;
private final String formName;
private final String[] expectedIndices;

public FormNavigationTestCase(String formName, String[] expectedIndices) {
this.formName = formName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CustomSQLiteQueryBuilderTestCase {
private static final String TEST_TABLE_NAME = "testTable";
private static final String TEST_TABLE_NAME_2 = "testTable2";

private String[] tableColumns = new String[] {"_id", "col1", "col2", "col3"};
private final String[] tableColumns = new String[] {"_id", "col1", "col2", "col3"};

private SQLiteDatabase sqLiteDatabase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onClick(View v) {
ToastUtils.showLongToast(R.string.take_picture_instruction);
}

private Camera.PictureCallback picture = new Camera.PictureCallback() {
private final Camera.PictureCallback picture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
CameraUtils.savePhoto(Collect.TMPFILE_PATH, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

public class FileManagerTabs extends CollectAbstractActivity {

private DataManagerList dataManagerList = DataManagerList.newInstance();
private FormManagerList formManagerList = FormManagerList.newInstance();
private final DataManagerList dataManagerList = DataManagerList.newInstance();
private final FormManagerList formManagerList = FormManagerList.newInstance();

private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class FormDownloadList extends FormListActivity implements FormListDownlo

private HashMap<String, FormDetails> formNamesAndURLs = new HashMap<String, FormDetails>();
private ArrayList<HashMap<String, String>> formList;
private ArrayList<HashMap<String, String>> filteredFormList = new ArrayList<>();
private final ArrayList<HashMap<String, String>> filteredFormList = new ArrayList<>();
private LinkedHashSet<String> selectedForms = new LinkedHashSet<>();

private static final boolean EXIT = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class GeoPointOsmMapActivity extends CollectAbstractActivity implements L
//private GoogleMap map;
private MapView map;

private Handler handler = new Handler();
private final Handler handler = new Handler();
private Marker marker;

private GeoPoint latLng;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class GeoShapeGoogleMapActivity extends CollectAbstractActivity implement
private LatLng curlatLng;
private PolygonOptions polygonOptions;
private Polygon polygon;
private ArrayList<Marker> markerArray = new ArrayList<Marker>();
private final ArrayList<Marker> markerArray = new ArrayList<Marker>();
private ImageButton gpsButton;
private ImageButton clearButton;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

public class GeoShapeOsmMapActivity extends CollectAbstractActivity implements IRegisterReceiver {
private MapView map;
private ArrayList<Marker> mapMarkers = new ArrayList<Marker>();
private final ArrayList<Marker> mapMarkers = new ArrayList<Marker>();
private Polyline polyline;
public int zoomLevel = 3;
public static final int stroke_width = 5;
Expand Down Expand Up @@ -252,9 +252,9 @@ private void overlayIntentPolygon(String str) {
}


private Handler handler = new Handler(Looper.getMainLooper());
private final Handler handler = new Handler(Looper.getMainLooper());

private Runnable centerAroundFix = new Runnable() {
private final Runnable centerAroundFix = new Runnable() {
public void run() {
handler.post(new Runnable() {
public void run() {
Expand Down Expand Up @@ -420,7 +420,7 @@ private void update_polygon() {
map.invalidate();
}

private MapEventsReceiver receive = new MapEventsReceiver() {
private final MapEventsReceiver receive = new MapEventsReceiver() {
@Override
public boolean longPressHelper(GeoPoint point) {
if (!clearButtonTest) {
Expand Down Expand Up @@ -451,7 +451,7 @@ public boolean singleTapConfirmedHelper(GeoPoint arg0) {
}
};

private MapListener mapViewListener = new MapListener() {
private final MapListener mapViewListener = new MapListener() {
@Override
public boolean onZoom(ZoomEvent zoomLev) {
zoomLevel = zoomLev.getZoomLevel();
Expand All @@ -465,7 +465,7 @@ public boolean onScroll(ScrollEvent arg0) {

};

private Marker.OnMarkerDragListener dragListener = new Marker.OnMarkerDragListener() {
private final Marker.OnMarkerDragListener dragListener = new Marker.OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {

Expand All @@ -485,7 +485,7 @@ public void onMarkerDrag(Marker marker) {
};


private Marker.OnMarkerClickListener nullMarkerListener = new Marker.OnMarkerClickListener() {
private final Marker.OnMarkerClickListener nullMarkerListener = new Marker.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker arg0, MapView arg1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
public class GeoTraceGoogleMapActivity extends CollectAbstractActivity implements LocationListener,
OnMarkerDragListener, OnMapLongClickListener, LocationClient.LocationClientListener {

private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture schedulerHandler;
private ImageButton playButton;
public ImageButton layersButton;
Expand All @@ -95,7 +95,7 @@ public class GeoTraceGoogleMapActivity extends CollectAbstractActivity implement
private LatLng curlatLng;
private PolylineOptions polylineOptions;
private Polyline polyline;
private ArrayList<Marker> markerArray = new ArrayList<Marker>();
private final ArrayList<Marker> markerArray = new ArrayList<Marker>();
private MapHelper helper;

private AlertDialog zoomDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
public class GeoTraceOsmMapActivity extends CollectAbstractActivity implements IRegisterReceiver,
LocationListener, LocationClient.LocationClientListener {

private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private ScheduledFuture schedulerHandler;
public int zoomLevel = 3;
public boolean gpsStatus = true;
Expand All @@ -83,7 +83,7 @@ public class GeoTraceOsmMapActivity extends CollectAbstractActivity implements I
private View traceSettingsView;
private View polygonPolylineView;
private Polyline polyline;
private ArrayList<Marker> mapMarkers = new ArrayList<Marker>();
private final ArrayList<Marker> mapMarkers = new ArrayList<Marker>();
private Integer traceMode; // 0 manual, 1 is automatic
private Spinner timeUnits;
private Spinner timeDelay;
Expand Down Expand Up @@ -449,9 +449,9 @@ private void overlayMyLocationLayers() {

}

private Handler handler = new Handler(Looper.getMainLooper());
private final Handler handler = new Handler(Looper.getMainLooper());

private Runnable centerAroundFix = new Runnable() {
private final Runnable centerAroundFix = new Runnable() {
public void run() {
handler.post(new Runnable() {
public void run() {
Expand Down Expand Up @@ -685,7 +685,7 @@ private void returnLocation() {
setResult(RESULT_OK, i);
}

private Marker.OnMarkerClickListener nullMarkerListener = new Marker.OnMarkerClickListener() {
private final Marker.OnMarkerClickListener nullMarkerListener = new Marker.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker arg0, MapView arg1) {
Expand All @@ -711,7 +711,7 @@ private void update_polygon() {
}


private Marker.OnMarkerDragListener dragListener = new Marker.OnMarkerDragListener() {
private final Marker.OnMarkerDragListener dragListener = new Marker.OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class GoogleDriveActivity extends FormListActivity implements View.OnClic
private Button backButton;
private Button downloadButton;
private Stack<String> currentPath = new Stack<>();
private Stack<String> folderIdStack = new Stack<>();
private final Stack<String> folderIdStack = new Stack<>();
private String alertMsg;
private boolean alertShowing;
private String rootId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public class MainMenuActivity extends CollectAbstractActivity {
private Cursor finalizedCursor;
private Cursor savedCursor;
private Cursor viewSentCursor;
private IncomingHandler handler = new IncomingHandler(this);
private MyContentObserver contentObserver = new MyContentObserver();
private final IncomingHandler handler = new IncomingHandler(this);
private final MyContentObserver contentObserver = new MyContentObserver();

// private static boolean DO_NOT_EXIT = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -35,11 +36,9 @@
import java.util.List;
import java.util.Locale;

import android.support.annotation.NonNull;

public class FileArrayAdapter extends ArrayAdapter<DriveListItem> {

private List<DriveListItem> items;
private final List<DriveListItem> items;

public FileArrayAdapter(Context context, List<DriveListItem> filteredDriveList) {
super(context, R.layout.two_item_image, filteredDriveList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

public class FormDownloadListAdapter extends ArrayAdapter {

private ArrayList<HashMap<String, String>> filteredFormList;
private HashMap<String, FormDetails> formIdsToDetails;
private final ArrayList<HashMap<String, String>> filteredFormList;
private final HashMap<String, FormDetails> formIdsToDetails;

public FormDownloadListAdapter(Context context, ArrayList<HashMap<String, String>> filteredFormList,
HashMap<String, FormDetails> formIdsToDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SortDialogAdapter extends RecyclerView.Adapter<SortDialogAdapter.Vi
private final int selectedSortingOrder;
private final RecyclerView recyclerView;
private final ThemeUtils themeUtils;
private String[] sortList;
private final String[] sortList;

public SortDialogAdapter(Context context, RecyclerView recyclerView, String[] sortList, int selectedSortingOrder, RecyclerViewClickListener recyclerViewClickListener) {
themeUtils = new ThemeUtils(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Locale;

public class ViewSentListAdapter extends SimpleCursorAdapter {
private Context context;
private final Context context;

public ViewSentListAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// We buffer scroll actions to make sure there aren't too many pauses
// during scrolling. This list is flushed every time any other type of
// action is logged.
private LinkedList<ContentValues> scrollActions = new LinkedList<ContentValues>();
private final LinkedList<ContentValues> scrollActions = new LinkedList<ContentValues>();

public ActivityLogger(String deviceId) {
this.deviceId = deviceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class DatabaseContext extends ContextWrapper {

private String path;
private final String path;

public DatabaseContext(String path) {
super(Collect.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class InstancesDatabaseHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 4;

private String[] instancesTableColumnsInVersion4 = new String[] {_ID, DISPLAY_NAME, SUBMISSION_URI, CAN_EDIT_WHEN_COMPLETE,
private final String[] instancesTableColumnsInVersion4 = new String[] {_ID, DISPLAY_NAME, SUBMISSION_URI, CAN_EDIT_WHEN_COMPLETE,
INSTANCE_FILE_PATH, JR_FORM_ID, JR_VERSION, STATUS, LAST_STATUS_CHANGE_DATE, DISPLAY_SUBTEXT, DELETED_DATE};

public InstancesDatabaseHelper() {
Expand Down
34 changes: 17 additions & 17 deletions collect_app/src/main/java/org/odk/collect/android/dto/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
* Objects of this class are created using builder pattern: https://en.wikipedia.org/wiki/Builder_pattern
*/
public class Form {
private int id;
private String displayName;
private String description;
private String jrFormId;
private String jrVersion;
private String formFilePath;
private String submissionUri;
private String base64RSAPublicKey;
private String displaySubtext;
private String md5Hash;
private Long date;
private String jrCacheFilePath;
private String formMediaPath;
private String language;
private String autoSend;
private String autoDelete;
private String lastDetectedFormVersionHash;
private final int id;
private final String displayName;
private final String description;
private final String jrFormId;
private final String jrVersion;
private final String formFilePath;
private final String submissionUri;
private final String base64RSAPublicKey;
private final String displaySubtext;
private final String md5Hash;
private final Long date;
private final String jrCacheFilePath;
private final String formMediaPath;
private final String language;
private final String autoSend;
private final String autoDelete;
private final String lastDetectedFormVersionHash;

private Form(Form.Builder builder) {
id = builder.id;
Expand Down
20 changes: 10 additions & 10 deletions collect_app/src/main/java/org/odk/collect/android/dto/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
*/
public class Instance {

private String displayName;
private String submissionUri;
private String canEditWhenComplete;
private String instanceFilePath;
private String jrFormId;
private String jrVersion;
private String status;
private Long lastStatusChangeDate;
private String displaySubtext;
private Long deletedDate;
private final String displayName;
private final String submissionUri;
private final String canEditWhenComplete;
private final String instanceFilePath;
private final String jrFormId;
private final String jrVersion;
private final String status;
private final Long lastStatusChangeDate;
private final String displaySubtext;
private final Long deletedDate;

private Instance(Builder builder) {
displayName = builder.displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
*/
public class ExternalDataManagerImpl implements ExternalDataManager {

private Map<String, ExternalSQLiteOpenHelper> dbMap =
new HashMap<String, ExternalSQLiteOpenHelper>();
private final Map<String, ExternalSQLiteOpenHelper> dbMap = new HashMap<String, ExternalSQLiteOpenHelper>();

private final File mediaFolder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public class ExternalDataReaderImpl implements ExternalDataReader {

private FormLoaderTask formLoaderTask;
private final FormLoaderTask formLoaderTask;

public ExternalDataReaderImpl(FormLoaderTask formLoaderTask) {
this.formLoaderTask = formLoaderTask;
Expand Down
Loading

0 comments on commit a0fda89

Please sign in to comment.