Skip to content

Instantly share code, notes, and snippets.

@datienza
Forked from Aracem/BeanListOptionsTemplate.java
Last active August 29, 2015 14:06
Show Gist options
  • Save datienza/cf2b7bb07e84a0ebfa05 to your computer and use it in GitHub Desktop.
Save datienza/cf2b7bb07e84a0ebfa05 to your computer and use it in GitHub Desktop.

Revisions

  1. @Aracem Aracem revised this gist Jul 29, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions BeanListOptionsTemplate.java
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,9 @@
    * Variables:
    * $TYPE$ expresion: arrayValue() defaultValue: listField
    * $OBJECT$ expresion:className() defaultValue: Object
    *
    * Follow this instruction to add it to Android Studio
    * http://dmytrodanylyk.com/pages/blog/templates.html
    */

    /**
  2. @Aracem Aracem revised this gist Jul 29, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions BeanListOptionsTemplate.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    /*
    * Declaration: Java - Declaration
    * Variables:
    * $TYPE$ expresion: arrayValue() defaultValue: listField
    * $OBJECT$ expresion:className() defaultValue: Object
    */

    /**
    * Returns the size of the list or 0 if null or empty
    */
  3. @Aracem Aracem created this gist Jul 29, 2014.
    29 changes: 29 additions & 0 deletions BeanListOptionsTemplate.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /**
    * Returns the size of the list or 0 if null or empty
    */
    public int size() {
    return $TYPE$ == null ? 0 : $TYPE$.size();
    }

    /**
    * @return true when the list is empty
    */
    public boolean isEmpty() {
    return size() == 0;
    }

    /**
    * Adds a $OBJECT$ to the list
    */
    public void add$OBJECT$($OBJECT$ object){
    if($TYPE$ != null){
    $TYPE$.add(object);
    }
    }

    /**
    * Gets a $OBJECT$ from list
    */
    public $OBJECT$ get$OBJECT$(int position){
    return $TYPE$.size() > position ? $TYPE$.get(position) : null;
    }