OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.distiller; | 5 package org.chromium.distiller; |
6 | 6 |
7 import java.util.ArrayList; | 7 import java.util.ArrayList; |
8 import java.util.List; | 8 import java.util.List; |
9 | 9 |
10 /** | 10 /** |
(...skipping 19 matching lines...) Expand all Loading... |
30 * parsed i.e. there's a break in the adjacency of plain numbers. | 30 * parsed i.e. there's a break in the adjacency of plain numbers. |
31 */ | 31 */ |
32 void addGroup() { | 32 void addGroup() { |
33 if (mGroups.isEmpty() || !getLastGroup().mList.isEmpty()) { | 33 if (mGroups.isEmpty() || !getLastGroup().mList.isEmpty()) { |
34 mGroups.add(new Group()); | 34 mGroups.add(new Group()); |
35 mPrevPageInfo = null; // Break in adjacency nukes the previous Page
Info. | 35 mPrevPageInfo = null; // Break in adjacency nukes the previous Page
Info. |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 /** | 39 /** |
40 * Add a PageParamInfo.PageInfo for the given page number and URL, ensuring
the group stays | 40 * Add the given PageParamInfo.PageInfo, ensuring the group stays monotonic: |
41 * monotonic: | |
42 * - add in the current group if the page number is strictly increasing or d
ecreasing | 41 * - add in the current group if the page number is strictly increasing or d
ecreasing |
43 * - otherwise, start a new group. | 42 * - otherwise, start a new group. |
44 */ | 43 */ |
45 void addNumber(int number, String url) { | 44 void addPageInfo(PageParamInfo.PageInfo pageInfo) { |
46 PageParamInfo.PageInfo pageInfo = new PageParamInfo.PageInfo(number, url
); | |
47 Group group = getLastGroup(); | 45 Group group = getLastGroup(); |
48 if (group.mList.isEmpty()) { | 46 if (group.mList.isEmpty()) { |
49 group.mList.add(pageInfo); | 47 group.mList.add(pageInfo); |
50 mPrevPageInfo = pageInfo; | 48 mPrevPageInfo = pageInfo; |
51 return; | 49 return; |
52 } | 50 } |
53 | 51 |
54 int delta = pageInfo.mPageNum - mPrevPageInfo.mPageNum; | 52 int delta = pageInfo.mPageNum - mPrevPageInfo.mPageNum; |
55 int deltaSign = delta == 0 ? 0 : (delta < 0 ? -1 : 1); | 53 int deltaSign = delta == 0 ? 0 : (delta < 0 ? -1 : 1); |
56 if (deltaSign != group.mDeltaSign) { | 54 if (deltaSign != group.mDeltaSign) { |
(...skipping 10 matching lines...) Expand all Loading... |
67 } else if (deltaSign == 0) { | 65 } else if (deltaSign == 0) { |
68 // This number is same as previous (i.e. the only entry in the group
), and will be added | 66 // This number is same as previous (i.e. the only entry in the group
), and will be added |
69 // (below), so clear the group to avoid duplication. | 67 // (below), so clear the group to avoid duplication. |
70 group.mList.clear(); | 68 group.mList.clear(); |
71 } | 69 } |
72 group.mList.add(pageInfo); | 70 group.mList.add(pageInfo); |
73 mPrevPageInfo = pageInfo; | 71 mPrevPageInfo = pageInfo; |
74 group.mDeltaSign = deltaSign; | 72 group.mDeltaSign = deltaSign; |
75 } | 73 } |
76 | 74 |
| 75 /** |
| 76 * Add a PageParamInfo.PageInfo for the given page number and URL, ensuring
the group stays |
| 77 * monotonic. |
| 78 */ |
| 79 void addNumber(int number, String url) { |
| 80 addPageInfo(new PageParamInfo.PageInfo(number, url)); |
| 81 } |
| 82 |
77 void cleanup() { | 83 void cleanup() { |
78 // Remove last empty adjacent number group. | 84 // Remove last empty adjacent number group. |
79 if (!mGroups.isEmpty() && getLastGroup().mList.isEmpty()) { | 85 if (!mGroups.isEmpty() && getLastGroup().mList.isEmpty()) { |
80 mGroups.remove(mGroups.size() - 1); | 86 mGroups.remove(mGroups.size() - 1); |
81 } | 87 } |
82 } | 88 } |
83 | 89 |
84 // Only call this if mGroups is not empty. | 90 // Only call this if mGroups is not empty. |
85 private Group getLastGroup() { | 91 private Group getLastGroup() { |
86 return mGroups.get(mGroups.size() - 1); | 92 return mGroups.get(mGroups.size() - 1); |
87 } | 93 } |
88 | 94 |
89 /** | 95 /** |
90 * Adds a new group because the new number is no longer monotonic (strictly
increasing/ | 96 * Adds a new group because the new number is no longer monotonic (strictly
increasing/ |
91 * decreasing) as in the current group. | 97 * decreasing) as in the current group. |
92 * | 98 * |
93 * @return the newly added group. | 99 * @return the newly added group. |
94 */ | 100 */ |
95 private Group addGroupButRetainPrev() { | 101 private Group addGroupButRetainPrev() { |
96 Group group = new Group(); | 102 Group group = new Group(); |
97 mGroups.add(group); | 103 mGroups.add(group); |
98 return group; | 104 return group; |
99 } | 105 } |
100 } | 106 } |
OLD | NEW |