Салам, я хочу получить список комбинаций, который представляет каждую уникальную комбинацию всех значений в моем списке списков. например, у меня есть список, который содержит список сессий, и я хочу комбинацию из каждого списка сессий:
My List of lists
{ List of Sessions1[S1,S2,S3]
List of Sessions2[S4,S5]
List of Sessions3[S6,S7]
}
список, который я получаю:
List result
{
List combination 1[S1,S4,S6]
List combination 2[S1,S4,S7]
List combination 3[S1,S5,S6]
.
.
.
}
У меня есть метод и это работает, но проблема в переменной j, потому что мои списки слишком велики, поэтому, когда она проходит 9223372036854775807 (2 ^ 63-1), она начинает давать отрицательные значения и разрушает прогресс, вот мой код
public List<List<Seance>> allUniqueCombinations1(List<List<Seance>> dataStructure) throws SQLException {
int n = dataStructure.size();
long solutions = 1;
for (List vector : dataStructure) {
solutions *= vector.size(); if(solutions>1000000000) break;//this condition is for the same problem
}
List<List<Seance>> allCombinations = new LinkedList();
for (int i = 0; i < solutions; i++) {
List<List<List<Seance>>> liste = new LinkedList();
List<Seance> combination = new LinkedList();
long j = 1;
List<List<Seance>> data = new LinkedList();
data = dataStructure;
int u = 0;
for (int a=0;a< data.size();a++) {
List vec =(List<Seance>) data.get(a);
combination.add((Seance) vec.get((i / (int)j) % vec.size()));
j *= vec.size();
data = remouve_conflicts(data, combination.get(u),u);//this removes all the sessions that will make a conflict with the session chosen in order not to appear in my combinition
u++;
}
}
return allCombinations;
}