-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1600 from danilovesky/task-description-details
Task description mutable details
- Loading branch information
Showing
9 changed files
with
114 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
workcraft/WorkcraftCore/src/org/workcraft/utils/ListUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.workcraft.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ListUtils { | ||
|
||
public static <T> List<T> zip(List<T> aList, List<T> bList) { | ||
return zip(aList, bList, 1); | ||
} | ||
|
||
public static <T> List<T> zip(List<T> aList, List<T> bList, int sliceSize) { | ||
List<T> result = new ArrayList<>(); | ||
if (sliceSize < 1) { | ||
sliceSize = 1; | ||
} | ||
int aSize = aList.size(); | ||
int bSize = bList.size(); | ||
int aFromIndex = 0; | ||
int bFromIndex = 0; | ||
while ((aFromIndex < aSize) && (bFromIndex < bSize)) { | ||
int aToIndex = Math.min(aFromIndex + sliceSize, aSize); | ||
int bToIndex = Math.min(bFromIndex + sliceSize, bSize); | ||
result.addAll(aList.subList(aFromIndex, aToIndex)); | ||
result.addAll(bList.subList(bFromIndex, bToIndex)); | ||
aFromIndex = aToIndex; | ||
bFromIndex = bToIndex; | ||
} | ||
result.addAll(aList.subList(aFromIndex, aSize)); | ||
result.addAll(bList.subList(bFromIndex, bSize)); | ||
return result; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
workcraft/WorkcraftCore/test-src/org/workcraft/utils/ListUtilsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.workcraft.utils; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
class ListUtilsTests { | ||
|
||
@Test | ||
void zipTest() { | ||
Assertions.assertEquals(List.of(), | ||
ListUtils.zip(List.of(), List.of(), 1)); | ||
|
||
Assertions.assertEquals(List.of(1), | ||
ListUtils.zip(List.of(1), List.of(), 2)); | ||
|
||
Assertions.assertEquals(List.of(2, 3, 4), | ||
ListUtils.zip(List.of(), List.of(2, 3, 4), 2)); | ||
|
||
Assertions.assertEquals(Arrays.asList(1, 2, 3, 4, 5), | ||
ListUtils.zip(Arrays.asList(1, 3, 5), Arrays.asList(2, 4), 1)); | ||
|
||
Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4"), | ||
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4"), | ||
Arrays.asList("b1", "b2", "b3", "b4"), 2)); | ||
|
||
Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4", "b5", "b6", "b7"), | ||
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4"), | ||
Arrays.asList("b1", "b2", "b3", "b4", "b5", "b6", "b7"), 2)); | ||
|
||
Assertions.assertEquals(Arrays.asList("a1", "a2", "b1", "b2", "a3", "a4", "b3", "b4", "a5", "a6", "a7"), | ||
ListUtils.zip(Arrays.asList("a1", "a2", "a3", "a4", "a5", "a6", "a7"), | ||
Arrays.asList("b1", "b2", "b3", "b4"), 2)); | ||
} | ||
|
||
} |