# Java：在列表中查找组合天数

``````    List<DepArr> personTrips = new ArrayList<DepArr>();
personTrips.add(new DepArr(2, 2));      // espected result = 1.00 --> 0.50 + 0.50
personTrips.add(new DepArr(3, 3));      // espected result = 0.66 --> 0.33 + 0.33
personTrips.add(new DepArr(3, 6));      // espected result = 3.33 --> 0.33 + 1.00 + 1.00 + 1.00
personTrips.add(new DepArr(7, 8));      // espected result = 1.50 --> 1.00 + 0.50
personTrips.add(new DepArr(8, 9));      // espected result = 1.00 --> 0.50 + 0.50
personTrips.add(new DepArr(9, 10));     // espected result = 0.75 --> 0.50 + 0.25
personTrips.add(new DepArr(10, 10));    // espected result = 0.50 --> 0.25 + 0.25
personTrips.add(new DepArr(10, 11));    // espected result = 1.25 --> 0.25 + 1.00
personTrips.add(new DepArr(12, 12));    // espected result = 1.00 --> 0.50 + 0.50
personTrips.add(new DepArr(13, 13));    // espected result = 0.66 --> 0.33 + 0.33
personTrips.add(new DepArr(13, 14));    // espected result = 1.33 --> 0.33 + 1.00
personTrips.add(new DepArr(15, 16));    // espected result = 2.00 --> 1.00 + 1.00

for (int i = 0; i < personTrips.size(); i++) {

DepArr personPrev = personTrips.get(i-1);
DepArr personThis = personTrips.get(i);
DepArr personNext = personTrips.get(i+1);

double base =  personThis.getArr() - personThis.getDep();
double depQuote = 0.5;
double arrQoute = 0.5;

// dep this = arr this
if(personThis.getDep() == personThis.getArr()) {
base = base + depQuote + arrQoute;
myCase = "a";
}
// *** DEP
// dep this = arr this = dep next
if(personThis.getDep() == personThis.getArr() && personThis.getArr() == personNext.getDep()) {
base = base - 1 + 2 * (depQuote + arrQoute) / 3;
myCase = "b";
}
// dep this = dep prev = arr prev
if(personThis.getDep() == personPrev.getDep() && personPrev.getDep() == personPrev.getArr()) {
base = base + 1 * (depQuote + arrQoute) / 3;
myCase = "c";
}
// dep this = arr prev
if(personThis.getDep() == personPrev.getArr() && personThis.getDep() != personThis.getArr() && personPrev.getDep() != personPrev.getArr()) {
base = base + 1 * (depQuote + arrQoute) / 2;
myCase = "d";
}
// *** ARR
// arr this = dep next = arr next
if(personThis.getArr() == personNext.getDep() && personNext.getDep() == personNext.getArr()) {
base = base + 1 * (depQuote + arrQoute) / 3;
myCase = "e";
}
// dep this = arr this = arr prev
if(personThis.getDep() == personThis.getArr() && personThis.getDep() == personPrev.getArr()) {
base = base - 1 + 2 * (depQuote + arrQoute) / 3;
myCase = "f";
}
// arr this = dep next
if(personThis.getArr() == personNext.getDep() && personThis.getDep() != personThis.getArr() && personNext.getDep() != personNext.getArr()) {
base = base + 1 * (depQuote + arrQoute) / 2;
myCase = "g";
}
// *** DEP and ARR
// dep this = arr this = dep prev = arr prev
if(personThis.getDep() == personThis.getArr() && personThis.getDep() == personPrev.getArr() && personPrev.getDep() == personPrev.getArr()) {
base = base - 1 + 2 * (depQuote + arrQoute) / 4;
myCase = "h";
}
// dep this = arr this = dep next = arr next
if(personThis.getDep() == personThis.getArr() && personThis.getArr() == personNext.getDep() && personNext.getDep() == personNext.getArr()) {
base = base - 1 + 2 * (depQuote + arrQoute) / 4;
myCase = "i";
}

Double usage = base;
log.info(i + " " + myCase + " " + personThis.getDep() + " " + personThis.getArr() + " " + usage);
}
``````