|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @param size 货架单排总数 | 
|---|
|  |  |  | * @param group 货架组数量 | 
|---|
|  |  |  | * @param size   货架单排总数 | 
|---|
|  |  |  | * @param group  货架组数量 | 
|---|
|  |  |  | * @param offset 序列号偏移量 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Shelves(int size, int group, int offset) { | 
|---|
|  |  |  | this.size = size; | 
|---|
|  |  |  | this.group = group; | 
|---|
|  |  |  | this.offset = offset-1; | 
|---|
|  |  |  | this.offset = offset - 1; | 
|---|
|  |  |  | init(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 初始化方法【私有】 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void init(){ | 
|---|
|  |  |  | if (group == 0 || size%group != 0) { | 
|---|
|  |  |  | private void init() { | 
|---|
|  |  |  | if (group == 0 || size % group != 0) { | 
|---|
|  |  |  | throw new RuntimeException("shelves init fail!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | nodes = new ArrayList<>(); | 
|---|
|  |  |  | for (int g = 1; g <= this.group; g++){ | 
|---|
|  |  |  | int unit = size/group; | 
|---|
|  |  |  | for (int g = 1; g <= this.group; g++) { | 
|---|
|  |  |  | int unit = size / group; | 
|---|
|  |  |  | List<Integer> node = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = (g-1)*unit+1+offset ; i <= g*unit+offset; i++){ | 
|---|
|  |  |  | for (int i = (g - 1) * unit + 1 + offset; i <= g * unit + offset; i++) { | 
|---|
|  |  |  | node.add(i); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | nodes.add(node); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 开始计算 =======>>> | 
|---|
|  |  |  | * | 
|---|
|  |  |  | *          货架命中规则如下: | 
|---|
|  |  |  | *              安装位置:   [1]  [2]  |  [3]  [4]  --------  [5] [6]  |  [7] [8] | 
|---|
|  |  |  | *                  命中顺序:      1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ... | 
|---|
|  |  |  | * | 
|---|
|  |  |  | *          1.该规则适不限制货架数量,总数与组别在构造器中设置 | 
|---|
|  |  |  | *          2.如有序列号起始问题,用偏移量规避即可 | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | * 货架命中规则如下: | 
|---|
|  |  |  | * 安装位置:   [1]  [2]  |  [3]  [4]  --------  [5] [6]  |  [7] [8] | 
|---|
|  |  |  | * 命中顺序:      1 -> 5 -> 4 -> 8 -> 2 -> 6 -> 3 -> 7 -> 1 ... | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | * 1.该规则适不限制货架数量,总数与组别在构造器中设置 | 
|---|
|  |  |  | * 2.如有序列号起始问题,用偏移量规避即可 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param curSeq 当前货架号 | 
|---|
|  |  |  | * @return 规则命中货架号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public int start(int curSeq){ | 
|---|
|  |  |  | public int start(int curSeq) { | 
|---|
|  |  |  | Iterator<List<Integer>> iterator = nodes.iterator(); | 
|---|
|  |  |  | while (iterator.hasNext()){ | 
|---|
|  |  |  | while (iterator.hasNext()) { | 
|---|
|  |  |  | List<Integer> node = iterator.next(); | 
|---|
|  |  |  | if (node.contains(curSeq)) { | 
|---|
|  |  |  | int idx = node.indexOf(curSeq); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Integer get(Integer curRow) { | 
|---|
|  |  |  | for (List<Integer> node : nodes){ | 
|---|
|  |  |  | for (List<Integer> node : nodes) { | 
|---|
|  |  |  | if (node.contains(curRow)) { | 
|---|
|  |  |  | return nodes.indexOf(node) + 1; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static void main(String[] args) throws InterruptedException { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | double remainder = Arith.divides(1,16 - 1, 16); | 
|---|
|  |  |  | double remainder = Arith.divides(1, 16 - 1, 16); | 
|---|
|  |  |  | System.out.println(remainder); | 
|---|
|  |  |  | System.out.println((int) remainder); | 
|---|
|  |  |  | //        Shelves shelves = new Shelves(8,2); | 
|---|