Skip to content

Commit c5d7a6f

Browse files
committed
[main] Added functions
1 parent 9347084 commit c5d7a6f

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
import java.util.concurrent.atomic.AtomicInteger;
4+
5+
// TODO: complete this object/class
6+
7+
public class PaginationHelper<I> {
8+
9+
public ArrayList<ArrayList<I>> paginatedItems;
10+
public int itemsPerPage;
11+
public int totalPages;
12+
public int totalItems;
13+
14+
/**
15+
* The constructor takes in an array of items and a integer indicating how many
16+
* items fit within a single page
17+
*/
18+
public PaginationHelper(List<I> collection, int itemsPerPage) {
19+
collection.forEach(e -> System.out.println(e));
20+
System.out.printf("itemsperpage = %d", itemsPerPage);
21+
this.paginatedItems = new ArrayList<ArrayList<I>>();
22+
this.itemsPerPage = itemsPerPage;
23+
this.totalPages = (collection.size() / this.itemsPerPage) + 1;
24+
this.totalItems = collection.size();
25+
int counter = 0;
26+
ArrayList<I> accumulatedPage = new ArrayList<I>();
27+
for (final I eachItem : collection) {
28+
if (counter == itemsPerPage) {
29+
this.paginatedItems.add(accumulatedPage);
30+
accumulatedPage.clear();
31+
accumulatedPage.add(eachItem);
32+
counter = 1;
33+
} else {
34+
counter++;
35+
accumulatedPage.add(eachItem);
36+
}
37+
}
38+
if (accumulatedPage.size() > 0) {
39+
this.paginatedItems.add(accumulatedPage);
40+
}
41+
}
42+
43+
/**
44+
* returns the number of items within the entire collection
45+
*/
46+
public int itemCount() {
47+
return this.totalItems;
48+
}
49+
50+
/**
51+
* returns the number of pages
52+
*/
53+
public int pageCount() {
54+
return this.totalPages;
55+
}
56+
57+
/**
58+
* returns the number of items on the current page. page_index is zero based.
59+
* this method should return -1 for pageIndex values that are out of range
60+
*/
61+
public int pageItemCount(int pageIndex) {
62+
System.out.println("itemcount = ", pageIndex);
63+
return this.paginatedItems.get(pageIndex).size();
64+
}
65+
66+
/**
67+
* determines what page an item is on. Zero based indexes
68+
* this method should return -1 for itemIndex values that are out of range
69+
*/
70+
public int pageIndex(int itemIndex) {
71+
if (this.totalItems == 0) {
72+
return -1;
73+
}
74+
if (this.totalItems < (itemIndex + 1)) {
75+
return -1;
76+
}
77+
return (itemIndex + 1) / this.itemsPerPage;
78+
}
79+
80+
public static void main(string[] args) {
81+
List<Integer> items = new ArrayList<>();
82+
for (int i = 1; i <= 24; i++) {
83+
items.add(i);
84+
}
85+
PaginationHelper<Integer> pagHelper = new PaginationHelper(items, 10);
86+
}
87+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function makeNegative(num) {
2+
return Math.abs(num) * -1;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function sayHello(name, city, state) {
2+
return `Hello, ${name.join(" ")}! Welcome to ${city}, ${state}!`;
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
def shifted_diff(first: str, second: str) -> int:
3+
for i in range(len(first)):
4+
if f"{first[-i:]}{first[:-i]}" == second:
5+
return i
6+
return -1
7+
8+
9+
if __name__ == '__main__':
10+
f = "Esham"
11+
s = "Esham"
12+
print(shifted_diff(f, s))

0 commit comments

Comments
 (0)