Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import org.jetbrains.annotations.NotNull;
  2.  
  3. public class Solution implements MonotonicClock {
  4.     private final RegularInt ZERO_VALUE = new RegularInt(0);
  5.  
  6.     private final RegularInt w_r2l_c1 = new RegularInt(0);
  7.     private final RegularInt w_r2l_c2 = new RegularInt(0);
  8.     private final RegularInt w_r2l_c3 = new RegularInt(0);
  9.     private final RegularInt w_l2r_c1 = new RegularInt(0);
  10.     private final RegularInt w_l2r_c2 = new RegularInt(0);
  11.     private final RegularInt w_l2r_c3 = new RegularInt(0);
  12.  
  13.     @Override
  14.     public void write(@NotNull Time time) {
  15.         // write left-to-right
  16.         w_l2r_c1.setValue(time.getD1());
  17.         w_l2r_c2.setValue(time.getD2());
  18.         w_l2r_c3.setValue(time.getD3());
  19.  
  20.         // write right-to-left
  21.         w_r2l_c3.setValue(time.getD3());
  22.         w_r2l_c2.setValue(time.getD2());
  23.         w_r2l_c1.setValue(time.getD1());
  24.     }
  25.  
  26.     @NotNull
  27.     @Override
  28.     public Time read() {
  29.         // read left-to-right
  30.         int r_l2r_c1 = w_r2l_c1.getValue();
  31.         int r_l2r_c2 = w_r2l_c2.getValue();
  32.         int r_l2r_c3 = w_r2l_c3.getValue();
  33.  
  34.         // read right-to-left
  35.         int r_r2l_c3 = w_l2r_c3.getValue();
  36.         int r_r2l_c2 = w_l2r_c2.getValue();
  37.         int r_r2l_c1 = w_l2r_c1.getValue();
  38.  
  39.         if (r_l2r_c1 == r_r2l_c1) {
  40.             if (r_l2r_c2 == r_r2l_c2) {
  41.                 if (r_l2r_c3 == r_r2l_c3) {
  42.                     return new Time(r_l2r_c1, r_l2r_c2, r_l2r_c3);
  43.                 } else {
  44.                     return new Time(r_l2r_c1, r_l2r_c2, r_r2l_c3);
  45.                 }
  46.             } else {
  47.                 return new Time(r_l2r_c1, r_r2l_c2, ZERO_VALUE.getValue());
  48.             }
  49.         } else {
  50.             return new Time(r_r2l_c1, ZERO_VALUE.getValue(), ZERO_VALUE.getValue());
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement