package com.philliphsu.bottomsheetpickers.view.numberpad;

import java.util.Arrays;

/**
 * Model that encapsulates data pertaining to the inputted time
 * in a number pad time picker.
 */
final class DigitwiseTimeModel {
    private final int[] digits = new int[4];

    private int count;

    DigitwiseTimeModel() {
        Arrays.fill(digits, -1);
    }

    void storeDigit(int digit) {
        digits[count] = digit;
        count++;
    }

    int getDigit(int at) {
        return digits[at];
    }

    void removeDigit() {
        if (count > 0) {
            count--; // move the cursor back
            digits[count] = -1;
        }
    }

    int count() {
        return count;
    }
}

@@ -227,16 +227,23 @@
 private 
+static 
 final in
@@ -247,17 +247,102 @@
  int
-%5B%5D digits
+ MAX_DIGITS = 4;%0A    private static final int UNMODIFIED = -1;%0A%0A    private final int%5B%5D mInput
  = n
@@ -348,17 +348,26 @@
 new int%5B
-4
+MAX_DIGITS
 %5D;%0A%0A    
@@ -374,25 +374,26 @@
 private int 
-c
+mC
 ount;%0A%0A    D
@@ -426,30 +426,74 @@
     
-Arrays.fill(d
+// Set contents of input array to UNMODIFIED.%0A        clearD
 igits
-, -1
+(
 );%0A 
@@ -535,32 +535,33 @@
 ) %7B%0A        
-digits%5Bc
+mInput%5BmC
 ount%5D = digi
@@ -567,25 +567,26 @@
 it;%0A        
-c
+mC
 ount++;%0A    
@@ -634,18 +634,271 @@
 urn 
+mInput%5Bat%5D;%0A    %7D%0A%0A    /**%0A     * @return a defensive copy of the internal array of inputted digits%0A     */%0A    int%5B%5D getDigits() %7B%0A        int%5B%5D digits = new int%5BmInput.length%5D;%0A        System.arraycopy(mInput, 0, digits, 0, mInput.length);%0A        return 
 digits
-%5Bat%5D
 ;%0A  
@@ -939,17 +939,18 @@
     if (
-c
+mC
 ount %3E 0
@@ -965,17 +965,18 @@
         
-c
+mC
 ount--; 
@@ -1015,84 +1015,873 @@
     
-digits%5Bcount%5D = -1;%0A        %7D%0A    %7D%0A%0A    int count() %7B%0A        return count;
+mInput%5BmCount%5D = UNMODIFIED;%0A        %7D%0A    %7D%0A%0A    void clearDigits() %7B%0A        Arrays.fill(mInput, UNMODIFIED);%0A        mCount = 0;%0A    %7D%0A%0A    int count() %7B%0A        return mCount;%0A    %7D%0A%0A    /**%0A     * @return the integer represented by the inputted digits%0A     */%0A    int getInput() %7B%0A        if (mCount %3C= 0) return UNMODIFIED;%0A%0A        int result = 0;%0A        for (int i = 0; i %3C mCount; i++) %7B%0A            result = result * 10 + mInput%5Bi%5D;%0A        %7D%0A        return result;%0A    %7D%0A%0A    /**%0A     * Inserts as many of the digits in the given sequence%0A     * into the input as possible.%0A     */%0A    void storeDigits(int... digits) %7B%0A        if (digits == null)%0A            return;%0A        for (int d : digits) %7B%0A            if (mCount == mInput.length)%0A                break;%0A            if (d %3E= 0 && d %3C 10) %7B%0A                storeDigit(d);%0A            %7D%0A        %7D
 %0A   

Implement DigitwiseTimeModel.