package com.zy.asrs.utils;
|
|
import com.zy.asrs.entity.BasDevpPosition;
|
import com.zy.core.enums.RouteCollectCountType;
|
|
import java.util.Arrays;
|
import java.util.List;
|
|
public class SortTheExecutionOfTheCarUtil {
|
//排序
|
public static int[][] ReorderSteId(int[][] steList,int steNoStart){
|
int[][] ints = new int[steList.length][2];
|
int Difference = 0;
|
for (int[] steNo : steList){
|
if (steNo[0] == steNoStart){
|
Difference = steNo[1] - 1;
|
break;
|
}
|
}
|
for (int[] steNo : steList){
|
int i = steNo[1];
|
if (i > Difference){
|
steNo[1] = i - Difference;
|
} else {
|
steNo[1] = steList.length + i-Difference;
|
}
|
ints[steNo[0]-1] = steNo;
|
}
|
return ints;
|
}
|
|
//获取最近并在当前位置前边的位置
|
public static Integer LatelyAndLessThan(List<BasDevpPosition> devpPosition, long nowPosition){
|
Integer result = 0;
|
long Difference = 1737000L;
|
for (BasDevpPosition positions : devpPosition){
|
Long position = positions.getPlcPosition();
|
if (position<=nowPosition){
|
if ((nowPosition-position) < Difference){
|
Difference = nowPosition-position;
|
result = positions.getDevNo();
|
}
|
} else {
|
if ((nowPosition-(position - 1737000L)) < Difference){
|
Difference = nowPosition-(position - 1737000L);
|
result = positions.getDevNo();
|
}
|
}
|
}
|
return result;
|
}
|
//获取最近并在当前位置前边的位置
|
public static Long LatelyAndLessThan(long[] devpPosition,long nowPosition){
|
long result = 0L;
|
long Difference = 1737000L;
|
for (long position : devpPosition){
|
if (position<=nowPosition){
|
if ((nowPosition-position) < Difference){
|
Difference = nowPosition-position;
|
result = position;
|
}
|
} else {
|
if ((nowPosition-(position - 1737000L)) < Difference){
|
Difference = nowPosition-(position - 1737000L);
|
result = position;
|
}
|
}
|
}
|
return result;
|
}
|
|
//id初始化
|
public static List<BasDevpPosition> devpNoInit(List<BasDevpPosition> devpPosition){
|
long i = 0;
|
for (BasDevpPosition basDevpPosition : devpPosition){
|
i++;
|
basDevpPosition.setId(i);
|
}
|
return devpPosition;
|
}
|
|
|
//站点排序
|
public static BasDevpPosition[] devpNoSort(List<BasDevpPosition> devpPosition1,Integer devpNo){
|
List<BasDevpPosition> devpPosition = devpNoInit(devpPosition1);
|
BasDevpPosition[] basDevpPositions = new BasDevpPosition[devpPosition.size()];
|
long Difference = 0L;
|
for (BasDevpPosition basDevpPosition : devpPosition){
|
if (basDevpPosition.getDevNo().equals(devpNo)){
|
Difference = basDevpPosition.getId() - 1L;
|
break;
|
}
|
}
|
for (BasDevpPosition basDevpPosition : devpPosition){
|
long i = basDevpPosition.getId();
|
if (i > Difference){
|
basDevpPosition.setId(i - Difference);
|
} else {
|
basDevpPosition.setId(devpPosition.size() + i - Difference);
|
}
|
basDevpPositions[basDevpPosition.getId().intValue()-1] = basDevpPosition;
|
}
|
return basDevpPositions;
|
}
|
|
//逆序排列
|
public static BasDevpPosition[] devpNoSortUN(BasDevpPosition[] devpPosition){
|
BasDevpPosition[] basDevpPositions = new BasDevpPosition[devpPosition.length];
|
for (BasDevpPosition basDevpPosition : devpPosition){
|
basDevpPositions[devpPosition.length - basDevpPosition.getId().intValue()] = basDevpPosition;
|
}
|
return basDevpPositions;
|
}
|
|
//逆序排列
|
public static boolean devpNoSortbj(BasDevpPosition[] devpPosition,Integer souDevpNo,Integer endDevpNo){
|
int sou = 0;
|
int end = 0;
|
for (int i = 0;i<devpPosition.length;i++){
|
if (devpPosition[i].getDevNo().equals(souDevpNo)){
|
sou = i;
|
}
|
if (devpPosition[i].getDevNo().equals(endDevpNo)){
|
end = i;
|
}
|
}
|
|
return sou>end;
|
}
|
|
public static void main(String[] args) {
|
int[][] ints = new int[][]{{1,1},{3,3},{2,2},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},{10,10}};
|
|
int[][] reorderSteId = ReorderSteId(ints, 2);
|
for (int[] ste : reorderSteId){
|
System.out.println(Arrays.toString(ste));
|
}
|
|
long[] longs = new long[]{1L,1000L,200000L,1100000L,1600000L};
|
long l = LatelyAndLessThan(longs, 1100000L);
|
System.out.println("l:"+l);
|
}
|
}
|