Skip to content

Commit

Permalink
added null checks for views
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacek Kwiecień committed Jun 16, 2016
1 parent 02eb88e commit 2fe0ec5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Iterator;
import java.util.List;

import static pl.aprilapps.switcher.guava.Preconditions.checkNotNull;

/**
* Created by Jacek Kwiecień on 14.03.15.
*/
Expand Down Expand Up @@ -69,31 +71,37 @@ public Builder(Context context) {
}

public Builder addContentView(View contentView) {
checkNotNull(contentView, "Provided content view is null");
switcher.addContentView(contentView);
return this;
}

public Builder addErrorView(View errorView) {
checkNotNull(errorView, "Provided error view is null");
switcher.addErrorView(errorView);
return this;
}

public Builder addEmptyView(View emptyView) {
checkNotNull(emptyView, "Provided empty view is null");
switcher.addEmptyView(emptyView);
return this;
}

public Builder addProgressView(View progressView) {
checkNotNull(progressView, "Provided progress view is null");
switcher.addProgressView(progressView);
return this;
}

public Builder setProgressLabel(TextView progressLabel) {
checkNotNull(progressLabel, "Provided progress label is null");
switcher.setProgressLabel(progressLabel);
return this;
}

public Builder setErrorLabel(TextView errorLabel) {
checkNotNull(errorLabel, "Provided error label is null");
switcher.setErrorLabel(errorLabel);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pl.aprilapps.switcher.guava;

/**
* Created by Jacek Kwiecień on 08.06.16.
*/
public final class Preconditions {

private Preconditions() {
}


/**
* Ensures that an object reference passed as a parameter to the calling method is not null.
*
* @param reference an object reference
* @return the non-null reference that was validated
* @throws NullPointerException if {@code reference} is null
*/
public static <T> T checkNotNull(T reference, Object errorMessage) {
if (reference == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
return reference;
}

}

0 comments on commit 2fe0ec5

Please sign in to comment.