DayClustering { public boolean isInside(DayClustering dc) { int n = dc.getGroupsCount(); for (int i = 0; i < n; ++i) { int cur = -1; for (int j = 0; j < 7; ++j) { if (dc.groups[j] == i) { int g = groups[j]; if (cur == -1) { cur = g; } else if (g != cur) { return false; } } } } return true; } DayClustering(final int[] groups); static DayClustering create(int[] groups); int getGroup(java.time.DayOfWeek dw); int getGroupsCount(); int getGroupCount(int idx); java.time.DayOfWeek[] group(int idx); int[] positions(int idx); int[][] allPositions(); boolean isInside(DayClustering dc); @Override String toString(); String toString(int i); int[] getGroupsDefinition(); static final DayClustering TD2; }
@Test public void testIsInside() { DayClustering cl0 = DayClustering.create(new int[]{0,1,1,1,1,1,0}); DayClustering cl1 = DayClustering.create(new int[]{0,2,2,2,2,2,1}); DayClustering cl2 = DayClustering.create(new int[]{0,1,2,3,4,5,6}); DayClustering cl3 = DayClustering.create(new int[]{0,1,2,0,2,3,3}); DayClustering cl4 = DayClustering.create(new int[]{0,1,2,2,2,3,0}); assertTrue(cl0.isInside(cl1)); assertTrue(cl1.isInside(cl2)); assertTrue(cl3.isInside(cl2)); assertTrue(!cl4.isInside(cl0)); assertTrue(cl0.isInside(cl4)); }