├── FurnitureFactory
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── hackerrank
│ │ ├── Furniture.java
│ │ ├── FurnitureOrder.java
│ │ └── FurnitureOrderInterface.java
│ └── test
│ └── java
│ └── hackerrank
│ ├── PrivateUnitTest.java
│ ├── SampleUnitTest.java
│ └── UnitTestSuite.java
├── check-braces
└── Exercise.java
├── codility
├── NailHammered.java
├── Solution.sql
├── StreamSolution.java
└── TransactionalStack.java
├── events-dataset-api-java
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── hackerrank
│ │ │ └── github
│ │ │ ├── Application.java
│ │ │ ├── controller
│ │ │ └── GithubApiRestController.java
│ │ │ ├── exception
│ │ │ ├── BadRequestException.java
│ │ │ └── NotFoundException.java
│ │ │ ├── model
│ │ │ ├── Actor.java
│ │ │ ├── Event.java
│ │ │ └── Repo.java
│ │ │ ├── repository
│ │ │ ├── ActorRepository.java
│ │ │ ├── EventRepository.java
│ │ │ └── RepoRepository.java
│ │ │ ├── service
│ │ │ ├── GithubApiRestServiceImpl.java
│ │ │ └── interfaces
│ │ │ │ └── GithubApiRestService.java
│ │ │ └── util
│ │ │ └── MapUtil.java
│ └── resources
│ │ └── application.properties
│ └── test
│ ├── java
│ └── com
│ │ └── hackerrank
│ │ └── github
│ │ └── HttpJsonDynamicUnitTest.java
│ └── resources
│ └── testcases
│ ├── description.txt
│ ├── http00.json
│ ├── http01.json
│ ├── http02.json
│ ├── http03.json
│ ├── http04.json
│ └── http05.json
├── find-odd-number
└── Exercise.java
├── merge-order-two-arrays
└── Exercise.java
├── product-arrays
└── Exercise.java
├── stream-sugestions
├── main
│ └── java
│ │ └── com
│ │ └── streams
│ │ ├── model
│ │ ├── Author.java
│ │ ├── Book.java
│ │ ├── Genre.java
│ │ └── Reader.java
│ │ └── services
│ │ └── SuggestionService.java
└── test
│ └── java
│ └── com
│ └── streams
│ └── services
│ └── SuggestionServiceTest.java
├── subarray-length
└── Application.java
├── sum-lcm-from-numbers
└── Exercise.java
└── vh-fair
├── .gitignore
├── bin
└── br
│ └── com
│ └── ironimedina
│ ├── digitalwallet
│ ├── DigitalWallet.class
│ ├── DigitalWalletTransaction.class
│ ├── Solution.class
│ └── TransactionException.class
│ ├── dostuff
│ ├── HelloWorld.class
│ ├── Interf.class
│ └── Pancake.class
│ ├── jsonstock
│ ├── Solution$StockDataEntity.class
│ ├── Solution$StockEntity.class
│ └── Solution.class
│ ├── reformatdate
│ └── Solution.class
│ ├── thread
│ ├── Logger.class
│ ├── Main.class
│ └── RunnableDemo.class
│ └── workschedule
│ ├── RightSolution.class
│ ├── Solution.class
│ └── Solution2.class
└── src
└── br
└── com
└── ironimedina
├── digitalwallet
└── Solution.java
├── dostuff
├── HelloWorld.java
└── Interf.java
├── jsonstock
└── Solution.java
├── reformatdate
└── Solution.java
├── thread
├── Logger.java
├── Main.java
└── RunnableDemo.java
└── workschedule
├── RightSolution.java
├── Solution.java
└── Solution2.java
/FurnitureFactory/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | .classpath
3 | .project
4 | /.settings/
5 |
--------------------------------------------------------------------------------
/FurnitureFactory/pom.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 | 4.0.0
6 |
7 | hackerrank
8 | FurnitureFactory
9 | jar
10 | 1.0-SNAPSHOT
11 |
12 | FurnitureFactory
13 |
14 | http://maven.apache.org
15 |
16 |
17 |
18 | junit
19 | junit
20 | 4.12
21 | test
22 |
23 |
24 |
25 |
26 |
27 |
28 | org.apache.maven.plugins
29 | maven-compiler-plugin
30 | 3.1
31 |
32 | 1.8
33 | 1.8
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/FurnitureFactory/src/main/java/hackerrank/Furniture.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | /**
4 | * FURNITURE_TYPE("Furniture Name", floating-point cost)
5 | */
6 |
7 |
8 | public enum Furniture {
9 | CHAIR("Chair", 100.0f),
10 | TABLE("Table", 250.0f),
11 | COUCH("Couch", 500.0f);
12 |
13 | private final String label;
14 | private final float cost;
15 |
16 | /**
17 | * @param label The plain text name of the furniture
18 | * @param cost The furniture's cost
19 | */
20 | Furniture(String label, float cost) {
21 | this.label = label;
22 | this.cost = cost;
23 | }
24 |
25 | /**
26 | * @return The plain text name of the furniture
27 | */
28 | public String label() {
29 | return this.label;
30 | }
31 |
32 | /**
33 | * @return The furniture's cost
34 | */
35 | public float cost() {
36 | return this.cost;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/FurnitureFactory/src/main/java/hackerrank/FurnitureOrder.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | import java.util.HashMap;
4 | import java.util.stream.Collectors;
5 |
6 | public class FurnitureOrder implements FurnitureOrderInterface {
7 |
8 | private final HashMap furnitures;
9 |
10 | /**
11 | * Initialize a new mapping of Furniture types to order quantities.
12 | */
13 | FurnitureOrder() {
14 | furnitures = new HashMap();
15 | }
16 |
17 | public void addToOrder(final Furniture type, final int furnitureCount) {
18 | Integer count = 0;
19 | if(furnitures.containsKey(type)) {
20 | count = furnitures.get(type);
21 | }
22 | furnitures.put(type, count + furnitureCount);
23 | }
24 |
25 | public HashMap getOrderedFurniture() {
26 | return new HashMap(furnitures);
27 | }
28 |
29 | public float getTotalOrderCost() {
30 | if(!furnitures.isEmpty()) {
31 | return furnitures.entrySet().stream()
32 | .map(f -> f.getKey().cost() * f.getValue())
33 | .collect(Collectors.toList())
34 | .stream()
35 | .reduce(Float::sum)
36 | .get();
37 | }
38 | return 0.0f;
39 | }
40 |
41 | public int getTypeCount(Furniture type) {
42 | if(furnitures.containsKey(type)) {
43 | return furnitures.get(type);
44 | }
45 | return 0;
46 | }
47 |
48 | public float getTypeCost(Furniture type) {
49 | if(furnitures.containsKey(type)) {
50 | return furnitures.get(type) * type.cost();
51 | }
52 | return 0.0f;
53 | }
54 |
55 | public int getTotalOrderQuantity() {
56 | if(!furnitures.isEmpty()) {
57 | return furnitures.values().stream()
58 | .reduce(Integer::sum)
59 | .get();
60 | }
61 | return 0;
62 | }
63 | }
--------------------------------------------------------------------------------
/FurnitureFactory/src/main/java/hackerrank/FurnitureOrderInterface.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | import java.util.HashMap;
4 |
5 | public interface FurnitureOrderInterface {
6 |
7 | /**
8 | * @param type The type of Furniture being added to the order.
9 | * @param count The number of units of Furniture type 'type' to add to the order.
10 | */
11 | public void addToOrder(final Furniture type, final int count);
12 |
13 | /**
14 | * @return All the ordered furniture as a mapping of Furniture types to Integer quantities.
15 | */
16 | public HashMap getOrderedFurniture();
17 |
18 | /**
19 | * @param type The type of Furniture
20 | * @return The total number of units of Furniture 'type' in the order.
21 | */
22 | public int getTypeCount(Furniture type);
23 |
24 | /**
25 | *
26 | * @param type The type of Furniture being ordered
27 | * @return The total cost of just the Furniture units of 'type' in the order.
28 | */
29 | public float getTypeCost(Furniture type);
30 |
31 | /**
32 | * @return The total cost of the order.
33 | */
34 | public float getTotalOrderCost();
35 |
36 | /**
37 | * @return The total number of all types of Furniture units in the order.
38 | */
39 | public int getTotalOrderQuantity();
40 | }
41 |
--------------------------------------------------------------------------------
/FurnitureFactory/src/test/java/hackerrank/PrivateUnitTest.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | import java.util.HashMap;
4 |
5 | import static junit.framework.TestCase.assertEquals;
6 | import org.junit.BeforeClass;
7 | import org.junit.FixMethodOrder;
8 | import org.junit.Test;
9 | import org.junit.runners.MethodSorters;
10 |
11 | @FixMethodOrder(MethodSorters.NAME_ASCENDING)
12 |
13 | public class PrivateUnitTest {
14 | private static FurnitureOrder furnitureFactory;
15 |
16 | @BeforeClass
17 | public static void instantiate() {
18 | furnitureFactory = new FurnitureOrder();
19 | }
20 |
21 | @Test
22 | public void _08_orderNothing() {
23 | furnitureFactory.addToOrder(Furniture.TABLE, 0);
24 | furnitureFactory.addToOrder(Furniture.CHAIR, 0);
25 | furnitureFactory.addToOrder(Furniture.COUCH, 0);
26 |
27 | assertEquals(0.0f, furnitureFactory.getTotalOrderCost());
28 | }
29 |
30 | @Test
31 | public void _09_placeOrders() {
32 | furnitureFactory.addToOrder(Furniture.TABLE, 6);
33 | furnitureFactory.addToOrder(Furniture.CHAIR, 10);
34 | furnitureFactory.addToOrder(Furniture.COUCH, 5);
35 |
36 | assertEquals(5000.0f, furnitureFactory.getTotalOrderCost());
37 | }
38 |
39 | @Test
40 | public void _10_validateFurnitureCostAndQuantity() {
41 | // ArrayList orderedFurniture = furnitureFactory.getOrderedFurniture();
42 | HashMap orderedFurniture = furnitureFactory.getOrderedFurniture();
43 |
44 | assertEquals(21, orderedFurniture.values().stream().mapToInt(Integer::intValue).sum());
45 |
46 | orderedFurniture.keySet().forEach(furniture -> {
47 | if ("Chair".equals(furniture.label())) {
48 | assertEquals(100.0f, furniture.cost());
49 | }
50 |
51 | if ("Table".equals(furniture.label())) {
52 | assertEquals(250.0f, furniture.cost());
53 | }
54 |
55 | if ("Couch".equals(furniture.label())) {
56 | assertEquals(500.0f, furniture.cost());
57 | }
58 | });
59 |
60 | assertEquals(10, furnitureFactory.getTypeCount(Furniture.CHAIR));
61 | assertEquals(1000.0f, furnitureFactory.getTypeCost(Furniture.CHAIR));
62 |
63 | assertEquals(6, furnitureFactory.getTypeCount(Furniture.TABLE));
64 | assertEquals(1500.0f, furnitureFactory.getTypeCost(Furniture.TABLE));
65 |
66 | assertEquals(5, furnitureFactory.getTypeCount(Furniture.COUCH));
67 |
68 | assertEquals(2500.0f, furnitureFactory.getTypeCost(Furniture.COUCH));
69 |
70 | // Validates order size
71 | assertEquals(21, furnitureFactory.getTotalOrderQuantity());
72 | }
73 |
74 | @Test
75 | public void _11_validateFurniture() {
76 | for (Furniture f : Furniture.values()) {
77 | switch(f.label()) {
78 | case("Chair"):
79 | assertEquals(100.0f, f.cost());
80 | break;
81 | case("Table"):
82 | assertEquals(250.0f, f.cost());
83 | break;
84 | case("Couch"):
85 | assertEquals(500.0f, f.cost());
86 | break;
87 | }
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/FurnitureFactory/src/test/java/hackerrank/SampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | import static junit.framework.TestCase.assertEquals;
4 | import org.junit.BeforeClass;
5 | import org.junit.FixMethodOrder;
6 | import org.junit.Test;
7 | import org.junit.runners.MethodSorters;
8 |
9 |
10 | @FixMethodOrder(MethodSorters.NAME_ASCENDING)
11 | public class SampleUnitTest {
12 | private static FurnitureOrder furnitureFactory;
13 |
14 | @BeforeClass
15 | public static void instantiate() {
16 | furnitureFactory = new FurnitureOrder();
17 | }
18 |
19 | @Test
20 | public void _01_getChairCount() {
21 | assertEquals(0, furnitureFactory.getTypeCount(Furniture.CHAIR));
22 | }
23 |
24 | @Test
25 | public void _02_orderFourChairs() {
26 | furnitureFactory.addToOrder(Furniture.CHAIR, 4);
27 | assertEquals(4, furnitureFactory.getTypeCount(Furniture.CHAIR));
28 | }
29 |
30 | @Test
31 | public void _03_orderThreeCouches() {
32 | furnitureFactory.addToOrder(Furniture.COUCH, 3);
33 | assertEquals(3, furnitureFactory.getTypeCount(Furniture.COUCH));
34 | }
35 |
36 | @Test
37 | public void _04_orderedChairsCost() {
38 | assertEquals(400.0f, furnitureFactory.getTypeCost(Furniture.CHAIR));
39 | }
40 |
41 | @Test
42 | public void _05_orderedTablesCost() {
43 | assertEquals(0.0f, furnitureFactory.getTypeCost(Furniture.TABLE));
44 | }
45 |
46 | @Test
47 | public void _06_orderedCouchesCost() {
48 | assertEquals(1500.0f, furnitureFactory.getTypeCost(Furniture.COUCH));
49 | }
50 |
51 | @Test
52 | public void _07_totalOrderCost() {
53 | furnitureFactory.addToOrder(Furniture.TABLE, 6);
54 | assertEquals(3400.0f, furnitureFactory.getTotalOrderCost());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/FurnitureFactory/src/test/java/hackerrank/UnitTestSuite.java:
--------------------------------------------------------------------------------
1 | package hackerrank;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 |
6 | @RunWith(Suite.class)
7 |
8 | @Suite.SuiteClasses({
9 | SampleUnitTest.class,
10 | PrivateUnitTest.class
11 | })
12 |
13 | public class UnitTestSuite {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/check-braces/Exercise.java:
--------------------------------------------------------------------------------
1 | public class Exercise {
2 |
3 | public static void main(String[] args) {
4 | String braces [] = {"{}[]()"};
5 | System.out.println(braces(braces));
6 | }
7 |
8 | private static String[] braces(String[] values) {
9 | String ret [] = new String[values.length];
10 |
11 | for(int i = 0; i < values.length; i++) {
12 | ret[i] = isValidBraces(values[i]) ? "YES" : "NO";
13 | }
14 |
15 | return ret;
16 | }
17 |
18 | private static final int SIZE = 2;
19 |
20 | private static boolean isValidBraces(final String value) {
21 | String braces = value;
22 |
23 | while (braces.contains("()") || braces.contains("[]") || braces.contains("{}")) {
24 | if (braces.contains("()")) {
25 | braces = braces.substring(0, braces.indexOf("()"))
26 | + braces.substring(braces.indexOf("()") + SIZE, braces.length());
27 | }
28 | if (braces.contains("{}")) {
29 | braces = braces.substring(0, braces.indexOf("{}"))
30 | + braces.substring(braces.indexOf("{}") + SIZE, braces.length());
31 | }
32 | if (braces.contains("[]")) {
33 | braces = braces.substring(0, braces.indexOf("[]"))
34 | + braces.substring(braces.indexOf("[]") + SIZE, braces.length());
35 | }
36 | }
37 |
38 | return braces.isEmpty();
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/codility/NailHammered.java:
--------------------------------------------------------------------------------
1 | package codility;
2 |
3 | public class NailHammered {
4 |
5 | public static void main(String[] args) {
6 | int[] A = {1, 1, 3, 3, 3, 4, 5, 5, 5};
7 | System.out.println(solutionPosted(A, 2));
8 | System.out.println(solutionPosted(new int[]{1, 1, 3, 3, 3, 4, 5, 5, 5, 5}, 2));
9 | System.out.println(solutionPosted(new int[]{1}, 3));
10 | System.out.println(solutionPosted(new int[]{1}, 1));
11 | System.out.println(solutionPosted(new int[]{1, 3}, 2));
12 | System.out.println(solutionPosted(new int[]{1, 2, 3, 4}, 2));
13 |
14 | }
15 |
16 | public static int solutionBest(int[] A, int K) {
17 | int aLength = A.length;
18 | if (K >= A.length) {
19 | return A.length; // if K is greater than array size so return array size
20 | }
21 |
22 | int biggestRepeat = 1; //starts with 1 because always repeat at least once
23 | int repeatCounter = 1; //starts with 1 because always repeat at least once
24 | for (int i = 0 ; i < aLength - K - 1; i++) { //ignore the last K numbers from array
25 | if (A[i] == A[i+1]) { //is repeated with next number
26 | repeatCounter++;
27 | } else {
28 | repeatCounter = 1; // reset repeater
29 | }
30 | if (repeatCounter > biggestRepeat) {
31 | biggestRepeat = repeatCounter;
32 | }
33 | }
34 | return biggestRepeat + K; // sum the biggest repetition with the K
35 | }
36 |
37 | public static int solutionPosted(int[] A, int N) {
38 | int[] res = new int[A[A.length - 1]+1]; //new array with (lastNumber + 1) positions
39 | int len = A.length -1;
40 | while(len >= 0 && A[A.length - 1] == A[len]) {
41 | len--;
42 | } //set len as the lastIndex before the last number
43 | res[A[A.length-1]] = A.length - 1 - len; //quantidade de numeros iguais nas ultimas posições do array
44 | int cur = 0;
45 | for (int i = len; i>= 0; i--) {
46 | if (A[i+1] != A[i] && A[i+1] - A[i] <= N) {
47 | if (i+1 != A.length - 1) {
48 | res[A[i+1]] = cur + res[A[i+1]];
49 | }
50 | res[A[i]] = Math.min(N, res[A[i+1]]);
51 | cur = 1;
52 | } else if (A[i] == A[i+1]) {
53 | cur++;
54 | } else if (A[i+1] != A[i] && A[i+1] - A[i] > N) {
55 | res[A[i]] = 0;
56 | cur = 1;
57 | }
58 | }
59 |
60 | int greatest = 0;
61 | for (int i = 0; i < A[A.length-1]+1; i++) {
62 | greatest = Math.max(res[i], greatest);
63 | }
64 | return greatest;
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/codility/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT d.name
2 | , sum(CASE WHEN d.value > 0 THEN d.value ELSE 0) deposit
3 | , sum(CASE WHEN d.value <= 0 THEN d.value * -1 ELSE 0) withdrawl
4 | FROM deposits d
5 | GROUP BY d.name
6 | ORDER BY d.name
--------------------------------------------------------------------------------
/codility/StreamSolution.java:
--------------------------------------------------------------------------------
1 | package codility;
2 |
3 | public class StreamSolution {
4 |
5 | public static Stream reconcile(Stream pending, Stream> processed) {
6 | if(pending == null || processed == null) {
7 | return Stream.empty();
8 | }
9 | List filteredProcessedId = processed
10 | .flatMap(p -> p)
11 | .filter(Objects::nonNull)
12 | .filter(p -> p.getStatus() != null && p.getStatus().isPresent() && "DONE".equalsIgnoreCase(p.getStatus().get()))
13 | .filter(p -> p.getId() != null && p.getId().length() > 0 && pending.anyMatch(pp -> pp.equals(p.getId())))
14 | .map(p -> Long.parseLong(p.getId())).collect(Collectors.toList());
15 |
16 | return pending.filter(p -> filteredProcessedId.contains(p.getId()));
17 | }
18 |
19 | }
--------------------------------------------------------------------------------
/codility/TransactionalStack.java:
--------------------------------------------------------------------------------
1 | package codility;
2 |
3 | import java.util.Stack;
4 |
5 | public class TransactionalStack {
6 |
7 | private Stack values;
8 | private Stack transactions;
9 |
10 | public TransactionalStack() {
11 | values = new Stack<>();
12 | transactions = new Stack<>();
13 | transactions.push(this);
14 | }
15 |
16 | public void push(int value) {
17 | if (!transactions.isEmpty()) {
18 | transactions.peek().values.push(value);
19 | }
20 | }
21 |
22 | public int top() {
23 | if (!transactions.isEmpty()
24 | && !transactions.peek().values.isEmpty()) {
25 | return transactions.peek().values.peek();
26 | }
27 | return 0;
28 | }
29 |
30 | public void pop() {
31 | if (!transactions.isEmpty()
32 | && !transactions.peek().values.isEmpty()) {
33 | transactions.peek().values.pop();
34 | }
35 | }
36 |
37 | public void begin() {
38 | TransactionalStack transaction = new TransactionalStack();
39 | //transaction.values = values; //need to copy/clone
40 | transactions.add(transaction);
41 | }
42 |
43 | public boolean rollback() {
44 | if (transactions.peek() != this) {
45 | transactions.pop();
46 | return true;
47 | } else {
48 | return false;
49 | }
50 | }
51 |
52 | public boolean commit() {
53 | TransactionalStack latestTransaction = transactions.peek();
54 | if (latestTransaction != this) {
55 | latestTransaction = transactions.pop();
56 | // transactions.peek().values = latestTransaction.values;
57 | for(Integer i: latestTransaction.values) {
58 | transactions.peek().values.push(i);
59 | }
60 | return true;
61 | }
62 | return false;
63 | }
64 |
65 | public static void main(String[] args) {
66 | TransactionalStack transactionalStack = new TransactionalStack();
67 | transactionalStack.push(4);
68 | transactionalStack.rollback(); // false;
69 | transactionalStack.begin(); // start transaction 1
70 | transactionalStack.push(7); // stack: [4,7]
71 | transactionalStack.begin(); // start transaction 2
72 | transactionalStack.push(2); // stack: [4,7,2]
73 | System.out.println(transactionalStack.rollback());// == true; // rollback transaction 2
74 | System.out.println(transactionalStack.top());// == 7; // stack: [4,7]
75 | transactionalStack.begin(); // start transaction 3
76 | transactionalStack.push(10); // stack: [4,7,10]
77 | System.out.println(transactionalStack.commit());// == true; // transaction 3 is committed
78 | System.out.println(transactionalStack.top()); //== 10;
79 | System.out.println(transactionalStack.commit());// == true; // rollback transaction 1
80 | System.out.println(transactionalStack.top());// == 4; // stack: [4]
81 | System.out.println(transactionalStack.commit());// == false; // there is no open transaction
82 |
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/events-dataset-api-java/.gitignore:
--------------------------------------------------------------------------------
1 | # Source : https://github.com/github/gitignore
2 | # Maven, Node, Python, Rails
3 |
4 | # Maven
5 |
6 | target/
7 | pom.xml.tag
8 | pom.xml.releaseBackup
9 | pom.xml.versionsBackup
10 | pom.xml.next
11 | release.properties
12 | buildNumber.properties
13 | .mvn/timing.properties
14 | .mvn/wrapper/maven-wrapper.jar
15 |
16 | # Node
17 |
18 | # Logs
19 | logs
20 | *.log
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
25 | # Runtime data
26 | pids
27 | *.pid
28 | *.seed
29 | *.pid.lock
30 |
31 | # Directory for instrumented libs generated by jscoverage/JSCover
32 | lib-cov
33 |
34 | # Coverage directory used by tools like istanbul
35 | coverage
36 |
37 | # nyc test coverage
38 | .nyc_output
39 |
40 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
41 | .grunt
42 |
43 | # Bower dependency directory (https://bower.io/)
44 | bower_components
45 |
46 | # node-waf configuration
47 | .lock-wscript
48 |
49 | # Compiled binary addons (https://nodejs.org/api/addons.html)
50 | build/Release
51 |
52 | # Dependency directories
53 | node_modules/
54 | jspm_packages/
55 |
56 | # TypeScript v1 declaration files
57 | typings/
58 |
59 | # Optional npm cache directory
60 | .npm
61 |
62 | # Optional eslint cache
63 | .eslintcache
64 |
65 | # Optional REPL history
66 | .node_repl_history
67 |
68 | # Output of 'npm pack'
69 | *.tgz
70 |
71 | # Yarn Integrity file
72 | .yarn-integrity
73 |
74 | # parcel-bundler cache (https://parceljs.org/)
75 | .cache
76 |
77 | # next.js build output
78 | .next
79 |
80 | # nuxt.js build output
81 | .nuxt
82 |
83 | # vuepress build output
84 | .vuepress/dist
85 |
86 | # Serverless directories
87 | .serverless
88 |
89 | # Python
90 |
91 | # Byte-compiled / optimized / DLL files
92 | __pycache__/
93 | *.py[cod]
94 | *$py.class
95 |
96 | # C extensions
97 | *.so
98 |
99 | # Distribution / packaging
100 | .Python
101 | build/
102 | develop-eggs/
103 | dist/
104 | downloads/
105 | eggs/
106 | .eggs/
107 | lib64/
108 | parts/
109 | sdist/
110 | var/
111 | wheels/
112 | *.egg-info/
113 | .installed.cfg
114 | *.egg
115 | MANIFEST
116 |
117 | # PyInstaller
118 | # Usually these files are written by a python script from a template
119 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
120 | *.manifest
121 | *.spec
122 |
123 | # Installer logs
124 | pip-log.txt
125 | pip-delete-this-directory.txt
126 |
127 | # Unit test / coverage reports
128 | htmlcov/
129 | .tox/
130 | .coverage
131 | .coverage.*
132 | .cache
133 | nosetests.xml
134 | coverage.xml
135 | *.cover
136 | .hypothesis/
137 | .pytest_cache/
138 |
139 | # Translations
140 | *.mo
141 | *.pot
142 |
143 | # Django stuff:
144 | *.log
145 | local_settings.py
146 | db.sqlite3
147 |
148 | # Flask stuff:
149 | instance/
150 | .webassets-cache
151 |
152 | # Scrapy stuff:
153 | .scrapy
154 |
155 | # Sphinx documentation
156 | docs/_build/
157 |
158 | # PyBuilder
159 | target/
160 |
161 | # Jupyter Notebook
162 | .ipynb_checkpoints
163 |
164 | # pyenv
165 | .python-version
166 |
167 | # celery beat schedule file
168 | celerybeat-schedule
169 |
170 | # SageMath parsed files
171 | *.sage.py
172 |
173 | # Environments
174 | .venv
175 | env/
176 | venv/
177 | ENV/
178 | env.bak/
179 | venv.bak/
180 |
181 | # Spyder project settings
182 | .spyderproject
183 | .spyproject
184 |
185 | # Rope project settings
186 | .ropeproject
187 |
188 | # mkdocs documentation
189 | /site
190 |
191 | # mypy
192 | .mypy_cache/
193 |
194 | # Rails
195 |
196 | *.rbc
197 | capybara-*.html
198 | /log
199 | /tmp
200 | /db/*.sqlite3
201 | /db/*.sqlite3-journal
202 | /public/system
203 | /coverage/
204 | /spec/tmp
205 | *.orig
206 | rerun.txt
207 | pickle-email-*.html
208 |
209 | ## Environment normalization:
210 | /.bundle
211 | /vendor/bundle
212 |
213 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
214 | .rvmrc
215 |
216 | # if using bower-rails ignore default bower_components path bower.json files
217 | /vendor/assets/bower_components
218 | *.bowerrc
219 |
220 | # Ignore pow environment settings
221 | .powenv
222 |
223 | # Ignore Byebug command history file.
224 | .byebug_history
225 |
226 | # Ignore node_modules
227 | node_modules/
228 |
--------------------------------------------------------------------------------
/events-dataset-api-java/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.hackerrank
6 | github
7 | 1.0-SNAPSHOT
8 | jar
9 |
10 |
11 | UTF-8
12 | 1.8
13 | 1.8
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-parent
19 | 1.5.6.RELEASE
20 |
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-starter-web
32 |
33 |
34 |
35 | com.h2database
36 | h2
37 | runtime
38 |
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-test
43 | test
44 |
45 |
46 |
47 | org.unitils
48 | unitils-core
49 | 3.4.6
50 | test
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-maven-plugin
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/Application.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github;
2 |
3 | import java.util.TimeZone;
4 | import javax.annotation.PostConstruct;
5 | import org.springframework.boot.SpringApplication;
6 | import org.springframework.boot.autoconfigure.SpringBootApplication;
7 |
8 | @SpringBootApplication
9 | public class Application {
10 | public static void main(String[] args) {
11 | SpringApplication.run(Application.class, args);
12 | }
13 |
14 | @PostConstruct
15 | private void setTimeZone() {
16 | TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/controller/GithubApiRestController.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.controller;
2 |
3 | import java.util.List;
4 |
5 | import javax.validation.Valid;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.http.HttpStatus;
9 | import org.springframework.http.ResponseEntity;
10 | import org.springframework.web.bind.annotation.DeleteMapping;
11 | import org.springframework.web.bind.annotation.GetMapping;
12 | import org.springframework.web.bind.annotation.PathVariable;
13 | import org.springframework.web.bind.annotation.PostMapping;
14 | import org.springframework.web.bind.annotation.PutMapping;
15 | import org.springframework.web.bind.annotation.RequestBody;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | import com.hackerrank.github.exception.BadRequestException;
19 | import com.hackerrank.github.exception.NotFoundException;
20 | import com.hackerrank.github.model.Actor;
21 | import com.hackerrank.github.model.Event;
22 | import com.hackerrank.github.service.interfaces.GithubApiRestService;
23 |
24 | @RestController
25 | public class GithubApiRestController {
26 |
27 | @Autowired
28 | private GithubApiRestService service;
29 |
30 | @DeleteMapping(path="/erase")
31 | public ResponseEntity> delete() {
32 | service.deleteAllEvents();
33 | return ResponseEntity.ok().build();
34 | }
35 |
36 | @PostMapping(path="/events")
37 | public ResponseEntity> create(@Valid @RequestBody Event request) {
38 | try {
39 | service.createEvent(request);
40 | } catch(NotFoundException ex) {
41 | return ResponseEntity.status(HttpStatus.BAD_REQUEST)
42 | .build();
43 | }
44 | return ResponseEntity.status(HttpStatus.CREATED).build();
45 | }
46 |
47 | @GetMapping(path="/events")
48 | public List getEvents() {
49 | return service.getAllEvents();
50 | }
51 |
52 | @GetMapping(path="/events/actors/{actorId}")
53 | public ResponseEntity> getActorEvents(
54 | @PathVariable Long actorId) {
55 |
56 | try {
57 | return ResponseEntity.ok(service.getEventsFromActor(actorId));
58 | } catch(NotFoundException ex) {
59 | return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
60 | }
61 | }
62 |
63 | @PutMapping(path="/actors")
64 | public ResponseEntity> update(@Valid @RequestBody Actor actor) {
65 | try {
66 | service.updateActorAvatar(actor);
67 | } catch(NotFoundException ex) {
68 | return ResponseEntity.status(HttpStatus.NOT_FOUND)
69 | .build();
70 | } catch(BadRequestException ex) {
71 | return ResponseEntity.status(HttpStatus.BAD_REQUEST)
72 | .build();
73 | }
74 | return ResponseEntity.ok().build();
75 | }
76 |
77 | @GetMapping(path="/actors")
78 | public ResponseEntity> getActors() {
79 | return ResponseEntity.ok(service.getAllActors());
80 | }
81 |
82 | @GetMapping(path="/actors/streak")
83 | public ResponseEntity> getStreak() {
84 | return ResponseEntity.ok(service.getActorsByMaximumStreak());
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/exception/BadRequestException.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.exception;
2 |
3 | public class BadRequestException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = 1574119354950745139L;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/exception/NotFoundException.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.exception;
2 |
3 | public class NotFoundException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = -7542620691720842689L;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/model/Actor.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.model;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.Id;
5 |
6 | import com.fasterxml.jackson.annotation.JsonProperty;
7 |
8 | @Entity
9 | public class Actor implements Comparable {
10 |
11 | @Id
12 | private Long id;
13 |
14 | private String login;
15 |
16 | @JsonProperty(value="avatar_url")
17 | private String avatarUrl;
18 |
19 | public Actor() {
20 | }
21 |
22 | public Actor(Long id, String login, String avatarUrl) {
23 | this.id = id;
24 | this.login = login;
25 | this.avatarUrl = avatarUrl;
26 | }
27 |
28 | public Long getId() {
29 | return id;
30 | }
31 |
32 | public void setId(Long id) {
33 | this.id = id;
34 | }
35 |
36 | public String getLogin() {
37 | return login;
38 | }
39 |
40 | public void setLogin(String login) {
41 | this.login = login;
42 | }
43 |
44 | public String getAvatarUrl() {
45 | return avatarUrl;
46 | }
47 |
48 | public void setAvatarUrl(String avatarUrl) {
49 | this.avatarUrl = avatarUrl;
50 | }
51 |
52 | @Override
53 | public int compareTo(Actor o) {
54 | return this.login.compareTo(o.login);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/model/Event.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.model;
2 |
3 | import java.sql.Timestamp;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.Id;
7 | import javax.persistence.OneToOne;
8 |
9 | import com.fasterxml.jackson.annotation.JsonFormat;
10 | import com.fasterxml.jackson.annotation.JsonProperty;
11 |
12 | @Entity
13 | public class Event {
14 |
15 | @Id
16 | private Long id;
17 |
18 | private String type;
19 |
20 | @OneToOne
21 | private Actor actor;
22 |
23 | @OneToOne
24 | private Repo repo;
25 |
26 | @JsonProperty(value="created_at")
27 | @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
28 | private Timestamp createdAt;
29 |
30 | public Event() {
31 | }
32 |
33 | public Event(Long id, String type, Actor actor, Repo repo, Timestamp createdAt) {
34 | this.id = id;
35 | this.type = type;
36 | this.actor = actor;
37 | this.repo = repo;
38 | this.createdAt = createdAt;
39 | }
40 |
41 | public Long getId() {
42 | return id;
43 | }
44 |
45 | public void setId(Long id) {
46 | this.id = id;
47 | }
48 |
49 | public String getType() {
50 | return type;
51 | }
52 |
53 | public void setType(String type) {
54 | this.type = type;
55 | }
56 |
57 | public Actor getActor() {
58 | return actor;
59 | }
60 |
61 | public void setActor(Actor actor) {
62 | this.actor = actor;
63 | }
64 |
65 | public Repo getRepo() {
66 | return repo;
67 | }
68 |
69 | public void setRepo(Repo repo) {
70 | this.repo = repo;
71 | }
72 |
73 | public Timestamp getCreatedAt() {
74 | return createdAt;
75 | }
76 |
77 | public void setCreatedAt(Timestamp createdAt) {
78 | this.createdAt = createdAt;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/model/Repo.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.model;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.Id;
5 |
6 | @Entity
7 | public class Repo {
8 | @Id
9 | private Long id;
10 | private String name;
11 | private String url;
12 |
13 | public Repo() {
14 | }
15 |
16 | public Repo(Long id, String name, String url) {
17 | this.id = id;
18 | this.name = name;
19 | this.url = url;
20 | }
21 |
22 | public Long getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Long id) {
27 | this.id = id;
28 | }
29 |
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | public void setName(String name) {
35 | this.name = name;
36 | }
37 |
38 | public String getUrl() {
39 | return url;
40 | }
41 |
42 | public void setUrl(String url) {
43 | this.url = url;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/repository/ActorRepository.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 | import org.springframework.data.jpa.repository.Query;
7 |
8 | import com.hackerrank.github.model.Actor;
9 |
10 | public interface ActorRepository extends JpaRepository {
11 |
12 | @Query(value="SELECT e.actor "
13 | + " FROM Event e "
14 | + " GROUP BY e.actor "
15 | + " ORDER BY COUNT(e) desc, MAX(e.createdAt) DESC, e.actor.login ASC")
16 | List findAllByQtEvents();
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/repository/EventRepository.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.repository;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.jpa.repository.JpaRepository;
6 | import org.springframework.data.jpa.repository.Query;
7 |
8 | import com.hackerrank.github.model.Event;
9 |
10 | public interface EventRepository extends JpaRepository {
11 |
12 | List findAllByActorIdOrderByIdAsc(Long actorId);
13 |
14 | @Query(value="SELECT e "
15 | + " FROM Event e "
16 | + " GROUP BY e "
17 | + " ORDER BY MAX(e.createdAt) DESC, e.actor.login ASC")
18 | List findAllByStreak();
19 |
20 | List findAllByOrderByActorIdAscCreatedAtDesc();
21 |
22 | List findAllByOrderByCreatedAtDesc();
23 | }
24 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/repository/RepoRepository.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.repository;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.hackerrank.github.model.Repo;
6 |
7 | public interface RepoRepository extends JpaRepository {
8 | }
9 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/service/GithubApiRestServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.service;
2 |
3 | import java.util.Arrays;
4 | import java.util.LinkedHashMap;
5 | import java.util.LinkedList;
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Map.Entry;
9 |
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.data.domain.Sort;
12 | import org.springframework.stereotype.Service;
13 |
14 | import com.hackerrank.github.exception.BadRequestException;
15 | import com.hackerrank.github.exception.NotFoundException;
16 | import com.hackerrank.github.model.Actor;
17 | import com.hackerrank.github.model.Event;
18 | import com.hackerrank.github.repository.ActorRepository;
19 | import com.hackerrank.github.repository.EventRepository;
20 | import com.hackerrank.github.repository.RepoRepository;
21 | import com.hackerrank.github.service.interfaces.GithubApiRestService;
22 | import com.hackerrank.github.util.MapUtil;
23 |
24 | @Service
25 | public class GithubApiRestServiceImpl implements GithubApiRestService {
26 |
27 | @Autowired
28 | private EventRepository eventRepo;
29 | @Autowired
30 | private ActorRepository actorRepo;
31 | @Autowired
32 | private RepoRepository repoRepo;
33 |
34 | @Override
35 | public void deleteAllEvents() {
36 | eventRepo.deleteAll();
37 | }
38 |
39 | @Override
40 | public void createEvent(Event event) throws NotFoundException {
41 | if(eventRepo.exists(event.getId())) {
42 | throw new NotFoundException();
43 | }
44 |
45 | actorRepo.save(event.getActor());
46 | repoRepo.save(event.getRepo());
47 | eventRepo.save(event);
48 | }
49 |
50 | @Override
51 | public List getAllEvents() {
52 | return eventRepo.findAll(new Sort(Sort.Direction.ASC, "id"));
53 | }
54 |
55 | @Override
56 | public List getEventsFromActor(Long actorId) {
57 | if(!actorRepo.exists(actorId)) {
58 | throw new NotFoundException();
59 | }
60 |
61 | return eventRepo.findAllByActorIdOrderByIdAsc(actorId);
62 | }
63 |
64 | @Override
65 | public void updateActorAvatar(Actor actor) {
66 | Actor original = actorRepo.findOne(actor.getId());
67 | if(original == null) {
68 | throw new NotFoundException();
69 | }
70 |
71 | if(!original.getLogin().equals(actor.getLogin())) {
72 | throw new BadRequestException();
73 | }
74 |
75 | actorRepo.save(actor);
76 | }
77 |
78 | @Override
79 | public List getAllActors() {
80 | return actorRepo.findAllByQtEvents();
81 | }
82 |
83 | @Override
84 | public List getActorsByMaximumStreak() {
85 | List events = eventRepo.findAllByStreak();
86 | Map maxStreakActor = getMaxStreakByActor(events);
87 |
88 | List actors = Arrays.asList(maxStreakActor.keySet()
89 | .toArray(new Actor[maxStreakActor.keySet().size()]));
90 |
91 | return actors;
92 | }
93 |
94 | private Map getMaxStreakByActor(List events) {
95 | Map> mapActorEvents = getEventsByActor(events);
96 |
97 | Map actorMaxStreak = new LinkedHashMap<>();
98 | for(Entry> entry: mapActorEvents.entrySet()) {
99 | Actor key = entry.getKey();
100 | actorMaxStreak.put(key, 0);
101 | Integer actorCurrentStreak = 0;
102 |
103 | Event currentEvent;
104 | Event previousEvent = null;
105 | for(Event e: entry.getValue()) {
106 | currentEvent = e;
107 |
108 | if(isConsecutive(previousEvent, currentEvent)) {
109 | Integer streakActor = actorCurrentStreak;
110 | streakActor = streakActor + 1;
111 | actorCurrentStreak = streakActor;
112 | } else {
113 | if(actorCurrentStreak > actorMaxStreak.get(key)) {
114 | actorMaxStreak.put(key, actorCurrentStreak);
115 | }
116 | actorCurrentStreak = 1;
117 | }
118 |
119 | previousEvent = currentEvent;
120 | }
121 | if(actorCurrentStreak > actorMaxStreak.get(key)) {
122 | actorMaxStreak.put(key, actorCurrentStreak);
123 | }
124 | }
125 | return MapUtil.sortReverseByValue(actorMaxStreak);
126 | }
127 |
128 | private Map> getEventsByActor(List events) {
129 | Map> mapActorEvents = new LinkedHashMap<>();
130 | for(Event e: events) {
131 | List evs;
132 | if(mapActorEvents.containsKey(e.getActor())) {
133 | evs = mapActorEvents.get(e.getActor());
134 | evs.add(e);
135 | } else {
136 | evs = new LinkedList<>();
137 | evs.add(e);
138 | mapActorEvents.put(e.getActor(), evs);
139 | }
140 | }
141 | return mapActorEvents;
142 | }
143 |
144 | private boolean isConsecutive(Event previous, Event current) {
145 | if(previous == null) {
146 | return true;
147 | }
148 |
149 | return previous.getCreatedAt().toLocalDateTime().toLocalDate().minusDays(1)
150 | .equals(current.getCreatedAt().toLocalDateTime().toLocalDate());
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/service/interfaces/GithubApiRestService.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.service.interfaces;
2 |
3 | import java.util.List;
4 |
5 | import com.hackerrank.github.exception.NotFoundException;
6 | import com.hackerrank.github.model.Actor;
7 | import com.hackerrank.github.model.Event;
8 |
9 | public interface GithubApiRestService {
10 |
11 | void deleteAllEvents();
12 |
13 | void createEvent(Event event) throws NotFoundException;
14 |
15 | List getAllEvents();
16 |
17 | List getEventsFromActor(Long actorId);
18 |
19 | void updateActorAvatar(Actor actor);
20 |
21 | List getAllActors();
22 |
23 | List getActorsByMaximumStreak();
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/java/com/hackerrank/github/util/MapUtil.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github.util;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.Comparator;
6 | import java.util.LinkedHashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Map.Entry;
10 |
11 | public class MapUtil {
12 | public static , V extends Comparable super V>> Map sortReverseByValue(Map map) {
13 | List> list = new ArrayList<>(map.entrySet());
14 | list.sort((Comparator> & Serializable)
15 | (c1, c2) -> c2.getValue().compareTo(c1.getValue()));
16 |
17 | Map result = new LinkedHashMap<>();
18 | for (Entry entry : list) {
19 | result.put(entry.getKey(), entry.getValue());
20 | }
21 |
22 | return result;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.address=0.0.0.0
2 | server.port=8000
--------------------------------------------------------------------------------
/events-dataset-api-java/src/test/java/com/hackerrank/github/HttpJsonDynamicUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hackerrank.github;
2 |
3 | import com.fasterxml.jackson.core.type.TypeReference;
4 | import com.fasterxml.jackson.databind.JsonNode;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import java.io.BufferedReader;
7 | import java.io.BufferedWriter;
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.InputStreamReader;
12 | import java.nio.charset.StandardCharsets;
13 | import java.nio.file.Files;
14 | import java.nio.file.Paths;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 | import java.util.Set;
20 | import java.util.concurrent.TimeUnit;
21 | import java.util.concurrent.atomic.AtomicInteger;
22 | import static java.util.stream.Collectors.toList;
23 | import java.util.stream.Stream;
24 | import javafx.util.Pair;
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertNotNull;
27 | import org.junit.Before;
28 | import org.junit.Rule;
29 | import org.junit.Test;
30 | import org.junit.rules.Stopwatch;
31 | import org.junit.rules.TestWatcher;
32 | import org.junit.runner.Description;
33 | import org.junit.runner.RunWith;
34 | import org.junit.runners.model.Statement;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.boot.test.context.SpringBootTest;
37 | import org.springframework.core.io.ClassPathResource;
38 | import org.springframework.http.MediaType;
39 | import org.springframework.http.converter.HttpMessageConverter;
40 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
41 | import org.springframework.mock.web.MockHttpServletResponse;
42 | import org.springframework.test.context.junit4.SpringRunner;
43 | import org.springframework.test.context.web.WebAppConfiguration;
44 | import org.springframework.test.web.servlet.MockMvc;
45 | import org.springframework.test.web.servlet.ResultActions;
46 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
47 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
48 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
49 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
50 | import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
51 | import org.springframework.web.context.WebApplicationContext;
52 |
53 | /**
54 | *
55 | * @author abhimanyusingh
56 | */
57 | @RunWith(SpringRunner.class)
58 | @SpringBootTest(classes = Application.class)
59 | @WebAppConfiguration
60 | public class HttpJsonDynamicUnitTest {
61 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
62 |
63 | private static final MediaType CONTENT_TYPE_JSON = MediaType.APPLICATION_JSON_UTF8;
64 | private static final MediaType CONTENT_TYPE_TEXT = MediaType.TEXT_PLAIN;
65 |
66 | private static HttpMessageConverter mappingJackson2HttpMessageConverter;
67 |
68 | @Autowired
69 | private WebApplicationContext webApplicationContext;
70 | private MockMvc mockMvc;
71 |
72 | @Before
73 | public void getContext() {
74 | mockMvc = webAppContextSetup(webApplicationContext).build();
75 | assertNotNull(mockMvc);
76 | }
77 |
78 | @Autowired
79 | public void setConverters(HttpMessageConverter>[] converters) {
80 | mappingJackson2HttpMessageConverter = Stream.of(converters)
81 | .filter(hmc -> hmc instanceof MappingJackson2HttpMessageConverter)
82 | .findAny()
83 | .orElse(null);
84 |
85 | assertNotNull(mappingJackson2HttpMessageConverter);
86 | }
87 |
88 | List httpJsonFiles = new ArrayList<>();
89 | Map httpJsonAndTestname = new HashMap<>();
90 | Map executionTime = new HashMap<>();
91 | Map, Pair>> testFailures = new HashMap<>();
92 |
93 | @Rule
94 | public Stopwatch stopwatch = new Stopwatch() {};
95 |
96 | @Rule
97 | public TestWatcher watchman = new TestWatcher() {
98 | @Override
99 | public Statement apply(Statement base, Description description) {
100 | return super.apply(base, description);
101 | }
102 |
103 | @Override
104 | protected void starting(Description description) {
105 | super.starting(description);
106 | }
107 |
108 | @Override
109 | protected void succeeded(Description description) {
110 | generateReportForProperExecution();
111 | }
112 |
113 | @Override
114 | protected void failed(Throwable e, Description description) {
115 | generateReportForRuntimeFailureExecution();
116 | }
117 |
118 | @Override
119 | protected void finished(Description description) {
120 | super.finished(description);
121 | }
122 | };
123 |
124 | @Test
125 | public void dynamicTests() {
126 | try {
127 | httpJsonFiles = Files.list(Paths.get("src/test/resources/testcases"))
128 | .filter(Files::isRegularFile)
129 | .map(f -> f.getFileName().toString())
130 | .filter(f -> f.endsWith(".json"))
131 | .collect(toList());
132 | } catch (IOException ex) {
133 | throw new Error(ex.toString());
134 | }
135 |
136 | if (!httpJsonFiles.isEmpty()) {
137 | List testnames = new ArrayList<>();
138 |
139 | ClassPathResource resource = new ClassPathResource("testcases/description.txt");
140 | try (InputStream inputStream = resource.getInputStream()) {
141 | testnames = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
142 | .lines()
143 | .collect(toList());
144 | } catch (IOException ex) {
145 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
146 | .map(trace -> trace.toString())
147 | .collect(toList())));
148 |
149 | throw new Error(ex.toString());
150 | }
151 |
152 | if (!testnames.isEmpty()) {
153 | assertEquals(httpJsonFiles.size(), testnames.size());
154 |
155 | for (int i = 0; i < testnames.size(); i++) {
156 | String[] testname = testnames.get(i).split(": ");
157 | httpJsonAndTestname.put(testname[0], testname[1]);
158 | }
159 |
160 | AtomicInteger processedRequestCount = new AtomicInteger(1);
161 |
162 | httpJsonFiles.forEach(filename -> {
163 | if (testFailures.containsKey(filename)) {
164 | return;
165 | }
166 |
167 | final List jsonStrings = new ArrayList<>();
168 |
169 | ClassPathResource jsonResource = new ClassPathResource("testcases/" + filename);
170 | try (InputStream inputStream = jsonResource.getInputStream()) {
171 | new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
172 | .lines()
173 | .collect(toList())
174 | .forEach(jsonString -> jsonStrings.add(jsonString));
175 | } catch (IOException ex) {
176 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
177 | .map(trace -> trace.toString())
178 | .collect(toList())));
179 |
180 | throw new Error(ex.toString());
181 | }
182 |
183 | if (!jsonStrings.isEmpty()) {
184 | jsonStrings.forEach(jsonString -> {
185 | if (testFailures.containsKey(filename)) {
186 | return;
187 | }
188 |
189 | try {
190 | JsonNode jsonObject = OBJECT_MAPPER.readTree(jsonString);
191 |
192 | JsonNode request = jsonObject.get("request");
193 | JsonNode response = jsonObject.get("response");
194 |
195 | String method = request.get("method").asText();
196 | String url = request.get("url").asText();
197 | String body = request.get("body").toString();
198 | String statusCode = response.get("status_code").asText();
199 |
200 | String requestID = Colors.BLUE_BOLD + String.format("Processing request %d ",
201 | processedRequestCount.get()) + Colors.RESET;
202 | String requestMessage = String.format("%s %s", method, url);
203 |
204 | if (method.charAt(0) == 'P') {
205 | requestMessage = String.format("%s %s %s", method, url, body);
206 | }
207 |
208 | System.out.println(requestID + Colors.WHITE_BOLD + requestMessage + Colors.RESET);
209 |
210 | processedRequestCount.set(processedRequestCount.incrementAndGet());
211 |
212 | switch (method) {
213 | case "POST":
214 | {
215 | MediaType contentType = MediaType.ALL;
216 | String type = request.get("headers").get("Content-Type").asText();
217 |
218 | if (type.equals("application/json")) {
219 | contentType = CONTENT_TYPE_JSON;
220 | } else if (type.equals("text/plain")) {
221 | contentType = CONTENT_TYPE_TEXT;
222 | }
223 |
224 | if (!contentType.equals(MediaType.ALL)) {
225 | try {
226 | ResultActions resultActions = mockMvc.perform(post(url)
227 | .content(body)
228 | .contentType(CONTENT_TYPE_JSON));
229 | MockHttpServletResponse mockResponse = resultActions.andReturn()
230 | .getResponse();
231 |
232 | validateStatusCode(filename, method + " " + url,
233 | statusCode, String.valueOf(mockResponse.getStatus()));
234 | } catch (Exception ex) {
235 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
236 | .map(trace -> trace.toString())
237 | .collect(toList())));
238 |
239 | throw new Error(ex.toString());
240 | }
241 | }
242 |
243 | break;
244 | }
245 | case "PUT":
246 | {
247 | MediaType contentType = MediaType.ALL;
248 | String type = request.get("headers").get("Content-Type").asText();
249 |
250 | if (type.equals("application/json")) {
251 | contentType = CONTENT_TYPE_JSON;
252 | } else if (type.equals("text/plain")) {
253 | contentType = CONTENT_TYPE_TEXT;
254 | }
255 |
256 | if (!contentType.equals(MediaType.ALL)) {
257 | try {
258 | ResultActions resultActions = mockMvc.perform(put(url)
259 | .content(body)
260 | .contentType(CONTENT_TYPE_JSON));
261 | MockHttpServletResponse mockResponse = resultActions.andReturn()
262 | .getResponse();
263 |
264 | validateStatusCode(filename, method + " " + url,
265 | statusCode, String.valueOf(mockResponse.getStatus()));
266 | } catch (Exception ex) {
267 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
268 | .map(trace -> trace.toString())
269 | .collect(toList())));
270 |
271 | throw new Error(ex.toString());
272 | }
273 | }
274 |
275 | break;
276 | }
277 | case "DELETE":
278 | try {
279 | ResultActions resultActions = mockMvc.perform(delete(url));
280 | MockHttpServletResponse mockResponse = resultActions.andReturn()
281 | .getResponse();
282 |
283 | validateStatusCode(filename, method + " " + url,
284 | statusCode, String.valueOf(mockResponse.getStatus()));
285 | } catch (Exception ex) {
286 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
287 | .map(trace -> trace.toString())
288 | .collect(toList())));
289 |
290 | throw new Error(ex.toString());
291 | }
292 |
293 | break;
294 | case "GET":
295 | try {
296 | ResultActions resultActions = mockMvc.perform(get(url));
297 | MockHttpServletResponse mockResponse = resultActions.andReturn()
298 | .getResponse();
299 |
300 | if (validateStatusCode(filename, method + " " + url,
301 | statusCode, String.valueOf(mockResponse.getStatus()))) {
302 | JsonNode expectedType = response.get("headers").get("Content-Type");
303 | if (expectedType != null) {
304 | if (mockResponse.containsHeader("content-type")) {
305 | validateContentType(filename, method + " " + url,
306 | expectedType.asText(), mockResponse.getContentType());
307 | }
308 |
309 | if (statusCode.equals("200")) {
310 | String responseBody = mockResponse.getContentAsString();
311 | JsonNode expectedResponseBodyJson = response.get("body");
312 |
313 | if (expectedType.asText().equals("application/json")) {
314 | JsonNode responseBodyJson = OBJECT_MAPPER.readTree(responseBody);
315 |
316 | validateJsonResponse(filename, method + " " + url,
317 | expectedResponseBodyJson, responseBodyJson);
318 | } else if (expectedType.asText().equals("text/plain")) {
319 | validateTextResponse(filename, method + " " + url,
320 | expectedResponseBodyJson.toString(), responseBody);
321 | }
322 | }
323 | }
324 | }
325 | } catch (Exception ex) {
326 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
327 | .map(trace -> trace.toString())
328 | .collect(toList())));
329 |
330 | throw new Error(ex.toString());
331 | }
332 |
333 | break;
334 | default:
335 | break;
336 | }
337 | } catch (IOException ex) {
338 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
339 | .map(trace -> trace.toString())
340 | .collect(toList())));
341 |
342 | throw new Error(ex.toString());
343 | }
344 | });
345 | }
346 |
347 | executionTime.put(filename, stopwatch.runtime(TimeUnit.MILLISECONDS));
348 | });
349 | }
350 | }
351 | }
352 |
353 | private boolean validateStatusCode(String filename, String testcase, String expected, String found) {
354 | if (!expected.equals(found)) {
355 | String reason = "Status code";
356 | addTestFailure(filename, new Pair(new Pair(testcase, reason), new Pair(expected, found)));
357 |
358 | return false;
359 | }
360 |
361 | return true;
362 | }
363 |
364 | private boolean validateContentType(String filename, String testcase, String expected, String found) {
365 | if (!found.startsWith(expected)) {
366 | String reason = "Content type";
367 | addTestFailure(filename, new Pair(new Pair(testcase, reason), new Pair(expected, found)));
368 |
369 | return false;
370 | }
371 |
372 | return true;
373 | }
374 |
375 | private boolean validateTextResponse(String filename, String testcase, String expected, String found) {
376 | if (!expected.equals(found)) {
377 | String reason = "Response text does not match with the expected response";
378 | addTestFailure(filename, new Pair(new Pair(testcase, reason), new Pair(expected, found)));
379 |
380 | return false;
381 | }
382 |
383 | return true;
384 | }
385 |
386 | private boolean validateJsonResponse(String filename, String testcase, JsonNode expected, JsonNode found) {
387 | try {
388 | List expectedResponseJsonList = OBJECT_MAPPER.readValue(expected.toString(),
389 | new TypeReference>(){});
390 |
391 | List responseBodyJsonList = OBJECT_MAPPER.readValue(found.toString(),
392 | new TypeReference>(){});
393 |
394 | if (expectedResponseJsonList.size() != responseBodyJsonList.size()) {
395 | String reason = "Response Json array size does not match with the expected array size";
396 | addTestFailure(filename, new Pair(new Pair(testcase, reason),
397 | new Pair(String.valueOf(expectedResponseJsonList.size()),
398 | String.valueOf(responseBodyJsonList.size()))));
399 |
400 | return false;
401 | } else {
402 | for (int i = 0; i < expectedResponseJsonList.size(); i++) {
403 | JsonNode expectedJson = expectedResponseJsonList.get(i);
404 | JsonNode foundJson = responseBodyJsonList.get(i);
405 |
406 | if (!expectedJson.equals(foundJson)) {
407 | String reason = String.format("Response Json (at index %d) does not match with the expected Json", i);
408 | addTestFailure(filename, new Pair(new Pair(testcase, reason), new Pair(expectedJson.toString(),
409 | foundJson.toString())));
410 |
411 | return false;
412 | }
413 | }
414 | }
415 | } catch (IOException ex) {
416 | if (!expected.equals(found)) {
417 | String reason = "Response Json does not match with the expected Json";
418 | addTestFailure(filename, new Pair(new Pair(testcase, reason), new Pair(expected.toString(),
419 | found.toString())));
420 |
421 | return false;
422 | }
423 | }
424 |
425 | return true;
426 | }
427 |
428 | private void addTestFailure(String filename, Pair, Pair> failure) {
429 | if (testFailures.containsKey(filename)) {
430 | throw new Error("I should skip rest of the test cases.");
431 | }
432 |
433 | testFailures.put(filename, failure);
434 | }
435 |
436 | private void generateReportForProperExecution() {
437 | List executionTimeInSeconds = executionTime.keySet()
438 | .stream()
439 | .sorted()
440 | .map(filename -> executionTime.get(filename))
441 | .collect(toList());
442 |
443 | for (int i = 1; i < executionTimeInSeconds.size(); i++) {
444 | executionTime.put(httpJsonFiles.get(i),
445 | (executionTimeInSeconds.get(i) < executionTimeInSeconds.get(i - 1))
446 | ? 0
447 | : executionTimeInSeconds.get(i) - executionTimeInSeconds.get(i - 1));
448 | }
449 |
450 | final Set failedTestFiles = testFailures.keySet();
451 |
452 | final String DASHES = "------------------------------------------------------------------------";
453 | final String ANSI_SUMMARY = DASHES + "\n" + Colors.BLUE_BOLD + "TEST SUMMARY\n" + Colors.RESET + DASHES;
454 | final String ANSI_RESULT = DASHES + "\n" + Colors.BLUE_BOLD + "TEST RESULT\n" + Colors.RESET + DASHES;
455 | final String ANSI_REPORT = DASHES + "\n" + Colors.BLUE_BOLD + "FAILURE REPORT %s\n" + Colors.RESET + DASHES;
456 | final String ANSI_FAILURE = Colors.RED_BOLD + "Failure" + Colors.RESET;
457 | final String ANSI_SUCCESS = Colors.GREEN_BOLD + "Success" + Colors.RESET;
458 |
459 | File reportFolder = new File("target/customReports");
460 | reportFolder.mkdir();
461 |
462 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("target/customReports/result.txt"))) {
463 | writer.write(Colors.WHITE_BOLD +
464 | " _ _ _ _ _______ _ _____ _ \n" +
465 | "| | | | (_) | |__ __| | | | __ \\ | | \n" +
466 | "| | | |_ __ _| |_ | | ___ ___| |_ | |__) |___ _ __ ___ _ __| |_ \n" +
467 | "| | | | '_ \\| | __| | |/ _ \\/ __| __| | _ // _ \\ '_ \\ / _ \\| '__| __|\n" +
468 | "| |__| | | | | | |_ | | __/\\__ \\ |_ | | \\ \\ __/ |_) | (_) | | | |_ \n" +
469 | " \\____/|_| |_|_|\\__| |_|\\___||___/\\__| |_| \\_\\___| .__/ \\___/|_| \\__|\n" +
470 | " | | \n" +
471 | " |_| " +
472 | Colors.RESET);
473 | writer.newLine();
474 |
475 | writer.write(ANSI_SUMMARY);
476 | writer.newLine();
477 | writer.write("Tests: " + httpJsonFiles.size());
478 | writer.write(", ");
479 | writer.write("Success: " + (httpJsonFiles.size() - failedTestFiles.size()));
480 | writer.write(", ");
481 |
482 | if (!failedTestFiles.isEmpty()) {
483 | writer.write("Failure: " + failedTestFiles.size());
484 | writer.write(", ");
485 | }
486 |
487 | writer.write("Total time: " + executionTimeInSeconds.get(executionTimeInSeconds.size() - 1) / 1000.0f + "s");
488 | writer.newLine();
489 | writer.newLine();
490 |
491 | writer.write(ANSI_RESULT);
492 | writer.newLine();
493 |
494 | httpJsonFiles.forEach(filename -> {
495 | if (failedTestFiles.contains(filename)) {
496 | try {
497 | writer.write(Colors.WHITE_BOLD + filename +": " + Colors.RESET +
498 | ANSI_FAILURE + " (" + executionTime.get(filename) / 1000.0f + "s)");
499 | writer.newLine();
500 | } catch (IOException ex) {
501 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
502 | .map(trace -> trace.toString())
503 | .collect(toList())));
504 |
505 | throw new Error(ex.toString());
506 | }
507 | } else {
508 | try {
509 | writer.write(Colors.WHITE_BOLD + filename +": " + Colors.RESET +
510 | ANSI_SUCCESS + " (" + executionTime.get(filename) / 1000.0f + "s)");
511 | writer.newLine();
512 | } catch (IOException ex) {
513 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
514 | .map(trace -> trace.toString())
515 | .collect(toList())));
516 |
517 | throw new Error(ex.toString());
518 | }
519 | }
520 | });
521 |
522 | writer.newLine();
523 |
524 | if (!failedTestFiles.isEmpty()) {
525 | failedTestFiles.stream()
526 | .sorted()
527 | .forEachOrdered(filename -> {
528 | Pair, Pair> report = testFailures.get(filename);
529 |
530 | String testcase = report.getKey()
531 | .getKey();
532 | String reason = report.getKey()
533 | .getValue();
534 | String expected = report.getValue()
535 | .getKey();
536 | String found = report.getValue()
537 | .getValue();
538 |
539 | try {
540 | writer.write(String.format(ANSI_REPORT, filename));
541 | writer.newLine();
542 | writer.write(Colors.WHITE_BOLD + "[Test Case]" + Colors.RESET + " " + testcase);
543 | writer.newLine();
544 | writer.write(Colors.WHITE_BOLD + "[ Reason]" + Colors.RESET + " " + Colors.RED_BOLD + reason +
545 | Colors.RESET);
546 | writer.newLine();
547 | writer.write(Colors.WHITE_BOLD + "[ Expected]" + Colors.RESET + " " + expected);
548 | writer.newLine();
549 | writer.write(Colors.WHITE_BOLD + "[ Found]" + Colors.RESET + " " + found);
550 | writer.newLine();
551 | writer.newLine();
552 | } catch (IOException ex) {
553 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
554 | .map(trace -> trace.toString())
555 | .collect(toList())));
556 |
557 | throw new Error(ex.toString());
558 | }
559 | });
560 | }
561 | } catch (IOException ex) {
562 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
563 | .map(trace -> trace.toString())
564 | .collect(toList())));
565 |
566 | throw new Error(ex.toString());
567 | }
568 |
569 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("target/customReports/result.xml"))) {
570 | writer.write("\n");
571 | writer.write(String.format("\n",
572 | this.getClass().getName(),
573 | executionTimeInSeconds.get(executionTimeInSeconds.size() - 1) / 1000.0f,
574 | httpJsonFiles.size(),
575 | failedTestFiles.size()));
576 |
577 | httpJsonFiles.stream()
578 | .sorted()
579 | .forEachOrdered(filename -> {
580 | try {
581 | if (! failedTestFiles.contains(filename)) {
582 | writer.write(String.format(" \n",
583 | httpJsonAndTestname.get(filename),
584 | this.getClass().getName(),
585 | executionTime.get(filename) / 1000.0f));
586 | } else {
587 | writer.write(String.format(" \n"
588 | + " \n \n \n",
589 | httpJsonAndTestname.get(filename),
590 | this.getClass().getName(),
591 | executionTime.get(filename) / 1000.0f));
592 | }
593 | } catch (IOException ex) {
594 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
595 | .map(trace -> trace.toString())
596 | .collect(toList())));
597 |
598 | throw new Error(ex.toString());
599 | }
600 | });
601 |
602 | writer.write("\n");
603 | } catch (IOException ex) {
604 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
605 | .map(trace -> trace.toString())
606 | .collect(toList())));
607 |
608 | throw new Error(ex.toString());
609 | }
610 | }
611 |
612 | private void generateReportForRuntimeFailureExecution() {
613 | final String DASHES = "------------------------------------------------------------------------";
614 | final String ANSI_SUMMARY = DASHES + "\n" + Colors.BLUE_BOLD + "TEST SUMMARY\n" + Colors.RESET + DASHES;
615 | final String ANSI_RESULT = DASHES + "\n" + Colors.BLUE_BOLD + "TEST RESULT\n" + Colors.RESET + DASHES;
616 | final String ANSI_REPORT = DASHES + "\n" + Colors.BLUE_BOLD + "FAILURE REPORT %s\n" + Colors.RESET + DASHES;
617 | final String ANSI_FAILURE = Colors.RED_BOLD + "Failure" + Colors.RESET;
618 | final String ANSI_SUCCESS = Colors.GREEN_BOLD + "Success" + Colors.RESET;
619 |
620 | File reportFolder = new File("target/customReports");
621 | reportFolder.mkdir();
622 |
623 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("target/customReports/result.txt"))) {
624 | writer.write(Colors.WHITE_BOLD +
625 | " _ _ _ _ _______ _ _____ _ \n" +
626 | "| | | | (_) | |__ __| | | | __ \\ | | \n" +
627 | "| | | |_ __ _| |_ | | ___ ___| |_ | |__) |___ _ __ ___ _ __| |_ \n" +
628 | "| | | | '_ \\| | __| | |/ _ \\/ __| __| | _ // _ \\ '_ \\ / _ \\| '__| __|\n" +
629 | "| |__| | | | | | |_ | | __/\\__ \\ |_ | | \\ \\ __/ |_) | (_) | | | |_ \n" +
630 | " \\____/|_| |_|_|\\__| |_|\\___||___/\\__| |_| \\_\\___| .__/ \\___/|_| \\__|\n" +
631 | " | | \n" +
632 | " |_| " +
633 | Colors.RESET);
634 | writer.newLine();
635 |
636 | writer.write(ANSI_SUMMARY);
637 | writer.newLine();
638 | writer.write("Tests: " + httpJsonFiles.size());
639 | writer.write(", ");
640 | writer.write("Success: 0");
641 | writer.write(", ");
642 | writer.write("Failure: " + httpJsonFiles.size());
643 | writer.write(", ");
644 | writer.write("Total time: 0s");
645 | writer.newLine();
646 | writer.newLine();
647 |
648 | writer.write(ANSI_RESULT);
649 | writer.newLine();
650 |
651 | httpJsonFiles.forEach(filename -> {
652 | try {
653 | writer.write(Colors.WHITE_BOLD + filename +": " + Colors.RESET +
654 | ANSI_FAILURE + " (0s)");
655 | writer.newLine();
656 | } catch (IOException ex) {
657 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
658 | .map(trace -> trace.toString())
659 | .collect(toList())));
660 |
661 | throw new Error(ex.toString());
662 | }
663 | });
664 | } catch (IOException ex) {
665 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
666 | .map(trace -> trace.toString())
667 | .collect(toList())));
668 |
669 | throw new Error(ex.toString());
670 | }
671 |
672 | try (BufferedWriter writer = Files.newBufferedWriter(Paths.get("target/customReports/result.xml"))) {
673 | writer.write("\n");
674 | writer.write(String.format("\n",
675 | this.getClass().getName(),
676 | 0.0f,
677 | httpJsonFiles.size(),
678 | httpJsonFiles.size()));
679 |
680 | httpJsonFiles.stream()
681 | .sorted()
682 | .forEachOrdered(filename -> {
683 | try {
684 | writer.write(String.format(" \n"
685 | + " \n \n \n",
686 | httpJsonAndTestname.get(filename),
687 | this.getClass().getName(),
688 | 0.0f));
689 | } catch (IOException ex) {
690 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
691 | .map(trace -> trace.toString())
692 | .collect(toList())));
693 |
694 | throw new Error(ex.toString());
695 | }
696 | });
697 |
698 | writer.write("\n");
699 | } catch (IOException ex) {
700 | System.out.println(String.join("\n", Stream.of(ex.getStackTrace())
701 | .map(trace -> trace.toString())
702 | .collect(toList())));
703 |
704 | throw new Error(ex.toString());
705 | }
706 | }
707 |
708 | private static class Colors {
709 | public static final String RESET = "\033[0m";
710 |
711 | public static final String BLACK = "\033[0;30m";
712 | public static final String RED = "\033[0;31m";
713 | public static final String GREEN = "\033[0;32m";
714 | public static final String YELLOW = "\033[0;33m";
715 | public static final String BLUE = "\033[0;34m";
716 | public static final String WHITE = "\033[0;37m";
717 |
718 | public static final String BLACK_BOLD = "\033[1;30m";
719 | public static final String RED_BOLD = "\033[1;31m";
720 | public static final String GREEN_BOLD = "\033[1;32m";
721 | public static final String YELLOW_BOLD = "\033[1;33m";
722 | public static final String BLUE_BOLD = "\033[1;34m";
723 | public static final String WHITE_BOLD = "\033[1;37m";
724 | }
725 | }
726 |
--------------------------------------------------------------------------------
/events-dataset-api-java/src/test/resources/testcases/description.txt:
--------------------------------------------------------------------------------
1 | http00.json: Sample Test
2 | http01.json: Additional Test 1
3 | http02.json: Additional Test 2
4 | http03.json: Additional Test 3
5 | http04.json: Additional Test 4
6 | http05.json: Additional Test 5
--------------------------------------------------------------------------------
/events-dataset-api-java/src/test/resources/testcases/http00.json:
--------------------------------------------------------------------------------
1 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4055191679, "type": "PushEvent", "actor": {"id": 2790311, "login": "daniel33", "avatar_url": "https://avatars.com/2790311"}, "repo": {"id": 352806, "name": "johnbolton/exercitationem", "url": "https://github.com/johnbolton/exercitationem"}, "created_at": "2015-10-03 06:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
2 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2712153979, "type": "PushEvent", "actor": {"id": 2907782, "login": "eric66", "avatar_url": "https://avatars.com/2907782"}, "repo": {"id": 426482, "name": "pestrada/voluptatem", "url": "https://github.com/pestrada/voluptatem"}, "created_at": "2014-07-13 08:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
3 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4633249595, "type": "PushEvent", "actor": {"id": 4276597, "login": "iholloway", "avatar_url": "https://avatars.com/4276597"}, "repo": {"id": 269910, "name": "iholloway/aperiam-consectetur", "url": "https://github.com/iholloway/aperiam-consectetur"}, "created_at": "2016-04-18 00:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
4 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1514531484, "type": "PushEvent", "actor": {"id": 3698252, "login": "daniel51", "avatar_url": "https://avatars.com/3698252"}, "repo": {"id": 451024, "name": "daniel51/quo-tempore-dolor", "url": "https://github.com/daniel51/quo-tempore-dolor"}, "created_at": "2013-06-16 02:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
5 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1838493121, "type": "PushEvent", "actor": {"id": 4864659, "login": "katrinaallen", "avatar_url": "https://avatars.com/4864659"}, "repo": {"id": 275832, "name": "elizabethbailey/error-quod-a", "url": "https://github.com/elizabethbailey/error-quod-a"}, "created_at": "2013-09-28 01:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
6 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1979554031, "type": "PushEvent", "actor": {"id": 3648056, "login": "ysims", "avatar_url": "https://avatars.com/3648056"}, "repo": {"id": 292520, "name": "svazquez/dolores-quidem", "url": "https://github.com/svazquez/dolores-quidem"}, "created_at": "2013-11-11 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
7 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1536363444, "type": "PushEvent", "actor": {"id": 4949434, "login": "millerlarry", "avatar_url": "https://avatars.com/4949434"}, "repo": {"id": 310964, "name": "brownphilip/rerum-quidem", "url": "https://github.com/brownphilip/rerum-quidem"}, "created_at": "2013-06-23 08:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
8 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4501280090, "type": "PushEvent", "actor": {"id": 2917996, "login": "oscarschmidt", "avatar_url": "https://avatars.com/2917996"}, "repo": {"id": 301227, "name": "oscarschmidt/doloremque-expedita", "url": "https://github.com/oscarschmidt/doloremque-expedita"}, "created_at": "2016-03-05 10:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
9 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3822562012, "type": "PushEvent", "actor": {"id": 2222918, "login": "xnguyen", "avatar_url": "https://avatars.com/2222918"}, "repo": {"id": 425512, "name": "cohenjacqueline/quam-autem-suscipit", "url": "https://github.com/cohenjacqueline/quam-autem-suscipit"}, "created_at": "2015-07-15 15:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
10 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1319379787, "type": "PushEvent", "actor": {"id": 3466404, "login": "khunt", "avatar_url": "https://avatars.com/3466404"}, "repo": {"id": 478747, "name": "ngriffin/rerum-aliquam-cum", "url": "https://github.com/ngriffin/rerum-aliquam-cum"}, "created_at": "2013-04-17 04:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
11 | {"request": {"method": "GET", "url": "/events/actors/2222918", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 3822562012, "type": "PushEvent", "actor": {"id": 2222918, "login": "xnguyen", "avatar_url": "https://avatars.com/2222918"}, "repo": {"id": 425512, "name": "cohenjacqueline/quam-autem-suscipit", "url": "https://github.com/cohenjacqueline/quam-autem-suscipit"}, "created_at": "2015-07-15 15:13:31"}], "headers": {"Content-Type": "application/json"}}}
12 | {"request": {"method": "GET", "url": "/actors/streak", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 4276597, "login": "iholloway", "avatar_url": "https://avatars.com/4276597"}, {"id": 2917996, "login": "oscarschmidt", "avatar_url": "https://avatars.com/2917996"}, {"id": 2790311, "login": "daniel33", "avatar_url": "https://avatars.com/2790311"}, {"id": 2222918, "login": "xnguyen", "avatar_url": "https://avatars.com/2222918"}, {"id": 2907782, "login": "eric66", "avatar_url": "https://avatars.com/2907782"}, {"id": 3648056, "login": "ysims", "avatar_url": "https://avatars.com/3648056"}, {"id": 4864659, "login": "katrinaallen", "avatar_url": "https://avatars.com/4864659"}, {"id": 4949434, "login": "millerlarry", "avatar_url": "https://avatars.com/4949434"}, {"id": 3698252, "login": "daniel51", "avatar_url": "https://avatars.com/3698252"}, {"id": 3466404, "login": "khunt", "avatar_url": "https://avatars.com/3466404"}], "headers": {"Content-Type": "application/json"}}}
13 | {"request": {"method": "PUT", "url": "/actors", "headers": {"Content-Type": "application/json"}, "body": {"id": 3648056, "login": "ysims", "avatar_url": "https://avatars.com/modified2"}}, "response": {"status_code": 200, "body": {}, "headers": {}}}
14 | {"request": {"method": "GET", "url": "/events", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 1319379787, "type": "PushEvent", "actor": {"id": 3466404, "login": "khunt", "avatar_url": "https://avatars.com/3466404"}, "repo": {"id": 478747, "name": "ngriffin/rerum-aliquam-cum", "url": "https://github.com/ngriffin/rerum-aliquam-cum"}, "created_at": "2013-04-17 04:13:31"}, {"id": 1514531484, "type": "PushEvent", "actor": {"id": 3698252, "login": "daniel51", "avatar_url": "https://avatars.com/3698252"}, "repo": {"id": 451024, "name": "daniel51/quo-tempore-dolor", "url": "https://github.com/daniel51/quo-tempore-dolor"}, "created_at": "2013-06-16 02:13:31"}, {"id": 1536363444, "type": "PushEvent", "actor": {"id": 4949434, "login": "millerlarry", "avatar_url": "https://avatars.com/4949434"}, "repo": {"id": 310964, "name": "brownphilip/rerum-quidem", "url": "https://github.com/brownphilip/rerum-quidem"}, "created_at": "2013-06-23 08:13:31"}, {"id": 1838493121, "type": "PushEvent", "actor": {"id": 4864659, "login": "katrinaallen", "avatar_url": "https://avatars.com/4864659"}, "repo": {"id": 275832, "name": "elizabethbailey/error-quod-a", "url": "https://github.com/elizabethbailey/error-quod-a"}, "created_at": "2013-09-28 01:13:31"}, {"id": 1979554031, "type": "PushEvent", "actor": {"id": 3648056, "login": "ysims", "avatar_url": "https://avatars.com/modified2"}, "repo": {"id": 292520, "name": "svazquez/dolores-quidem", "url": "https://github.com/svazquez/dolores-quidem"}, "created_at": "2013-11-11 17:13:31"}, {"id": 2712153979, "type": "PushEvent", "actor": {"id": 2907782, "login": "eric66", "avatar_url": "https://avatars.com/2907782"}, "repo": {"id": 426482, "name": "pestrada/voluptatem", "url": "https://github.com/pestrada/voluptatem"}, "created_at": "2014-07-13 08:13:31"}, {"id": 3822562012, "type": "PushEvent", "actor": {"id": 2222918, "login": "xnguyen", "avatar_url": "https://avatars.com/2222918"}, "repo": {"id": 425512, "name": "cohenjacqueline/quam-autem-suscipit", "url": "https://github.com/cohenjacqueline/quam-autem-suscipit"}, "created_at": "2015-07-15 15:13:31"}, {"id": 4055191679, "type": "PushEvent", "actor": {"id": 2790311, "login": "daniel33", "avatar_url": "https://avatars.com/2790311"}, "repo": {"id": 352806, "name": "johnbolton/exercitationem", "url": "https://github.com/johnbolton/exercitationem"}, "created_at": "2015-10-03 06:13:31"}, {"id": 4501280090, "type": "PushEvent", "actor": {"id": 2917996, "login": "oscarschmidt", "avatar_url": "https://avatars.com/2917996"}, "repo": {"id": 301227, "name": "oscarschmidt/doloremque-expedita", "url": "https://github.com/oscarschmidt/doloremque-expedita"}, "created_at": "2016-03-05 10:13:31"}, {"id": 4633249595, "type": "PushEvent", "actor": {"id": 4276597, "login": "iholloway", "avatar_url": "https://avatars.com/4276597"}, "repo": {"id": 269910, "name": "iholloway/aperiam-consectetur", "url": "https://github.com/iholloway/aperiam-consectetur"}, "created_at": "2016-04-18 00:13:31"}], "headers": {"Content-Type": "application/json"}}}
15 | {"request": {"method": "GET", "url": "/actors", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 4276597, "login": "iholloway", "avatar_url": "https://avatars.com/4276597"}, {"id": 2917996, "login": "oscarschmidt", "avatar_url": "https://avatars.com/2917996"}, {"id": 2790311, "login": "daniel33", "avatar_url": "https://avatars.com/2790311"}, {"id": 2222918, "login": "xnguyen", "avatar_url": "https://avatars.com/2222918"}, {"id": 2907782, "login": "eric66", "avatar_url": "https://avatars.com/2907782"}, {"id": 3648056, "login": "ysims", "avatar_url": "https://avatars.com/modified2"}, {"id": 4864659, "login": "katrinaallen", "avatar_url": "https://avatars.com/4864659"}, {"id": 4949434, "login": "millerlarry", "avatar_url": "https://avatars.com/4949434"}, {"id": 3698252, "login": "daniel51", "avatar_url": "https://avatars.com/3698252"}, {"id": 3466404, "login": "khunt", "avatar_url": "https://avatars.com/3466404"}], "headers": {"Content-Type": "application/json"}}}
16 | {"request": {"method": "DELETE", "url": "/erase", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": {}, "headers": {}}}
17 | {"request": {"method": "GET", "url": "/events", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [], "headers": {"Content-Type": "application/json"}}}
--------------------------------------------------------------------------------
/events-dataset-api-java/src/test/resources/testcases/http01.json:
--------------------------------------------------------------------------------
1 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2574047966, "type": "PushEvent", "actor": {"id": 1150819, "login": "kelly06", "avatar_url": "https://avatars.com/1150819"}, "repo": {"id": 396918, "name": "terryrangel/veritatis-nam", "url": "https://github.com/terryrangel/veritatis-nam"}, "created_at": "2014-06-01 12:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
2 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3401510983, "type": "PushEvent", "actor": {"id": 3884464, "login": "burchwesley", "avatar_url": "https://avatars.com/3884464"}, "repo": {"id": 323734, "name": "qclark/mollitia-quaerat", "url": "https://github.com/qclark/mollitia-quaerat"}, "created_at": "2015-02-21 20:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
3 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3748093778, "type": "PushEvent", "actor": {"id": 2863822, "login": "heather04", "avatar_url": "https://avatars.com/2863822"}, "repo": {"id": 386392, "name": "davidvazquez/saepe-recusandae", "url": "https://github.com/davidvazquez/saepe-recusandae"}, "created_at": "2015-06-20 13:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
4 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2617464803, "type": "PushEvent", "actor": {"id": 3254680, "login": "bradley49", "avatar_url": "https://avatars.com/3254680"}, "repo": {"id": 175979, "name": "robert37/nesciunt-cum-sint", "url": "https://github.com/robert37/nesciunt-cum-sint"}, "created_at": "2014-06-14 14:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
5 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2365648058, "type": "PushEvent", "actor": {"id": 1646158, "login": "christyingram", "avatar_url": "https://avatars.com/1646158"}, "repo": {"id": 168145, "name": "christyingram/odit-quisquam", "url": "https://github.com/christyingram/odit-quisquam"}, "created_at": "2014-03-23 08:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
6 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3485816627, "type": "PushEvent", "actor": {"id": 2520459, "login": "joy30", "avatar_url": "https://avatars.com/2520459"}, "repo": {"id": 249558, "name": "joy30/corporis-hic", "url": "https://github.com/joy30/corporis-hic"}, "created_at": "2015-03-20 11:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
7 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2225087887, "type": "PushEvent", "actor": {"id": 1834821, "login": "carrie89", "avatar_url": "https://avatars.com/1834821"}, "repo": {"id": 309117, "name": "carrie89/reprehenderit-illo", "url": "https://github.com/carrie89/reprehenderit-illo"}, "created_at": "2014-02-05 04:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
8 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1263251027, "type": "PushEvent", "actor": {"id": 4123208, "login": "trevorhernandez", "avatar_url": "https://avatars.com/4123208"}, "repo": {"id": 332780, "name": "trevorhernandez/quaerat-debitis", "url": "https://github.com/trevorhernandez/quaerat-debitis"}, "created_at": "2013-03-23 22:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
9 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2306769705, "type": "PushEvent", "actor": {"id": 1266960, "login": "austin42", "avatar_url": "https://avatars.com/1266960"}, "repo": {"id": 169895, "name": "austin42/qui-delectus-nulla", "url": "https://github.com/austin42/qui-delectus-nulla"}, "created_at": "2014-03-03 04:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
10 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1617090123, "type": "PushEvent", "actor": {"id": 3338029, "login": "noahball", "avatar_url": "https://avatars.com/3338029"}, "repo": {"id": 294049, "name": "noahball/animi-occaecati", "url": "https://github.com/noahball/animi-occaecati"}, "created_at": "2013-07-16 14:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
11 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1738168616, "type": "PushEvent", "actor": {"id": 4157376, "login": "szhang", "avatar_url": "https://avatars.com/4157376"}, "repo": {"id": 239703, "name": "szhang/quis-quod-quo", "url": "https://github.com/szhang/quis-quod-quo"}, "created_at": "2013-08-27 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
12 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2128252826, "type": "PushEvent", "actor": {"id": 2592501, "login": "davissteve", "avatar_url": "https://avatars.com/2592501"}, "repo": {"id": 220377, "name": "davissteve/quibusdam-ratione", "url": "https://github.com/davissteve/quibusdam-ratione"}, "created_at": "2014-01-01 09:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
13 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4052984544, "type": "PushEvent", "actor": {"id": 4066703, "login": "cory72", "avatar_url": "https://avatars.com/4066703"}, "repo": {"id": 290840, "name": "cory72/perspiciatis", "url": "https://github.com/cory72/perspiciatis"}, "created_at": "2015-10-01 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
14 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4384178234, "type": "PushEvent", "actor": {"id": 3693687, "login": "stephen43", "avatar_url": "https://avatars.com/3693687"}, "repo": {"id": 358948, "name": "stephen43/at-deserunt-quidem", "url": "https://github.com/stephen43/at-deserunt-quidem"}, "created_at": "2016-01-22 20:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
15 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1492950578, "type": "PushEvent", "actor": {"id": 1243932, "login": "jonathanhoffman", "avatar_url": "https://avatars.com/1243932"}, "repo": {"id": 177235, "name": "jonathanhoffman/qui-quod-expedita", "url": "https://github.com/jonathanhoffman/qui-quod-expedita"}, "created_at": "2013-06-11 06:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
16 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1882934979, "type": "PushEvent", "actor": {"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, "repo": {"id": 223563, "name": "brian89/et-laudantium-eos-a", "url": "https://github.com/brian89/et-laudantium-eos-a"}, "created_at": "2013-10-11 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
17 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1881870999, "type": "PushEvent", "actor": {"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, "repo": {"id": 314211, "name": "crystal47/natus-unde-dolore", "url": "https://github.com/crystal47/natus-unde-dolore"}, "created_at": "2013-10-10 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
18 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1561208225, "type": "PushEvent", "actor": {"id": 3422812, "login": "davidgonzalez", "avatar_url": "https://avatars.com/3422812"}, "repo": {"id": 360201, "name": "davidgonzalez/laudantium-corporis", "url": "https://github.com/davidgonzalez/laudantium-corporis"}, "created_at": "2013-06-29 18:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
19 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3789279223, "type": "PushEvent", "actor": {"id": 2259909, "login": "bridget53", "avatar_url": "https://avatars.com/2259909"}, "repo": {"id": 399797, "name": "bridget53/repellendus", "url": "https://github.com/bridget53/repellendus"}, "created_at": "2015-07-03 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
20 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2872093058, "type": "PushEvent", "actor": {"id": 2102610, "login": "fjohnson", "avatar_url": "https://avatars.com/2102610"}, "repo": {"id": 198771, "name": "piercemelissa/officia-id-nulla", "url": "https://github.com/piercemelissa/officia-id-nulla"}, "created_at": "2014-09-08 02:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
21 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1871687406, "type": "PushEvent", "actor": {"id": 1487547, "login": "brittany76", "avatar_url": "https://avatars.com/1487547"}, "repo": {"id": 217705, "name": "erogers/blanditiis", "url": "https://github.com/erogers/blanditiis"}, "created_at": "2013-10-08 15:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
22 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1716784312, "type": "PushEvent", "actor": {"id": 4467597, "login": "adamhenderson", "avatar_url": "https://avatars.com/4467597"}, "repo": {"id": 426776, "name": "gdecker/atque-cum-fuga", "url": "https://github.com/gdecker/atque-cum-fuga"}, "created_at": "2013-08-21 04:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
23 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2959880520, "type": "PushEvent", "actor": {"id": 2855645, "login": "adam00", "avatar_url": "https://avatars.com/2855645"}, "repo": {"id": 237713, "name": "adam00/eum-voluptates", "url": "https://github.com/adam00/eum-voluptates"}, "created_at": "2014-10-05 13:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
24 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4347617181, "type": "PushEvent", "actor": {"id": 4740807, "login": "lauradecker", "avatar_url": "https://avatars.com/4740807"}, "repo": {"id": 494116, "name": "lauradecker/recusandae-harum", "url": "https://github.com/lauradecker/recusandae-harum"}, "created_at": "2016-01-12 13:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
25 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3092732178, "type": "PushEvent", "actor": {"id": 3135921, "login": "oparker", "avatar_url": "https://avatars.com/3135921"}, "repo": {"id": 470982, "name": "oparker/quibusdam-rerum", "url": "https://github.com/oparker/quibusdam-rerum"}, "created_at": "2014-11-17 21:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
26 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4745170420, "type": "PushEvent", "actor": {"id": 4999205, "login": "mitchellpatricia", "avatar_url": "https://avatars.com/4999205"}, "repo": {"id": 131068, "name": "mitchellpatricia/id-cum-ea-quisquam", "url": "https://github.com/mitchellpatricia/id-cum-ea-quisquam"}, "created_at": "2016-06-02 20:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
27 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2844830199, "type": "PushEvent", "actor": {"id": 4774666, "login": "brian06", "avatar_url": "https://avatars.com/4774666"}, "repo": {"id": 145039, "name": "yhubbard/dolores-quam-odit", "url": "https://github.com/yhubbard/dolores-quam-odit"}, "created_at": "2014-08-29 05:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
28 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4308339559, "type": "PushEvent", "actor": {"id": 4120347, "login": "amy64", "avatar_url": "https://avatars.com/4120347"}, "repo": {"id": 186461, "name": "amy64/rerum-quis-rem", "url": "https://github.com/amy64/rerum-quis-rem"}, "created_at": "2015-12-29 21:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
29 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3808480238, "type": "PushEvent", "actor": {"id": 3447344, "login": "pkrause", "avatar_url": "https://avatars.com/3447344"}, "repo": {"id": 128265, "name": "greg30/aut-sapiente-magni", "url": "https://github.com/greg30/aut-sapiente-magni"}, "created_at": "2015-07-11 12:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
30 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1221708571, "type": "PushEvent", "actor": {"id": 4423526, "login": "andrew83", "avatar_url": "https://avatars.com/4423526"}, "repo": {"id": 283516, "name": "andrew83/pariatur-asperiores", "url": "https://github.com/andrew83/pariatur-asperiores"}, "created_at": "2013-03-10 02:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
31 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4533493923, "type": "PushEvent", "actor": {"id": 3709777, "login": "mary22", "avatar_url": "https://avatars.com/3709777"}, "repo": {"id": 134502, "name": "aaronaustin/molestiae-tenetur", "url": "https://github.com/aaronaustin/molestiae-tenetur"}, "created_at": "2016-03-15 02:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
32 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4086789703, "type": "PushEvent", "actor": {"id": 1665468, "login": "brandonmcmahon", "avatar_url": "https://avatars.com/1665468"}, "repo": {"id": 218043, "name": "john47/ex-rem-quas-earum", "url": "https://github.com/john47/ex-rem-quas-earum"}, "created_at": "2015-10-15 08:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
33 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2496439633, "type": "PushEvent", "actor": {"id": 4148608, "login": "michael80", "avatar_url": "https://avatars.com/4148608"}, "repo": {"id": 315063, "name": "ydowns/nemo-illum-voluptas", "url": "https://github.com/ydowns/nemo-illum-voluptas"}, "created_at": "2014-05-05 09:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
34 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1390390563, "type": "PushEvent", "actor": {"id": 1926441, "login": "fhill", "avatar_url": "https://avatars.com/1926441"}, "repo": {"id": 483195, "name": "fhill/quia-hic-placeat", "url": "https://github.com/fhill/quia-hic-placeat"}, "created_at": "2013-05-09 03:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
35 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3349994045, "type": "PushEvent", "actor": {"id": 3084646, "login": "jonesrhonda", "avatar_url": "https://avatars.com/3084646"}, "repo": {"id": 328519, "name": "daniel14/libero-dignissimos", "url": "https://github.com/daniel14/libero-dignissimos"}, "created_at": "2015-02-08 22:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
36 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1297049767, "type": "PushEvent", "actor": {"id": 1432556, "login": "tedwards", "avatar_url": "https://avatars.com/1432556"}, "repo": {"id": 427447, "name": "lisa67/nam-inventore", "url": "https://github.com/lisa67/nam-inventore"}, "created_at": "2013-04-06 12:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
37 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3647003602, "type": "PushEvent", "actor": {"id": 3830996, "login": "lopezbarry", "avatar_url": "https://avatars.com/3830996"}, "repo": {"id": 314991, "name": "lopezbarry/aliquam-eveniet", "url": "https://github.com/lopezbarry/aliquam-eveniet"}, "created_at": "2015-05-17 04:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
38 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1139424092, "type": "PushEvent", "actor": {"id": 1087596, "login": "jason96", "avatar_url": "https://avatars.com/1087596"}, "repo": {"id": 406290, "name": "jason96/perferendis", "url": "https://github.com/jason96/perferendis"}, "created_at": "2013-02-11 22:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
39 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3000460528, "type": "PushEvent", "actor": {"id": 1154866, "login": "williamolson", "avatar_url": "https://avatars.com/1154866"}, "repo": {"id": 201228, "name": "williamolson/enim-modi-expedita", "url": "https://github.com/williamolson/enim-modi-expedita"}, "created_at": "2014-10-19 05:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
40 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3887570859, "type": "PushEvent", "actor": {"id": 1507784, "login": "amanda40", "avatar_url": "https://avatars.com/1507784"}, "repo": {"id": 330045, "name": "lopezrobert/sapiente-voluptatem", "url": "https://github.com/lopezrobert/sapiente-voluptatem"}, "created_at": "2015-08-06 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
41 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2646393240, "type": "PushEvent", "actor": {"id": 2435001, "login": "robertsondonald", "avatar_url": "https://avatars.com/2435001"}, "repo": {"id": 464732, "name": "robertsondonald/natus-itaque-sit", "url": "https://github.com/robertsondonald/natus-itaque-sit"}, "created_at": "2014-06-23 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
42 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3748278229, "type": "PushEvent", "actor": {"id": 3843889, "login": "brian65", "avatar_url": "https://avatars.com/3843889"}, "repo": {"id": 326461, "name": "brian65/nisi-pariatur", "url": "https://github.com/brian65/nisi-pariatur"}, "created_at": "2015-06-20 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
43 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4591339624, "type": "PushEvent", "actor": {"id": 1543690, "login": "harrislevi", "avatar_url": "https://avatars.com/1543690"}, "repo": {"id": 250873, "name": "harrislevi/sed-cumque-hic", "url": "https://github.com/harrislevi/sed-cumque-hic"}, "created_at": "2016-04-03 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
44 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4450001658, "type": "PushEvent", "actor": {"id": 2527143, "login": "kimberly97", "avatar_url": "https://avatars.com/2527143"}, "repo": {"id": 411068, "name": "kimberly97/assumenda", "url": "https://github.com/kimberly97/assumenda"}, "created_at": "2016-02-17 00:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
45 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2490355854, "type": "PushEvent", "actor": {"id": 3580452, "login": "jamesscott", "avatar_url": "https://avatars.com/3580452"}, "repo": {"id": 347804, "name": "harrisjudy/non-illo-blanditiis", "url": "https://github.com/harrisjudy/non-illo-blanditiis"}, "created_at": "2014-05-03 00:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
46 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2116545087, "type": "PushEvent", "actor": {"id": 4887912, "login": "alisha24", "avatar_url": "https://avatars.com/4887912"}, "repo": {"id": 324761, "name": "alisha24/vitae-atque-eos", "url": "https://github.com/alisha24/vitae-atque-eos"}, "created_at": "2013-12-27 13:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
47 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3913826700, "type": "PushEvent", "actor": {"id": 3692087, "login": "hawkinseric", "avatar_url": "https://avatars.com/3692087"}, "repo": {"id": 226980, "name": "curtisburke/distinctio-sed", "url": "https://github.com/curtisburke/distinctio-sed"}, "created_at": "2015-08-13 17:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
48 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1057254646, "type": "PushEvent", "actor": {"id": 2151966, "login": "fbailey", "avatar_url": "https://avatars.com/2151966"}, "repo": {"id": 195938, "name": "fbailey/odit-voluptate", "url": "https://github.com/fbailey/odit-voluptate"}, "created_at": "2013-01-16 22:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
49 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2974820003, "type": "PushEvent", "actor": {"id": 2782108, "login": "atkinsonemily", "avatar_url": "https://avatars.com/2782108"}, "repo": {"id": 332625, "name": "cwolfe/eveniet-provident", "url": "https://github.com/cwolfe/eveniet-provident"}, "created_at": "2014-10-11 14:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
50 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1648867687, "type": "PushEvent", "actor": {"id": 3213163, "login": "sandy34", "avatar_url": "https://avatars.com/3213163"}, "repo": {"id": 422881, "name": "sandy34/hic-error", "url": "https://github.com/sandy34/hic-error"}, "created_at": "2013-07-28 01:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
51 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4915595498, "type": "PushEvent", "actor": {"id": 3744250, "login": "aphillips", "avatar_url": "https://avatars.com/3744250"}, "repo": {"id": 261062, "name": "aphillips/nostrum-alias-nihil", "url": "https://github.com/aphillips/nostrum-alias-nihil"}, "created_at": "2016-08-23 18:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
52 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1896365977, "type": "PushEvent", "actor": {"id": 3375972, "login": "alyssahendricks", "avatar_url": "https://avatars.com/3375972"}, "repo": {"id": 152350, "name": "jamie49/consequatur-dolorum", "url": "https://github.com/jamie49/consequatur-dolorum"}, "created_at": "2013-10-15 15:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
53 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 4403174223, "type": "PushEvent", "actor": {"id": 1784183, "login": "eortega", "avatar_url": "https://avatars.com/1784183"}, "repo": {"id": 276635, "name": "terryjohn/temporibus-ratione", "url": "https://github.com/terryjohn/temporibus-ratione"}, "created_at": "2016-01-29 05:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
54 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2155147817, "type": "PushEvent", "actor": {"id": 1352530, "login": "mariah69", "avatar_url": "https://avatars.com/1352530"}, "repo": {"id": 142622, "name": "mariah69/corrupti-cumque", "url": "https://github.com/mariah69/corrupti-cumque"}, "created_at": "2014-01-11 06:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
55 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 1104885308, "type": "PushEvent", "actor": {"id": 1669333, "login": "dariushernandez", "avatar_url": "https://avatars.com/1669333"}, "repo": {"id": 343170, "name": "hernandezamy/ratione-soluta", "url": "https://github.com/hernandezamy/ratione-soluta"}, "created_at": "2013-01-31 18:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
56 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3914849212, "type": "PushEvent", "actor": {"id": 3749719, "login": "kelleyanna", "avatar_url": "https://avatars.com/3749719"}, "repo": {"id": 263921, "name": "kelleyanna/sed-repellat", "url": "https://github.com/kelleyanna/sed-repellat"}, "created_at": "2015-08-14 11:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
57 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2826499619, "type": "PushEvent", "actor": {"id": 3791484, "login": "gmyers", "avatar_url": "https://avatars.com/3791484"}, "repo": {"id": 211150, "name": "gmyers/blanditiis-cum-sunt", "url": "https://github.com/gmyers/blanditiis-cum-sunt"}, "created_at": "2014-08-22 02:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
58 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 2824724808, "type": "PushEvent", "actor": {"id": 2846528, "login": "owenspatricia", "avatar_url": "https://avatars.com/2846528"}, "repo": {"id": 121707, "name": "elizabeth38/atque-illum-id-ab", "url": "https://github.com/elizabeth38/atque-illum-id-ab"}, "created_at": "2014-08-21 23:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
59 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3962368695, "type": "PushEvent", "actor": {"id": 1125185, "login": "nwerner", "avatar_url": "https://avatars.com/1125185"}, "repo": {"id": 414344, "name": "rcollins/possimus-commodi", "url": "https://github.com/rcollins/possimus-commodi"}, "created_at": "2015-09-01 10:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
60 | {"request": {"method": "POST", "url": "/events", "headers": {"Content-Type": "application/json"}, "body": {"id": 3518255637, "type": "PushEvent", "actor": {"id": 2172119, "login": "kristina09", "avatar_url": "https://avatars.com/2172119"}, "repo": {"id": 233108, "name": "smithcraig/voluptate-qui-ea", "url": "https://github.com/smithcraig/voluptate-qui-ea"}, "created_at": "2015-04-01 18:13:31"}}, "response": {"status_code": 201, "body": {}, "headers": {}}}
61 | {"request": {"method": "GET", "url": "/events/actors/1087596", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 1139424092, "type": "PushEvent", "actor": {"id": 1087596, "login": "jason96", "avatar_url": "https://avatars.com/1087596"}, "repo": {"id": 406290, "name": "jason96/perferendis", "url": "https://github.com/jason96/perferendis"}, "created_at": "2013-02-11 22:13:31"}], "headers": {"Content-Type": "application/json"}}}
62 | {"request": {"method": "GET", "url": "/actors/streak", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, {"id": 3744250, "login": "aphillips", "avatar_url": "https://avatars.com/3744250"}, {"id": 4999205, "login": "mitchellpatricia", "avatar_url": "https://avatars.com/4999205"}, {"id": 1543690, "login": "harrislevi", "avatar_url": "https://avatars.com/1543690"}, {"id": 3709777, "login": "mary22", "avatar_url": "https://avatars.com/3709777"}, {"id": 2527143, "login": "kimberly97", "avatar_url": "https://avatars.com/2527143"}, {"id": 1784183, "login": "eortega", "avatar_url": "https://avatars.com/1784183"}, {"id": 3693687, "login": "stephen43", "avatar_url": "https://avatars.com/3693687"}, {"id": 4740807, "login": "lauradecker", "avatar_url": "https://avatars.com/4740807"}, {"id": 4120347, "login": "amy64", "avatar_url": "https://avatars.com/4120347"}, {"id": 1665468, "login": "brandonmcmahon", "avatar_url": "https://avatars.com/1665468"}, {"id": 4066703, "login": "cory72", "avatar_url": "https://avatars.com/4066703"}, {"id": 1125185, "login": "nwerner", "avatar_url": "https://avatars.com/1125185"}, {"id": 3749719, "login": "kelleyanna", "avatar_url": "https://avatars.com/3749719"}, {"id": 3692087, "login": "hawkinseric", "avatar_url": "https://avatars.com/3692087"}, {"id": 1507784, "login": "amanda40", "avatar_url": "https://avatars.com/1507784"}, {"id": 3447344, "login": "pkrause", "avatar_url": "https://avatars.com/3447344"}, {"id": 2259909, "login": "bridget53", "avatar_url": "https://avatars.com/2259909"}, {"id": 3843889, "login": "brian65", "avatar_url": "https://avatars.com/3843889"}, {"id": 2863822, "login": "heather04", "avatar_url": "https://avatars.com/2863822"}, {"id": 3830996, "login": "lopezbarry", "avatar_url": "https://avatars.com/3830996"}, {"id": 2172119, "login": "kristina09", "avatar_url": "https://avatars.com/2172119"}, {"id": 2520459, "login": "joy30", "avatar_url": "https://avatars.com/2520459"}, {"id": 3884464, "login": "burchwesley", "avatar_url": "https://avatars.com/3884464"}, {"id": 3084646, "login": "jonesrhonda", "avatar_url": "https://avatars.com/3084646"}, {"id": 3135921, "login": "oparker", "avatar_url": "https://avatars.com/3135921"}, {"id": 1154866, "login": "williamolson", "avatar_url": "https://avatars.com/1154866"}, {"id": 2782108, "login": "atkinsonemily", "avatar_url": "https://avatars.com/2782108"}, {"id": 2855645, "login": "adam00", "avatar_url": "https://avatars.com/2855645"}, {"id": 2102610, "login": "fjohnson", "avatar_url": "https://avatars.com/2102610"}, {"id": 4774666, "login": "brian06", "avatar_url": "https://avatars.com/4774666"}, {"id": 3791484, "login": "gmyers", "avatar_url": "https://avatars.com/3791484"}, {"id": 2846528, "login": "owenspatricia", "avatar_url": "https://avatars.com/2846528"}, {"id": 2435001, "login": "robertsondonald", "avatar_url": "https://avatars.com/2435001"}, {"id": 3254680, "login": "bradley49", "avatar_url": "https://avatars.com/3254680"}, {"id": 1150819, "login": "kelly06", "avatar_url": "https://avatars.com/1150819"}, {"id": 4148608, "login": "michael80", "avatar_url": "https://avatars.com/4148608"}, {"id": 3580452, "login": "jamesscott", "avatar_url": "https://avatars.com/3580452"}, {"id": 1646158, "login": "christyingram", "avatar_url": "https://avatars.com/1646158"}, {"id": 1266960, "login": "austin42", "avatar_url": "https://avatars.com/1266960"}, {"id": 1834821, "login": "carrie89", "avatar_url": "https://avatars.com/1834821"}, {"id": 1352530, "login": "mariah69", "avatar_url": "https://avatars.com/1352530"}, {"id": 2592501, "login": "davissteve", "avatar_url": "https://avatars.com/2592501"}, {"id": 4887912, "login": "alisha24", "avatar_url": "https://avatars.com/4887912"}, {"id": 3375972, "login": "alyssahendricks", "avatar_url": "https://avatars.com/3375972"}, {"id": 1487547, "login": "brittany76", "avatar_url": "https://avatars.com/1487547"}, {"id": 4157376, "login": "szhang", "avatar_url": "https://avatars.com/4157376"}, {"id": 4467597, "login": "adamhenderson", "avatar_url": "https://avatars.com/4467597"}, {"id": 3213163, "login": "sandy34", "avatar_url": "https://avatars.com/3213163"}, {"id": 3338029, "login": "noahball", "avatar_url": "https://avatars.com/3338029"}, {"id": 3422812, "login": "davidgonzalez", "avatar_url": "https://avatars.com/3422812"}, {"id": 1243932, "login": "jonathanhoffman", "avatar_url": "https://avatars.com/1243932"}, {"id": 1926441, "login": "fhill", "avatar_url": "https://avatars.com/1926441"}, {"id": 1432556, "login": "tedwards", "avatar_url": "https://avatars.com/1432556"}, {"id": 4123208, "login": "trevorhernandez", "avatar_url": "https://avatars.com/4123208"}, {"id": 4423526, "login": "andrew83", "avatar_url": "https://avatars.com/4423526"}, {"id": 1087596, "login": "jason96", "avatar_url": "https://avatars.com/1087596"}, {"id": 1669333, "login": "dariushernandez", "avatar_url": "https://avatars.com/1669333"}, {"id": 2151966, "login": "fbailey", "avatar_url": "https://avatars.com/2151966"}], "headers": {"Content-Type": "application/json"}}}
63 | {"request": {"method": "PUT", "url": "/actors", "headers": {"Content-Type": "application/json"}, "body": {"id": 2520459, "login": "joy30", "avatar_url": "https://avatars.com/modified2"}}, "response": {"status_code": 200, "body": {}, "headers": {}}}
64 | {"request": {"method": "GET", "url": "/events", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 1057254646, "type": "PushEvent", "actor": {"id": 2151966, "login": "fbailey", "avatar_url": "https://avatars.com/2151966"}, "repo": {"id": 195938, "name": "fbailey/odit-voluptate", "url": "https://github.com/fbailey/odit-voluptate"}, "created_at": "2013-01-16 22:13:31"}, {"id": 1104885308, "type": "PushEvent", "actor": {"id": 1669333, "login": "dariushernandez", "avatar_url": "https://avatars.com/1669333"}, "repo": {"id": 343170, "name": "hernandezamy/ratione-soluta", "url": "https://github.com/hernandezamy/ratione-soluta"}, "created_at": "2013-01-31 18:13:31"}, {"id": 1139424092, "type": "PushEvent", "actor": {"id": 1087596, "login": "jason96", "avatar_url": "https://avatars.com/1087596"}, "repo": {"id": 406290, "name": "jason96/perferendis", "url": "https://github.com/jason96/perferendis"}, "created_at": "2013-02-11 22:13:31"}, {"id": 1221708571, "type": "PushEvent", "actor": {"id": 4423526, "login": "andrew83", "avatar_url": "https://avatars.com/4423526"}, "repo": {"id": 283516, "name": "andrew83/pariatur-asperiores", "url": "https://github.com/andrew83/pariatur-asperiores"}, "created_at": "2013-03-10 02:13:31"}, {"id": 1263251027, "type": "PushEvent", "actor": {"id": 4123208, "login": "trevorhernandez", "avatar_url": "https://avatars.com/4123208"}, "repo": {"id": 332780, "name": "trevorhernandez/quaerat-debitis", "url": "https://github.com/trevorhernandez/quaerat-debitis"}, "created_at": "2013-03-23 22:13:31"}, {"id": 1297049767, "type": "PushEvent", "actor": {"id": 1432556, "login": "tedwards", "avatar_url": "https://avatars.com/1432556"}, "repo": {"id": 427447, "name": "lisa67/nam-inventore", "url": "https://github.com/lisa67/nam-inventore"}, "created_at": "2013-04-06 12:13:31"}, {"id": 1390390563, "type": "PushEvent", "actor": {"id": 1926441, "login": "fhill", "avatar_url": "https://avatars.com/1926441"}, "repo": {"id": 483195, "name": "fhill/quia-hic-placeat", "url": "https://github.com/fhill/quia-hic-placeat"}, "created_at": "2013-05-09 03:13:31"}, {"id": 1492950578, "type": "PushEvent", "actor": {"id": 1243932, "login": "jonathanhoffman", "avatar_url": "https://avatars.com/1243932"}, "repo": {"id": 177235, "name": "jonathanhoffman/qui-quod-expedita", "url": "https://github.com/jonathanhoffman/qui-quod-expedita"}, "created_at": "2013-06-11 06:13:31"}, {"id": 1561208225, "type": "PushEvent", "actor": {"id": 3422812, "login": "davidgonzalez", "avatar_url": "https://avatars.com/3422812"}, "repo": {"id": 360201, "name": "davidgonzalez/laudantium-corporis", "url": "https://github.com/davidgonzalez/laudantium-corporis"}, "created_at": "2013-06-29 18:13:31"}, {"id": 1617090123, "type": "PushEvent", "actor": {"id": 3338029, "login": "noahball", "avatar_url": "https://avatars.com/3338029"}, "repo": {"id": 294049, "name": "noahball/animi-occaecati", "url": "https://github.com/noahball/animi-occaecati"}, "created_at": "2013-07-16 14:13:31"}, {"id": 1648867687, "type": "PushEvent", "actor": {"id": 3213163, "login": "sandy34", "avatar_url": "https://avatars.com/3213163"}, "repo": {"id": 422881, "name": "sandy34/hic-error", "url": "https://github.com/sandy34/hic-error"}, "created_at": "2013-07-28 01:13:31"}, {"id": 1716784312, "type": "PushEvent", "actor": {"id": 4467597, "login": "adamhenderson", "avatar_url": "https://avatars.com/4467597"}, "repo": {"id": 426776, "name": "gdecker/atque-cum-fuga", "url": "https://github.com/gdecker/atque-cum-fuga"}, "created_at": "2013-08-21 04:13:31"}, {"id": 1738168616, "type": "PushEvent", "actor": {"id": 4157376, "login": "szhang", "avatar_url": "https://avatars.com/4157376"}, "repo": {"id": 239703, "name": "szhang/quis-quod-quo", "url": "https://github.com/szhang/quis-quod-quo"}, "created_at": "2013-08-27 17:13:31"}, {"id": 1871687406, "type": "PushEvent", "actor": {"id": 1487547, "login": "brittany76", "avatar_url": "https://avatars.com/1487547"}, "repo": {"id": 217705, "name": "erogers/blanditiis", "url": "https://github.com/erogers/blanditiis"}, "created_at": "2013-10-08 15:13:31"}, {"id": 1881870999, "type": "PushEvent", "actor": {"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, "repo": {"id": 314211, "name": "crystal47/natus-unde-dolore", "url": "https://github.com/crystal47/natus-unde-dolore"}, "created_at": "2013-10-10 23:13:31"}, {"id": 1882934979, "type": "PushEvent", "actor": {"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, "repo": {"id": 223563, "name": "brian89/et-laudantium-eos-a", "url": "https://github.com/brian89/et-laudantium-eos-a"}, "created_at": "2013-10-11 17:13:31"}, {"id": 1896365977, "type": "PushEvent", "actor": {"id": 3375972, "login": "alyssahendricks", "avatar_url": "https://avatars.com/3375972"}, "repo": {"id": 152350, "name": "jamie49/consequatur-dolorum", "url": "https://github.com/jamie49/consequatur-dolorum"}, "created_at": "2013-10-15 15:13:31"}, {"id": 2116545087, "type": "PushEvent", "actor": {"id": 4887912, "login": "alisha24", "avatar_url": "https://avatars.com/4887912"}, "repo": {"id": 324761, "name": "alisha24/vitae-atque-eos", "url": "https://github.com/alisha24/vitae-atque-eos"}, "created_at": "2013-12-27 13:13:31"}, {"id": 2128252826, "type": "PushEvent", "actor": {"id": 2592501, "login": "davissteve", "avatar_url": "https://avatars.com/2592501"}, "repo": {"id": 220377, "name": "davissteve/quibusdam-ratione", "url": "https://github.com/davissteve/quibusdam-ratione"}, "created_at": "2014-01-01 09:13:31"}, {"id": 2155147817, "type": "PushEvent", "actor": {"id": 1352530, "login": "mariah69", "avatar_url": "https://avatars.com/1352530"}, "repo": {"id": 142622, "name": "mariah69/corrupti-cumque", "url": "https://github.com/mariah69/corrupti-cumque"}, "created_at": "2014-01-11 06:13:31"}, {"id": 2225087887, "type": "PushEvent", "actor": {"id": 1834821, "login": "carrie89", "avatar_url": "https://avatars.com/1834821"}, "repo": {"id": 309117, "name": "carrie89/reprehenderit-illo", "url": "https://github.com/carrie89/reprehenderit-illo"}, "created_at": "2014-02-05 04:13:31"}, {"id": 2306769705, "type": "PushEvent", "actor": {"id": 1266960, "login": "austin42", "avatar_url": "https://avatars.com/1266960"}, "repo": {"id": 169895, "name": "austin42/qui-delectus-nulla", "url": "https://github.com/austin42/qui-delectus-nulla"}, "created_at": "2014-03-03 04:13:31"}, {"id": 2365648058, "type": "PushEvent", "actor": {"id": 1646158, "login": "christyingram", "avatar_url": "https://avatars.com/1646158"}, "repo": {"id": 168145, "name": "christyingram/odit-quisquam", "url": "https://github.com/christyingram/odit-quisquam"}, "created_at": "2014-03-23 08:13:31"}, {"id": 2490355854, "type": "PushEvent", "actor": {"id": 3580452, "login": "jamesscott", "avatar_url": "https://avatars.com/3580452"}, "repo": {"id": 347804, "name": "harrisjudy/non-illo-blanditiis", "url": "https://github.com/harrisjudy/non-illo-blanditiis"}, "created_at": "2014-05-03 00:13:31"}, {"id": 2496439633, "type": "PushEvent", "actor": {"id": 4148608, "login": "michael80", "avatar_url": "https://avatars.com/4148608"}, "repo": {"id": 315063, "name": "ydowns/nemo-illum-voluptas", "url": "https://github.com/ydowns/nemo-illum-voluptas"}, "created_at": "2014-05-05 09:13:31"}, {"id": 2574047966, "type": "PushEvent", "actor": {"id": 1150819, "login": "kelly06", "avatar_url": "https://avatars.com/1150819"}, "repo": {"id": 396918, "name": "terryrangel/veritatis-nam", "url": "https://github.com/terryrangel/veritatis-nam"}, "created_at": "2014-06-01 12:13:31"}, {"id": 2617464803, "type": "PushEvent", "actor": {"id": 3254680, "login": "bradley49", "avatar_url": "https://avatars.com/3254680"}, "repo": {"id": 175979, "name": "robert37/nesciunt-cum-sint", "url": "https://github.com/robert37/nesciunt-cum-sint"}, "created_at": "2014-06-14 14:13:31"}, {"id": 2646393240, "type": "PushEvent", "actor": {"id": 2435001, "login": "robertsondonald", "avatar_url": "https://avatars.com/2435001"}, "repo": {"id": 464732, "name": "robertsondonald/natus-itaque-sit", "url": "https://github.com/robertsondonald/natus-itaque-sit"}, "created_at": "2014-06-23 23:13:31"}, {"id": 2824724808, "type": "PushEvent", "actor": {"id": 2846528, "login": "owenspatricia", "avatar_url": "https://avatars.com/2846528"}, "repo": {"id": 121707, "name": "elizabeth38/atque-illum-id-ab", "url": "https://github.com/elizabeth38/atque-illum-id-ab"}, "created_at": "2014-08-21 23:13:31"}, {"id": 2826499619, "type": "PushEvent", "actor": {"id": 3791484, "login": "gmyers", "avatar_url": "https://avatars.com/3791484"}, "repo": {"id": 211150, "name": "gmyers/blanditiis-cum-sunt", "url": "https://github.com/gmyers/blanditiis-cum-sunt"}, "created_at": "2014-08-22 02:13:31"}, {"id": 2844830199, "type": "PushEvent", "actor": {"id": 4774666, "login": "brian06", "avatar_url": "https://avatars.com/4774666"}, "repo": {"id": 145039, "name": "yhubbard/dolores-quam-odit", "url": "https://github.com/yhubbard/dolores-quam-odit"}, "created_at": "2014-08-29 05:13:31"}, {"id": 2872093058, "type": "PushEvent", "actor": {"id": 2102610, "login": "fjohnson", "avatar_url": "https://avatars.com/2102610"}, "repo": {"id": 198771, "name": "piercemelissa/officia-id-nulla", "url": "https://github.com/piercemelissa/officia-id-nulla"}, "created_at": "2014-09-08 02:13:31"}, {"id": 2959880520, "type": "PushEvent", "actor": {"id": 2855645, "login": "adam00", "avatar_url": "https://avatars.com/2855645"}, "repo": {"id": 237713, "name": "adam00/eum-voluptates", "url": "https://github.com/adam00/eum-voluptates"}, "created_at": "2014-10-05 13:13:31"}, {"id": 2974820003, "type": "PushEvent", "actor": {"id": 2782108, "login": "atkinsonemily", "avatar_url": "https://avatars.com/2782108"}, "repo": {"id": 332625, "name": "cwolfe/eveniet-provident", "url": "https://github.com/cwolfe/eveniet-provident"}, "created_at": "2014-10-11 14:13:31"}, {"id": 3000460528, "type": "PushEvent", "actor": {"id": 1154866, "login": "williamolson", "avatar_url": "https://avatars.com/1154866"}, "repo": {"id": 201228, "name": "williamolson/enim-modi-expedita", "url": "https://github.com/williamolson/enim-modi-expedita"}, "created_at": "2014-10-19 05:13:31"}, {"id": 3092732178, "type": "PushEvent", "actor": {"id": 3135921, "login": "oparker", "avatar_url": "https://avatars.com/3135921"}, "repo": {"id": 470982, "name": "oparker/quibusdam-rerum", "url": "https://github.com/oparker/quibusdam-rerum"}, "created_at": "2014-11-17 21:13:31"}, {"id": 3349994045, "type": "PushEvent", "actor": {"id": 3084646, "login": "jonesrhonda", "avatar_url": "https://avatars.com/3084646"}, "repo": {"id": 328519, "name": "daniel14/libero-dignissimos", "url": "https://github.com/daniel14/libero-dignissimos"}, "created_at": "2015-02-08 22:13:31"}, {"id": 3401510983, "type": "PushEvent", "actor": {"id": 3884464, "login": "burchwesley", "avatar_url": "https://avatars.com/3884464"}, "repo": {"id": 323734, "name": "qclark/mollitia-quaerat", "url": "https://github.com/qclark/mollitia-quaerat"}, "created_at": "2015-02-21 20:13:31"}, {"id": 3485816627, "type": "PushEvent", "actor": {"id": 2520459, "login": "joy30", "avatar_url": "https://avatars.com/modified2"}, "repo": {"id": 249558, "name": "joy30/corporis-hic", "url": "https://github.com/joy30/corporis-hic"}, "created_at": "2015-03-20 11:13:31"}, {"id": 3518255637, "type": "PushEvent", "actor": {"id": 2172119, "login": "kristina09", "avatar_url": "https://avatars.com/2172119"}, "repo": {"id": 233108, "name": "smithcraig/voluptate-qui-ea", "url": "https://github.com/smithcraig/voluptate-qui-ea"}, "created_at": "2015-04-01 18:13:31"}, {"id": 3647003602, "type": "PushEvent", "actor": {"id": 3830996, "login": "lopezbarry", "avatar_url": "https://avatars.com/3830996"}, "repo": {"id": 314991, "name": "lopezbarry/aliquam-eveniet", "url": "https://github.com/lopezbarry/aliquam-eveniet"}, "created_at": "2015-05-17 04:13:31"}, {"id": 3748093778, "type": "PushEvent", "actor": {"id": 2863822, "login": "heather04", "avatar_url": "https://avatars.com/2863822"}, "repo": {"id": 386392, "name": "davidvazquez/saepe-recusandae", "url": "https://github.com/davidvazquez/saepe-recusandae"}, "created_at": "2015-06-20 13:13:31"}, {"id": 3748278229, "type": "PushEvent", "actor": {"id": 3843889, "login": "brian65", "avatar_url": "https://avatars.com/3843889"}, "repo": {"id": 326461, "name": "brian65/nisi-pariatur", "url": "https://github.com/brian65/nisi-pariatur"}, "created_at": "2015-06-20 17:13:31"}, {"id": 3789279223, "type": "PushEvent", "actor": {"id": 2259909, "login": "bridget53", "avatar_url": "https://avatars.com/2259909"}, "repo": {"id": 399797, "name": "bridget53/repellendus", "url": "https://github.com/bridget53/repellendus"}, "created_at": "2015-07-03 23:13:31"}, {"id": 3808480238, "type": "PushEvent", "actor": {"id": 3447344, "login": "pkrause", "avatar_url": "https://avatars.com/3447344"}, "repo": {"id": 128265, "name": "greg30/aut-sapiente-magni", "url": "https://github.com/greg30/aut-sapiente-magni"}, "created_at": "2015-07-11 12:13:31"}, {"id": 3887570859, "type": "PushEvent", "actor": {"id": 1507784, "login": "amanda40", "avatar_url": "https://avatars.com/1507784"}, "repo": {"id": 330045, "name": "lopezrobert/sapiente-voluptatem", "url": "https://github.com/lopezrobert/sapiente-voluptatem"}, "created_at": "2015-08-06 17:13:31"}, {"id": 3913826700, "type": "PushEvent", "actor": {"id": 3692087, "login": "hawkinseric", "avatar_url": "https://avatars.com/3692087"}, "repo": {"id": 226980, "name": "curtisburke/distinctio-sed", "url": "https://github.com/curtisburke/distinctio-sed"}, "created_at": "2015-08-13 17:13:31"}, {"id": 3914849212, "type": "PushEvent", "actor": {"id": 3749719, "login": "kelleyanna", "avatar_url": "https://avatars.com/3749719"}, "repo": {"id": 263921, "name": "kelleyanna/sed-repellat", "url": "https://github.com/kelleyanna/sed-repellat"}, "created_at": "2015-08-14 11:13:31"}, {"id": 3962368695, "type": "PushEvent", "actor": {"id": 1125185, "login": "nwerner", "avatar_url": "https://avatars.com/1125185"}, "repo": {"id": 414344, "name": "rcollins/possimus-commodi", "url": "https://github.com/rcollins/possimus-commodi"}, "created_at": "2015-09-01 10:13:31"}, {"id": 4052984544, "type": "PushEvent", "actor": {"id": 4066703, "login": "cory72", "avatar_url": "https://avatars.com/4066703"}, "repo": {"id": 290840, "name": "cory72/perspiciatis", "url": "https://github.com/cory72/perspiciatis"}, "created_at": "2015-10-01 23:13:31"}, {"id": 4086789703, "type": "PushEvent", "actor": {"id": 1665468, "login": "brandonmcmahon", "avatar_url": "https://avatars.com/1665468"}, "repo": {"id": 218043, "name": "john47/ex-rem-quas-earum", "url": "https://github.com/john47/ex-rem-quas-earum"}, "created_at": "2015-10-15 08:13:31"}, {"id": 4308339559, "type": "PushEvent", "actor": {"id": 4120347, "login": "amy64", "avatar_url": "https://avatars.com/4120347"}, "repo": {"id": 186461, "name": "amy64/rerum-quis-rem", "url": "https://github.com/amy64/rerum-quis-rem"}, "created_at": "2015-12-29 21:13:31"}, {"id": 4347617181, "type": "PushEvent", "actor": {"id": 4740807, "login": "lauradecker", "avatar_url": "https://avatars.com/4740807"}, "repo": {"id": 494116, "name": "lauradecker/recusandae-harum", "url": "https://github.com/lauradecker/recusandae-harum"}, "created_at": "2016-01-12 13:13:31"}, {"id": 4384178234, "type": "PushEvent", "actor": {"id": 3693687, "login": "stephen43", "avatar_url": "https://avatars.com/3693687"}, "repo": {"id": 358948, "name": "stephen43/at-deserunt-quidem", "url": "https://github.com/stephen43/at-deserunt-quidem"}, "created_at": "2016-01-22 20:13:31"}, {"id": 4403174223, "type": "PushEvent", "actor": {"id": 1784183, "login": "eortega", "avatar_url": "https://avatars.com/1784183"}, "repo": {"id": 276635, "name": "terryjohn/temporibus-ratione", "url": "https://github.com/terryjohn/temporibus-ratione"}, "created_at": "2016-01-29 05:13:31"}, {"id": 4450001658, "type": "PushEvent", "actor": {"id": 2527143, "login": "kimberly97", "avatar_url": "https://avatars.com/2527143"}, "repo": {"id": 411068, "name": "kimberly97/assumenda", "url": "https://github.com/kimberly97/assumenda"}, "created_at": "2016-02-17 00:13:31"}, {"id": 4533493923, "type": "PushEvent", "actor": {"id": 3709777, "login": "mary22", "avatar_url": "https://avatars.com/3709777"}, "repo": {"id": 134502, "name": "aaronaustin/molestiae-tenetur", "url": "https://github.com/aaronaustin/molestiae-tenetur"}, "created_at": "2016-03-15 02:13:31"}, {"id": 4591339624, "type": "PushEvent", "actor": {"id": 1543690, "login": "harrislevi", "avatar_url": "https://avatars.com/1543690"}, "repo": {"id": 250873, "name": "harrislevi/sed-cumque-hic", "url": "https://github.com/harrislevi/sed-cumque-hic"}, "created_at": "2016-04-03 23:13:31"}, {"id": 4745170420, "type": "PushEvent", "actor": {"id": 4999205, "login": "mitchellpatricia", "avatar_url": "https://avatars.com/4999205"}, "repo": {"id": 131068, "name": "mitchellpatricia/id-cum-ea-quisquam", "url": "https://github.com/mitchellpatricia/id-cum-ea-quisquam"}, "created_at": "2016-06-02 20:13:31"}, {"id": 4915595498, "type": "PushEvent", "actor": {"id": 3744250, "login": "aphillips", "avatar_url": "https://avatars.com/3744250"}, "repo": {"id": 261062, "name": "aphillips/nostrum-alias-nihil", "url": "https://github.com/aphillips/nostrum-alias-nihil"}, "created_at": "2016-08-23 18:13:31"}], "headers": {"Content-Type": "application/json"}}}
65 | {"request": {"method": "GET", "url": "/actors", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [{"id": 3967160, "login": "crystal47", "avatar_url": "https://avatars.com/3967160"}, {"id": 3744250, "login": "aphillips", "avatar_url": "https://avatars.com/3744250"}, {"id": 4999205, "login": "mitchellpatricia", "avatar_url": "https://avatars.com/4999205"}, {"id": 1543690, "login": "harrislevi", "avatar_url": "https://avatars.com/1543690"}, {"id": 3709777, "login": "mary22", "avatar_url": "https://avatars.com/3709777"}, {"id": 2527143, "login": "kimberly97", "avatar_url": "https://avatars.com/2527143"}, {"id": 1784183, "login": "eortega", "avatar_url": "https://avatars.com/1784183"}, {"id": 3693687, "login": "stephen43", "avatar_url": "https://avatars.com/3693687"}, {"id": 4740807, "login": "lauradecker", "avatar_url": "https://avatars.com/4740807"}, {"id": 4120347, "login": "amy64", "avatar_url": "https://avatars.com/4120347"}, {"id": 1665468, "login": "brandonmcmahon", "avatar_url": "https://avatars.com/1665468"}, {"id": 4066703, "login": "cory72", "avatar_url": "https://avatars.com/4066703"}, {"id": 1125185, "login": "nwerner", "avatar_url": "https://avatars.com/1125185"}, {"id": 3749719, "login": "kelleyanna", "avatar_url": "https://avatars.com/3749719"}, {"id": 3692087, "login": "hawkinseric", "avatar_url": "https://avatars.com/3692087"}, {"id": 1507784, "login": "amanda40", "avatar_url": "https://avatars.com/1507784"}, {"id": 3447344, "login": "pkrause", "avatar_url": "https://avatars.com/3447344"}, {"id": 2259909, "login": "bridget53", "avatar_url": "https://avatars.com/2259909"}, {"id": 3843889, "login": "brian65", "avatar_url": "https://avatars.com/3843889"}, {"id": 2863822, "login": "heather04", "avatar_url": "https://avatars.com/2863822"}, {"id": 3830996, "login": "lopezbarry", "avatar_url": "https://avatars.com/3830996"}, {"id": 2172119, "login": "kristina09", "avatar_url": "https://avatars.com/2172119"}, {"id": 2520459, "login": "joy30", "avatar_url": "https://avatars.com/modified2"}, {"id": 3884464, "login": "burchwesley", "avatar_url": "https://avatars.com/3884464"}, {"id": 3084646, "login": "jonesrhonda", "avatar_url": "https://avatars.com/3084646"}, {"id": 3135921, "login": "oparker", "avatar_url": "https://avatars.com/3135921"}, {"id": 1154866, "login": "williamolson", "avatar_url": "https://avatars.com/1154866"}, {"id": 2782108, "login": "atkinsonemily", "avatar_url": "https://avatars.com/2782108"}, {"id": 2855645, "login": "adam00", "avatar_url": "https://avatars.com/2855645"}, {"id": 2102610, "login": "fjohnson", "avatar_url": "https://avatars.com/2102610"}, {"id": 4774666, "login": "brian06", "avatar_url": "https://avatars.com/4774666"}, {"id": 3791484, "login": "gmyers", "avatar_url": "https://avatars.com/3791484"}, {"id": 2846528, "login": "owenspatricia", "avatar_url": "https://avatars.com/2846528"}, {"id": 2435001, "login": "robertsondonald", "avatar_url": "https://avatars.com/2435001"}, {"id": 3254680, "login": "bradley49", "avatar_url": "https://avatars.com/3254680"}, {"id": 1150819, "login": "kelly06", "avatar_url": "https://avatars.com/1150819"}, {"id": 4148608, "login": "michael80", "avatar_url": "https://avatars.com/4148608"}, {"id": 3580452, "login": "jamesscott", "avatar_url": "https://avatars.com/3580452"}, {"id": 1646158, "login": "christyingram", "avatar_url": "https://avatars.com/1646158"}, {"id": 1266960, "login": "austin42", "avatar_url": "https://avatars.com/1266960"}, {"id": 1834821, "login": "carrie89", "avatar_url": "https://avatars.com/1834821"}, {"id": 1352530, "login": "mariah69", "avatar_url": "https://avatars.com/1352530"}, {"id": 2592501, "login": "davissteve", "avatar_url": "https://avatars.com/2592501"}, {"id": 4887912, "login": "alisha24", "avatar_url": "https://avatars.com/4887912"}, {"id": 3375972, "login": "alyssahendricks", "avatar_url": "https://avatars.com/3375972"}, {"id": 1487547, "login": "brittany76", "avatar_url": "https://avatars.com/1487547"}, {"id": 4157376, "login": "szhang", "avatar_url": "https://avatars.com/4157376"}, {"id": 4467597, "login": "adamhenderson", "avatar_url": "https://avatars.com/4467597"}, {"id": 3213163, "login": "sandy34", "avatar_url": "https://avatars.com/3213163"}, {"id": 3338029, "login": "noahball", "avatar_url": "https://avatars.com/3338029"}, {"id": 3422812, "login": "davidgonzalez", "avatar_url": "https://avatars.com/3422812"}, {"id": 1243932, "login": "jonathanhoffman", "avatar_url": "https://avatars.com/1243932"}, {"id": 1926441, "login": "fhill", "avatar_url": "https://avatars.com/1926441"}, {"id": 1432556, "login": "tedwards", "avatar_url": "https://avatars.com/1432556"}, {"id": 4123208, "login": "trevorhernandez", "avatar_url": "https://avatars.com/4123208"}, {"id": 4423526, "login": "andrew83", "avatar_url": "https://avatars.com/4423526"}, {"id": 1087596, "login": "jason96", "avatar_url": "https://avatars.com/1087596"}, {"id": 1669333, "login": "dariushernandez", "avatar_url": "https://avatars.com/1669333"}, {"id": 2151966, "login": "fbailey", "avatar_url": "https://avatars.com/2151966"}], "headers": {"Content-Type": "application/json"}}}
66 | {"request": {"method": "DELETE", "url": "/erase", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": {}, "headers": {}}}
67 | {"request": {"method": "GET", "url": "/events", "headers": {}, "body": {}}, "response": {"status_code": 200, "body": [], "headers": {"Content-Type": "application/json"}}}
--------------------------------------------------------------------------------
/find-odd-number/Exercise.java:
--------------------------------------------------------------------------------
1 | public class Exercise {
2 | public static void main(String[] args) {
3 | Integer[] arr = new Integer[] {7,8,4,5,5,8,7,8,8,4};
4 |
5 | System.out.println(hashSetSolution(arr));
6 | System.out.println(xorSolution(arr));
7 | }
8 |
9 | private static Set hashSetSolution(Integer[] arr) {
10 | Set ans = new HashSet<>();
11 | for(Integer a: arr) {
12 | int v = 1;
13 | if(ans.contains(a)) {
14 | ans.remove(a);
15 | } else {
16 | ans.add(a);
17 | }
18 | }
19 | return ans;
20 | }
21 |
22 | private static Integer xorSolution(Integer[] arr) {
23 | Integer xor = 0;
24 | for(Integer n: arr) {
25 | xor = xor^n;
26 | }
27 | return xor;
28 | }
29 | }
--------------------------------------------------------------------------------
/merge-order-two-arrays/Exercise.java:
--------------------------------------------------------------------------------
1 | public class Exercise {
2 |
3 | public static void main(String[] args) {
4 | int a [] = {3,5,7,9,12,14, 15};
5 | int b [] = {6 ,7, 10};
6 |
7 | int[] answer = new int[a.length + b.length];
8 | int i = a.length - 1, j = b.length - 1, k = answer.length;
9 |
10 | while (k > 0) {
11 | if(j < 0 || (i >= 0 && a[i] >= b[j])) {
12 | answer[--k] = a[i--];
13 | } else {
14 | answer[--k] = b[j--];
15 | }
16 | }
17 |
18 | System.out.println(answer);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/product-arrays/Exercise.java:
--------------------------------------------------------------------------------
1 | public class Exercise {
2 | public static void main(String[] args) {
3 | List input = Arrays.asList(1,2,3,4);
4 | Integer[] outp = new Integer[input.size()];
5 | for(int i = 0; i < input.size(); i++) {
6 | outp[i] = multi(i, input);
7 | }
8 | System.out.println(Arrays.asList(outp));
9 | }
10 |
11 | private static Integer multi(Integer ignore, List input) {
12 | Integer res = 1;
13 | for(int j = 0; j < input.size(); j++) {
14 | if(j != ignore) {
15 | res = res * input.get(j);
16 | }
17 | }
18 | return res;
19 | }
20 | }
--------------------------------------------------------------------------------
/stream-sugestions/main/java/com/streams/model/Author.java:
--------------------------------------------------------------------------------
1 | package com.streams.model;
2 |
3 | public class Author {
4 |
5 | private String firstName;
6 | private String lastName;
7 |
8 | public Author(String firstName, String lastName) {
9 | this.firstName = firstName;
10 | this.lastName = lastName;
11 | }
12 |
13 | public String getFirstName() {
14 | return firstName;
15 | }
16 |
17 | public void setFirstName(String firstName) {
18 | this.firstName = firstName;
19 | }
20 |
21 | public String getLastName() {
22 | return lastName;
23 | }
24 |
25 | public void setLastName(String lastName) {
26 | this.lastName = lastName;
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/stream-sugestions/main/java/com/streams/model/Book.java:
--------------------------------------------------------------------------------
1 | package com.streams.model;
2 |
3 | public class Book {
4 |
5 | private final Author author;
6 |
7 | private final String title;
8 |
9 | private final String isbn;
10 |
11 | private final Genre genre;
12 |
13 | private int rating;
14 |
15 | public Book(Author author, String title, String isbn, Genre genre) {
16 | this.author = author;
17 | this.title = title;
18 | this.isbn = isbn;
19 | this.genre = genre;
20 | }
21 |
22 | public Book(Author author, String title, String isbn, Genre genre, int rating) {
23 | validate(rating);
24 | this.author = author;
25 | this.title = title;
26 | this.isbn = isbn;
27 | this.genre = genre;
28 | this.rating = rating;
29 | }
30 |
31 | private void validate(int rating) {
32 | if (rating > 5 || rating < 1) {
33 | throw new IllegalArgumentException();
34 | }
35 | }
36 |
37 | public Author getAuthor() {
38 | return author;
39 | }
40 |
41 | public String getTitle() {
42 | return title;
43 | }
44 |
45 | public String getIsbn() {
46 | return isbn;
47 | }
48 |
49 | public int getRating() {
50 | return rating;
51 | }
52 |
53 | public void setRating(int rating) {
54 | validate(rating);
55 | this.rating = rating;
56 | }
57 |
58 | public Genre getGenre() {
59 | return genre;
60 | }
61 |
62 | @Override
63 | public int hashCode() {
64 | int result = author != null ? author.hashCode() : 0;
65 | result = 31 * result + (title != null ? title.hashCode() : 0);
66 | result = 31 * result + (isbn != null ? isbn.hashCode() : 0);
67 | result = 31 * result + (genre != null ? genre.hashCode() : 0);
68 | result = 31 * result + rating;
69 | return result;
70 | }
71 |
72 | @Override
73 | public boolean equals(Object o) {
74 | if (this == o) return true;
75 | if (o == null || getClass() != o.getClass()) return false;
76 |
77 | Book book = (Book) o;
78 |
79 | if (rating != book.rating) return false;
80 | if (author != null ? !author.equals(book.author) : book.author != null) return false;
81 | if (title != null ? !title.equals(book.title) : book.title != null) return false;
82 | if (isbn != null ? !isbn.equals(book.isbn) : book.isbn != null) return false;
83 | return genre == book.genre;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/stream-sugestions/main/java/com/streams/model/Genre.java:
--------------------------------------------------------------------------------
1 | package com.streams.model;
2 |
3 | public enum Genre {
4 |
5 | FICTION,
6 | HORROR,
7 | COMEDY,
8 | DRAMA,
9 | NON_FICTION,
10 | REALISTIC,
11 | ROMANTIC,
12 | TECH,
13 | TRAGEDY,
14 | FANTASY
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/stream-sugestions/main/java/com/streams/model/Reader.java:
--------------------------------------------------------------------------------
1 | package com.streams.model;
2 |
3 | import java.util.Set;
4 |
5 | import com.google.common.collect.Sets;
6 |
7 | public class Reader {
8 |
9 | private final Set favouriteBooks = Sets.newHashSet();
10 | private final Set favouriteGenres = Sets.newHashSet();
11 | private int age;
12 |
13 | public Reader(int age) {
14 | this.age = age;
15 | }
16 |
17 | public void addToFavourites(Book book) {
18 | favouriteBooks.add(book);
19 | }
20 |
21 | public void addToFavourites(Genre genre) {
22 | favouriteGenres.add(genre);
23 | }
24 |
25 | public void removeFromFavourites(Book book) {
26 | favouriteBooks.remove(book);
27 | }
28 |
29 | public void removeFromFavourites(Genre genre) {
30 | favouriteGenres.remove(genre);
31 | }
32 |
33 | public int getAge() {
34 | return age;
35 | }
36 |
37 | public Set getFavouriteBooks() {
38 | return Sets.newHashSet(favouriteBooks);
39 | }
40 |
41 | public Set getFavouriteGenres() {
42 | return Sets.newHashSet(favouriteGenres);
43 | }
44 |
45 | @Override
46 | public int hashCode() {
47 | int result = favouriteBooks.hashCode();
48 | result = 31 * result + favouriteGenres.hashCode();
49 | result = 31 * result + age;
50 | return result;
51 | }
52 |
53 | @Override
54 | public boolean equals(Object o) {
55 | if (this == o) return true;
56 | if (o == null || getClass() != o.getClass()) return false;
57 |
58 | Reader reader = (Reader) o;
59 |
60 | if (age != reader.age) return false;
61 | if (!favouriteBooks.equals(reader.favouriteBooks)) return false;
62 | return favouriteGenres.equals(reader.favouriteGenres);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/stream-sugestions/main/java/com/streams/services/SuggestionService.java:
--------------------------------------------------------------------------------
1 | package com.streams.services;
2 |
3 | import java.util.Set;
4 | import java.util.HashSet;
5 | import java.util.stream.Collectors;
6 |
7 | import com.streams.model.Author;
8 | import com.streams.model.Book;
9 | import com.streams.model.Reader;
10 | import com.streams.model.Genre;
11 |
12 | class SuggestionService {
13 |
14 | private final Set books;
15 | private final Set readers;
16 |
17 | public SuggestionService(Set books, Set readers) {
18 | this.books = books;
19 | this.readers = readers;
20 | }
21 |
22 | Set suggestBooks(Reader reader) {
23 | Set favGenres = reader.getFavouriteGenres();
24 |
25 | return books.stream()
26 | .filter(b -> b.getRating() >= 4)
27 | .filter(b -> favGenres.contains(b.getGenre()))
28 | .filter(b -> favBooksSameAge(reader).contains(b))
29 | .map(b -> b.getTitle())
30 | .collect(Collectors.toSet());
31 | }
32 |
33 | Set suggestBooks(Reader reader, int rating) {
34 | Set favGenres = reader.getFavouriteGenres();
35 |
36 | return books.stream()
37 | .filter(b -> b.getRating() >= rating)
38 | .filter(b -> favGenres.contains(b.getGenre()))
39 | .filter(b -> favBooksSameAge(reader).contains(b))
40 | .map(b -> b.getTitle())
41 | .collect(Collectors.toSet());
42 | }
43 |
44 | Set suggestBooks(Reader reader, Author author) {
45 | Set favGenres = reader.getFavouriteGenres();
46 |
47 | return books.stream()
48 | .filter(b -> b.getRating() >= 4)
49 | .filter(b -> favGenres.contains(b.getGenre()))
50 | .filter(b -> favBooksSameAge(reader).contains(b))
51 | .filter(b -> b.getAuthor().equals(author))
52 | .map(b -> b.getTitle())
53 | .collect(Collectors.toSet());
54 | }
55 |
56 | private Set favBooksSameAge(Reader reader) {
57 | Set setReaders = readers.stream()
58 | .filter(r -> reader.getAge() == r.getAge())
59 | .filter(r -> !reader.equals(r))
60 | .collect(Collectors.toSet());
61 |
62 | Set favBooks = new HashSet<>();
63 | setReaders.forEach(r -> favBooks.addAll(r.getFavouriteBooks()));
64 | return favBooks;
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/stream-sugestions/test/java/com/streams/services/SuggestionServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.streams.services;
2 |
3 | import java.util.Set;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 |
8 | import com.streams.model.Author;
9 | import com.streams.model.Book;
10 | import com.streams.model.Reader;
11 |
12 | import static com.streams.model.Genre.FANTASY;
13 | import static com.streams.model.Genre.NON_FICTION;
14 | import static com.streams.model.Genre.TECH;
15 | import static com.google.common.collect.Sets.newHashSet;
16 | import static org.assertj.core.api.Assertions.assertThat;
17 |
18 | public class SuggestionServiceTest {
19 |
20 |
21 | private Author jemisin = new Author("N.K.", "Jemisin");
22 | private Author bloch = new Author("Joshua", "Bloch");
23 | private Author neuvel = new Author("Sylvain", "Neuvel");
24 | private Author duckworth = new Author("Angela", "Duckworth");
25 | private Author bennett = new Author("Robert", "Bennett");
26 | private Book fifthSeason = new Book(jemisin, "The Fifth Season", "0316229296", FANTASY, 5);
27 | private Book obeliskGate = new Book(jemisin, "The Obelisk Gate", "0356508366", FANTASY, 4);
28 | private Book sleepingGiants = new Book(neuvel, "Sleeping Giants", "1101886692", FANTASY, 3);
29 | private Book effectiveJava = new Book(bloch, "Effective Java", " 0321356683", TECH, 5);
30 | private Book cityOfStairs = new Book(bennett, "City of Stairs", "080413717X", FANTASY, 5);
31 | private Book grit = new Book(duckworth, "Grit", "1501111108", NON_FICTION, 5);
32 | private Reader sara = new Reader(18);
33 | private Reader john = new Reader(18);
34 | private Reader anastasia = new Reader(44);
35 | private SuggestionService suggestionService;
36 |
37 | @Before
38 | public void setUp() {
39 | sara.addToFavourites(FANTASY);
40 | sara.addToFavourites(TECH);
41 | john.addToFavourites(obeliskGate);
42 | john.addToFavourites(fifthSeason);
43 | john.addToFavourites(sleepingGiants);
44 | john.addToFavourites(effectiveJava);
45 | anastasia.addToFavourites(cityOfStairs);
46 | Set books = newHashSet(fifthSeason, obeliskGate, sleepingGiants, effectiveJava, cityOfStairs, grit);
47 | Set readers = newHashSet(sara, john, anastasia);
48 | suggestionService = new SuggestionService(books, readers);
49 | }
50 |
51 |
52 | @Test
53 | public void shouldSuggestBookTitlesWithCorrectRating() throws Exception {
54 | // when:
55 | Set suggestedBooks = suggestionService.suggestBooks(sara, 5);
56 |
57 | // then:
58 | assertThat(suggestedBooks).isEqualTo(newHashSet(fifthSeason.getTitle(), effectiveJava.getTitle()));
59 | }
60 |
61 | @Test
62 | public void shouldSuggestBookTitlesWithDefaultRatingOfFourOrHigher() throws Exception {
63 | // when:
64 | Set suggestedBooks = suggestionService.suggestBooks(sara);
65 |
66 | // then:
67 | assertThat(suggestedBooks).isEqualTo(newHashSet(fifthSeason.getTitle(), obeliskGate.getTitle(),
68 | effectiveJava.getTitle()));
69 | }
70 |
71 | @Test
72 | public void shouldOnlySuggestBookTitlesFromReadersFavouriteGenres() throws Exception {
73 | // when:
74 | Set suggestedBooks = suggestionService.suggestBooks(sara);
75 |
76 | // then:
77 | assertThat(suggestedBooks).doesNotContain(grit.getTitle());
78 | assertThat(suggestedBooks).contains(obeliskGate.getTitle());
79 | assertThat(suggestedBooks).contains(effectiveJava.getTitle());
80 | }
81 |
82 | @Test
83 | public void shouldOnlySuggestBookTitlesLikedByOtherReadersOfTheSameAge() {
84 | // when:
85 | Set suggestedBooks = suggestionService.suggestBooks(sara);
86 |
87 | // then:
88 | assertThat(suggestedBooks).doesNotContain(cityOfStairs.getTitle());
89 | assertThat(suggestedBooks).contains(obeliskGate.getTitle());
90 | }
91 |
92 | @Test
93 | public void shouldOnlySuggestBookTitlesOfGivenAuthor() {
94 | // when:
95 | Set suggestedBooks = suggestionService.suggestBooks(sara, jemisin);
96 |
97 | // then:
98 | assertThat(suggestedBooks).isEqualTo(newHashSet(fifthSeason.getTitle(), obeliskGate.getTitle()));
99 | }
100 |
101 | }
--------------------------------------------------------------------------------
/subarray-length/Application.java:
--------------------------------------------------------------------------------
1 | /*
2 | For an array of integers and a number x, find the minimal length subarray with sum greater than the given value.
3 |
4 | Examples:
5 | array = {1, 4, 45, 6, 0, 19}
6 | x = 51
7 | Output: 3
8 | Minimum length subarray is {4, 45, 6}
9 |
10 | array = {1, 10, 5, 2, 7}
11 | x = 9
12 | Output: 1
13 | Minimum length subarray is {10}
14 | */
15 | public class Application {
16 | public static void main(String[] args) {
17 | Integer x = 9;
18 | List arr = Arrays.asList(1, 10, 5, 2, 7);
19 |
20 | Integer len = 0;
21 | for (Integer i = 0; i < arr.size(); i++) {
22 | Integer s = 0;
23 | for (Integer j = i; j < arr.size(); j++) {
24 | s = s + arr.get(j);
25 | if (s > x
26 | && (len > (j - i + 1) || len == 0)) {
27 | len = (j - i) + 1;
28 | }
29 | }
30 | }
31 | System.out.println("len: " + len);
32 | }
33 | }
--------------------------------------------------------------------------------
/sum-lcm-from-numbers/Exercise.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.Arrays;
3 | import java.util.List;
4 |
5 | public class Exercise {
6 |
7 | private static long solucao2_getSumOfLeastCommonMultiple(int input) {
8 | long result = 0;
9 | int sum = 0;
10 |
11 | for (int i = 0; i <= input; i++) {
12 | int gcd = 1;
13 | for (int j = 1; j <= input && j <= i; ++j) {
14 | // Checks if i is factor of both integers
15 | if (input % j == 0 && i % j == 0)
16 | gcd = j;
17 | }
18 |
19 | int lcm = (input * i) / gcd;
20 | if (lcm == input) {
21 | sum = sum + i;
22 | }
23 | }
24 | System.out.println("SUM: " + sum);
25 | return sum;
26 | }
27 |
28 | public static void solucao1_lcmSum(int array[]) {
29 |
30 | for (int j = 0; j < array.length; j++) {
31 | int lcmSum = 0;
32 | for (int i = 1; i <= array[j]; i++) {
33 |
34 | if (array[j] % i == 0)
35 | lcmSum = lcmSum + i;
36 |
37 | }
38 | System.out.println("lcmSum : " + lcmSum);
39 | }
40 |
41 | }
42 |
43 | private static int[] solucao3_getMaximumSumWithLCM(int[] numbers) {
44 | int[] ret = new int[numbers.length];
45 |
46 | for (int ii = 0; ii < numbers.length; ii++) {
47 | int number = numbers[ii];
48 | int sum = 0;
49 | int sqrt = (int) Math.sqrt(number);
50 |
51 | for (int i = 1; i <= sqrt; i++) {
52 |
53 | if (number % i == 0) {
54 |
55 | if (i == (number / i))
56 | sum += i;
57 | else
58 | sum += (i + number / i);
59 | }
60 | }
61 | ret[ii] = sum;
62 | }
63 |
64 | return ret;
65 | }
66 |
67 | private static long[] solucao7_maxSubsetSum2(int[] k) {
68 | int l = k.length;
69 | long[] sums = new long[l];
70 | for (int i=0;i result = new ArrayList<>();
150 |
151 | for (int element : arr) {
152 | int flag = 0;
153 | for(int i = 1; i <= element; i++){
154 | if(element % i == 0)
155 | flag += i;
156 | }
157 | result.add(flag);
158 | }
159 | System.out.println(result);
160 | }
161 |
162 | public static void main(String[] args) {
163 | int array[] = { 10, 4, 2, 12, 4 };
164 |
165 | System.out.println(System.currentTimeMillis());
166 | solucao1_lcmSum(array);
167 | System.out.println(System.currentTimeMillis());
168 |
169 |
170 | System.out.println(System.currentTimeMillis());
171 | long[] result = new long[array.length];
172 |
173 | for (int i = 0; i < array.length; i++) {
174 | result[i] = solucao2_getSumOfLeastCommonMultiple(array[i]);
175 | }
176 | System.out.println(result);
177 | System.out.println(System.currentTimeMillis());
178 |
179 |
180 | System.out.println(System.currentTimeMillis());
181 | int[] res = (solucao3_getMaximumSumWithLCM(array));
182 | for (int i = 0; i < res.length; i++) {
183 | System.out.println(res[i]);
184 | }
185 | System.out.println(System.currentTimeMillis());
186 |
187 |
188 | System.out.println(System.currentTimeMillis());
189 | System.out.println(Arrays.toString(solucao4_getSubsetSum(array)));
190 | System.out.println(System.currentTimeMillis());
191 |
192 |
193 | System.out.println(System.currentTimeMillis());
194 | int[] largestSubsetSum = solucao5_findLargestSubsetSum(array);
195 | printArray(largestSubsetSum);
196 | System.out.println(System.currentTimeMillis());
197 |
198 |
199 | System.out.println(System.currentTimeMillis());
200 | long maxSum[] = solucao6_maxSubsetSum(array);
201 | for (long sum : maxSum) {
202 | System.out.println(sum);
203 | }
204 | System.out.println(System.currentTimeMillis());
205 |
206 |
207 | System.out.println(System.currentTimeMillis());
208 | long[] arr = solucao7_maxSubsetSum2(array);
209 | for(long a: arr) {
210 | System.out.println(a);
211 | }
212 | System.out.println(System.currentTimeMillis());
213 |
214 |
215 | System.out.println(System.currentTimeMillis());
216 | solucao8_findLcm(array);
217 | System.out.println(System.currentTimeMillis());
218 |
219 |
220 | System.out.println(System.currentTimeMillis());
221 |
222 | System.out.println(System.currentTimeMillis());
223 |
224 | }
225 |
226 |
227 | }
228 |
--------------------------------------------------------------------------------
/vh-fair/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | .classpath
3 | .project
4 | /.settings/
5 |
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/digitalwallet/DigitalWallet.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/digitalwallet/DigitalWallet.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/digitalwallet/DigitalWalletTransaction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/digitalwallet/DigitalWalletTransaction.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/digitalwallet/Solution.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/digitalwallet/Solution.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/digitalwallet/TransactionException.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/digitalwallet/TransactionException.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/dostuff/HelloWorld.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/dostuff/HelloWorld.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/dostuff/Interf.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/dostuff/Interf.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/dostuff/Pancake.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/dostuff/Pancake.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/jsonstock/Solution$StockDataEntity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/jsonstock/Solution$StockDataEntity.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/jsonstock/Solution$StockEntity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/jsonstock/Solution$StockEntity.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/jsonstock/Solution.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/jsonstock/Solution.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/reformatdate/Solution.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/reformatdate/Solution.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/thread/Logger.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/thread/Logger.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/thread/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/thread/Main.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/thread/RunnableDemo.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/thread/RunnableDemo.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/workschedule/RightSolution.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/workschedule/RightSolution.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/workschedule/Solution.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/workschedule/Solution.class
--------------------------------------------------------------------------------
/vh-fair/bin/br/com/ironimedina/workschedule/Solution2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ironijunior/java-exercise/3edb8c3cedf3462b61167c736c2b4d9797ecb382/vh-fair/bin/br/com/ironimedina/workschedule/Solution2.class
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/digitalwallet/Solution.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.digitalwallet;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Scanner;
6 |
7 |
8 | /*
9 | * Create TransactionException, DigitalWallet, and DigitalWalletTransaction classes here.
10 | */
11 |
12 | class TransactionException extends Exception {
13 |
14 | private static final long serialVersionUID = -2711363784897761513L;
15 |
16 | private final String errorMessage;
17 | private final String errorCode;
18 |
19 | public TransactionException(String errorMessage, String errorCode) {
20 | super(errorMessage);
21 | this.errorMessage = errorMessage;
22 | this.errorCode = errorCode;
23 | }
24 |
25 | public String getErrorCode() {
26 | return this.errorCode;
27 | }
28 |
29 | }
30 |
31 | class DigitalWallet {
32 |
33 | private String walletId;
34 | private String userName;
35 | private String userAcessCode;
36 | private int walletBalance;
37 |
38 | public DigitalWallet(String walletId, String userName) {
39 | this.walletId = walletId;
40 | this.userName = userName;
41 | }
42 |
43 | public DigitalWallet(String walletId, String userName, String userAcessCode) {
44 | this.walletId = walletId;
45 | this.userName = userName;
46 | this.userAcessCode = userAcessCode;
47 | }
48 |
49 | public String getWalletId() {
50 | return this.walletId;
51 | }
52 |
53 | public String getUsername() {
54 | return this.userName;
55 | }
56 |
57 | public String getUserAccessToken() {
58 | return this.userAcessCode;
59 | }
60 |
61 | public int getWalletBalance() {
62 | return this.walletBalance;
63 | }
64 |
65 | public void setWalletBalance(int walletBalance) {
66 | this.walletBalance = walletBalance;
67 | }
68 | }
69 |
70 | class DigitalWalletTransaction {
71 |
72 | public void addMoney(DigitalWallet digitalWallet, int amount) throws TransactionException {
73 | validateTransaction(digitalWallet, amount, false);
74 | digitalWallet.setWalletBalance(digitalWallet.getWalletBalance() + amount);
75 | }
76 |
77 | public void payMoney(DigitalWallet digitalWallet, int amount) throws TransactionException {
78 | validateTransaction(digitalWallet, amount, true);
79 | digitalWallet.setWalletBalance(digitalWallet.getWalletBalance() - amount);
80 | }
81 |
82 | private void validateTransaction(DigitalWallet digitalWallet, int amount, boolean isPayment) throws TransactionException {
83 | validateAccessCode(digitalWallet);
84 | validateAmount(amount);
85 | if(isPayment) {
86 | validateBalance(digitalWallet, amount);
87 | }
88 | }
89 |
90 | private void validateAccessCode(DigitalWallet digitalWallet) throws TransactionException {
91 | if(digitalWallet.getUserAccessToken() == null) {
92 | throw new TransactionException("User not authorized", "USER_NOT_AUTHORIZED");
93 | }
94 | }
95 |
96 | private void validateAmount(int amount) throws TransactionException {
97 | if(amount <= 0) {
98 | throw new TransactionException("Amount should be greater than zero", "INVALID_AMOUNT");
99 | }
100 | }
101 |
102 | private void validateBalance(DigitalWallet digitalWallet, int amount) throws TransactionException {
103 | int balance = digitalWallet.getWalletBalance();
104 | if(amount > balance) {
105 | throw new TransactionException("Insufficient balance", "INSUFFICIENT_BALANCE");
106 | }
107 | }
108 |
109 | }
110 |
111 | public class Solution {
112 | private static final Scanner INPUT_READER = new Scanner(System.in);
113 | private static final DigitalWalletTransaction DIGITAL_WALLET_TRANSACTION = new DigitalWalletTransaction();
114 |
115 | private static final Map DIGITAL_WALLETS = new HashMap<>();
116 |
117 | public static void main(String[] args) {
118 | int numberOfWallets = Integer.parseInt(INPUT_READER.nextLine());
119 | while (numberOfWallets-- > 0) {
120 | String[] wallet = INPUT_READER.nextLine().split(" ");
121 | DigitalWallet digitalWallet;
122 |
123 | if (wallet.length == 2) {
124 | digitalWallet = new DigitalWallet(wallet[0], wallet[1]);
125 | } else {
126 | digitalWallet = new DigitalWallet(wallet[0], wallet[1], wallet[2]);
127 | }
128 |
129 | DIGITAL_WALLETS.put(wallet[0], digitalWallet);
130 | }
131 |
132 | int numberOfTransactions = Integer.parseInt(INPUT_READER.nextLine());
133 | while (numberOfTransactions-- > 0) {
134 | String[] transaction = INPUT_READER.nextLine().split(" ");
135 | DigitalWallet digitalWallet = DIGITAL_WALLETS.get(transaction[0]);
136 |
137 | if (transaction[1].equals("add")) {
138 | try {
139 | DIGITAL_WALLET_TRANSACTION.addMoney(digitalWallet, Integer.parseInt(transaction[2]));
140 | System.out.println("Wallet successfully credited.");
141 | } catch (TransactionException ex) {
142 | System.out.println(ex.getErrorCode() + ": " + ex.getMessage() + ".");
143 | }
144 | } else {
145 | try {
146 | DIGITAL_WALLET_TRANSACTION.payMoney(digitalWallet, Integer.parseInt(transaction[2]));
147 | System.out.println("Wallet successfully debited.");
148 | } catch (TransactionException ex) {
149 | System.out.println(ex.getErrorCode() + ": " + ex.getMessage() + ".");
150 | }
151 | }
152 | }
153 |
154 | System.out.println();
155 |
156 | DIGITAL_WALLETS.keySet()
157 | .stream()
158 | .sorted()
159 | .map((digitalWalletId) -> DIGITAL_WALLETS.get(digitalWalletId))
160 | .forEachOrdered((digitalWallet) -> {
161 | System.out.println(digitalWallet.getWalletId()
162 | + " " + digitalWallet.getUsername()
163 | + " " + digitalWallet.getWalletBalance());
164 | });
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/dostuff/HelloWorld.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.dostuff;
2 | import java.util.ArrayList;
3 | import java.util.List;
4 |
5 | public class HelloWorld implements Pancake {
6 |
7 | public static void main(String []args){
8 | List x = new ArrayList();
9 | x.add("3"); x.add("7"); x.add("5");
10 | List y = new HelloWorld().doStuff(x);
11 | y.add("1");
12 | System.out.println(x);
13 | }
14 |
15 | List doStuff(List s) {
16 | s.add("9");
17 | return s;
18 | }
19 | }
20 |
21 | interface Pancake {
22 | List doStuff(List s);
23 | }
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/dostuff/Interf.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.dostuff;
2 | import java.util.List;
3 |
4 | public interface Interf {
5 | List doStuff(List s);
6 | }
7 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/jsonstock/Solution.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.jsonstock;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 | import java.net.URL;
6 | import java.text.ParseException;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Arrays;
9 | import java.util.Calendar;
10 | import java.util.Date;
11 | import java.util.List;
12 | import java.util.Locale;
13 |
14 | import com.google.gson.Gson;
15 |
16 | public class Solution {
17 |
18 | private static final List DAYS = Arrays.asList("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
19 | "Saturday");
20 |
21 | public static void main(String[] args) {
22 | openAndClosePrices("1-January-2000", "22-February-2000", "Monday");
23 | }
24 |
25 | public static void openAndClosePrices(String firstDate, String lastDate, String weekDay) {
26 | String stocksJson = "";
27 | try {
28 | stocksJson = getContentFrom("https://jsonmock.hackerrank.com/api/stocks");
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | }
32 |
33 | Gson gson = new Gson();
34 | StockEntity stockEntity = gson.fromJson(stocksJson, StockEntity.class);
35 |
36 | stockEntity.getData().stream()
37 | .filter((stockData) -> hasDateMatching(stockData, firstDate, lastDate, weekDay))
38 | .forEach((stockData) -> {
39 | StringBuilder result = new StringBuilder(stockData.getDate());
40 | result.append(" ")
41 | .append(stockData.getOpen())
42 | .append(" ")
43 | .append(stockData.getClose());
44 |
45 | System.out.println(result.toString());
46 | });
47 | }
48 |
49 | private static String getContentFrom(String urlString) throws Exception {
50 | BufferedReader reader = null;
51 | try {
52 | URL url = new URL(urlString);
53 | reader = new BufferedReader(new InputStreamReader(url.openStream()));
54 | StringBuffer buffer = new StringBuffer();
55 | int read;
56 | char[] chars = new char[1024];
57 | while ((read = reader.read(chars)) != -1) {
58 | buffer.append(chars, 0, read);
59 | }
60 | return buffer.toString();
61 | } finally {
62 | if (reader != null)
63 | reader.close();
64 | }
65 | }
66 |
67 | private static boolean hasDateMatching(StockDataEntity stockData, String firstDate, String lastDate, String weekDay) {
68 | try {
69 | return (parseDate(stockData.date).compareTo(parseDate(firstDate)) >= 0)
70 | && (parseDate(stockData.date).compareTo(parseDate(lastDate)) <= 0)
71 | && (getDayOfDate(stockData.date) == (DAYS.indexOf(weekDay) + 1));
72 | } catch (ParseException e) {
73 | e.printStackTrace();
74 | }
75 | return false;
76 | }
77 |
78 | private static Date parseDate(String date) throws ParseException {
79 | return new SimpleDateFormat("dd-MMM-yyyy", Locale.US).parse(date);
80 | }
81 |
82 | private static int getDayOfDate(String date) throws ParseException {
83 | Calendar calendar = Calendar.getInstance();
84 | calendar.setTime(parseDate(date));
85 | return calendar.get(Calendar.DAY_OF_WEEK);
86 | }
87 |
88 | class StockDataEntity {
89 |
90 | private String date;
91 | private float open;
92 | private float high;
93 | private float low;
94 | private float close;
95 |
96 | public String getDate() {
97 | return date;
98 | }
99 |
100 | public void setDate(String date) {
101 | this.date = date;
102 | }
103 |
104 | public float getOpen() {
105 | return open;
106 | }
107 |
108 | public void setOpen(float open) {
109 | this.open = open;
110 | }
111 |
112 | public float getHigh() {
113 | return high;
114 | }
115 |
116 | public void setHigh(float high) {
117 | this.high = high;
118 | }
119 |
120 | public float getLow() {
121 | return low;
122 | }
123 |
124 | public void setLow(float low) {
125 | this.low = low;
126 | }
127 |
128 | public float getClose() {
129 | return close;
130 | }
131 |
132 | public void setClose(float close) {
133 | this.close = close;
134 | }
135 | }
136 |
137 | class StockEntity {
138 |
139 | private Integer page;
140 | private Integer perPage;
141 | private Integer total;
142 | private Integer totalPages;
143 | private List data = null;
144 |
145 | public Integer getPage() {
146 | return page;
147 | }
148 |
149 | public void setPage(Integer page) {
150 | this.page = page;
151 | }
152 |
153 | public Integer getPerPage() {
154 | return perPage;
155 | }
156 |
157 | public void setPerPage(Integer perPage) {
158 | this.perPage = perPage;
159 | }
160 |
161 | public Integer getTotal() {
162 | return total;
163 | }
164 |
165 | public void setTotal(Integer total) {
166 | this.total = total;
167 | }
168 |
169 | public Integer getTotalPages() {
170 | return totalPages;
171 | }
172 |
173 | public void setTotalPages(Integer totalPages) {
174 | this.totalPages = totalPages;
175 | }
176 |
177 | public List getData() {
178 | return data;
179 | }
180 |
181 | public void setData(List data) {
182 | this.data = data;
183 | }
184 | }
185 |
186 | }
187 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/reformatdate/Solution.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.reformatdate;
2 |
3 | import java.io.IOException;
4 | import java.time.LocalDate;
5 | import java.time.format.DateTimeFormatter;
6 | import java.util.ArrayList;
7 | import java.util.Arrays;
8 | import java.util.List;
9 | import java.util.Locale;
10 |
11 | public class Solution {
12 |
13 | public static void main(String[] args) throws IOException {
14 | final List dates = Arrays.asList("20th Oct 2052", "6th Jun 1933", "26th May 1960", "20th Sep 1958",
15 | "16th Mar 2068", "25th May 1912", "16th Dec 2018", "26th Dec 2061", "4th Nov 2030", "28th Jul 1963");
16 | List result = reformatDate(dates);
17 | System.out.println(result);
18 | }
19 |
20 | /*
21 | * Complete the 'reformatDate' function below.
22 | *
23 | * The function is expected to return a STRING_ARRAY. The function accepts
24 | * STRING_ARRAY dates as parameter.
25 | */
26 |
27 | public static List reformatDate(List dates) {
28 | DateTimeFormatter dtFormat = DateTimeFormatter.ofPattern(
29 | "d['st']['nd']['rd']['th'] MMM yyyy", Locale.ENGLISH);
30 |
31 | List formattedDates = new ArrayList<>();
32 | for (String date : dates) {
33 | LocalDate fDate = LocalDate.parse(date, dtFormat);
34 | formattedDates.add(fDate.toString());
35 | }
36 |
37 | return formattedDates;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/thread/Logger.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.thread;
2 |
3 | public class Logger {
4 |
5 | private StringBuilder contents = new StringBuilder();
6 |
7 | public void log(String msg) {
8 | contents.append(System.currentTimeMillis());
9 | contents.append(": ");
10 | contents.append(Thread.currentThread().getName());
11 | contents.append(msg);
12 | contents.append("\n");
13 | }
14 |
15 | public String getContent() {
16 | return contents.toString();
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/thread/Main.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.thread;
2 |
3 | public class Main {
4 |
5 | public static void main(String args[]) {
6 | RunnableDemo R1 = new RunnableDemo("Thread-1");
7 | R1.start();
8 |
9 | RunnableDemo R2 = new RunnableDemo("Thread-2");
10 | R2.start();
11 |
12 | System.out.println(new Logger().getContent());
13 | Double d = new Double("1234567890123456789012345");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/thread/RunnableDemo.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.thread;
2 |
3 | class RunnableDemo implements Runnable {
4 | private Thread t;
5 | private String threadName;
6 |
7 | public RunnableDemo(String name) {
8 | threadName = name;
9 | System.out.println("Creating " + threadName);
10 | }
11 |
12 | public void run() {
13 | System.out.println("Running " + threadName);
14 | Logger log = new Logger();
15 | try {
16 | for (int i = 4; i > 0; i--) {
17 | System.out.println("Thread: " + threadName + ", " + i);
18 | log.log("MSG");
19 | // Let the thread sleep for a while.
20 | Thread.sleep(50);
21 | }
22 | } catch (InterruptedException e) {
23 | System.out.println("Thread " + threadName + " interrupted.");
24 | }
25 | System.out.println("Thread " + threadName + " exiting.");
26 | }
27 |
28 | public void start() {
29 | System.out.println("Starting " + threadName);
30 | if (t == null) {
31 | t = new Thread(this, threadName);
32 | t.start();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/workschedule/RightSolution.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.workschedule;
2 |
3 | import java.util.LinkedList;
4 | import java.util.List;
5 |
6 | public class RightSolution {
7 |
8 | public static List findSchedules(int workHours, int dayHours, String pattern) {
9 | // Write your code here
10 |
11 | int sum = 0;
12 | int count = 0;
13 | for (int i = 0; i < pattern.length(); i++) {
14 | if (pattern.charAt(i) != '?') {
15 | sum += Character.getNumericValue(pattern.charAt(i));
16 | count += 1;
17 | }
18 | }
19 |
20 | LinkedList> resultAfterFilling = findSchedulesHelper(pattern.length() - count, workHours - sum, dayHours, new String());
21 |
22 | LinkedList res = new LinkedList<>();
23 | for (LinkedList str:resultAfterFilling) {
24 | StringBuilder pat = new StringBuilder(pattern);
25 |
26 | String s = str.removeFirst();
27 | for (int i = 0; i < s.length(); i++) {
28 | int index = pat.indexOf("?");
29 | pat.setCharAt(index, s.charAt(i));
30 | }
31 | res.add(pat.toString());
32 |
33 | }
34 |
35 | return res;
36 | }
37 |
38 | private static LinkedList> findSchedulesHelper(int k, int workHours, int dayHours, String res) {
39 | if (k * dayHours < workHours) {
40 | return null;
41 | }
42 | if (k == 1) {
43 | res += Integer.toString(workHours);
44 | LinkedList lst = new LinkedList<>();
45 | LinkedList> a = new LinkedList<>();
46 | lst.add(res);
47 | a.add(lst);
48 | return a;
49 | }
50 |
51 | LinkedList> result = new LinkedList<>();
52 | for (int i = 0; i <= dayHours; i++) {
53 | if (workHours - i < 0) {
54 | break;
55 | }
56 | LinkedList> subRes = findSchedulesHelper(k - 1, workHours - i, dayHours, new String(res) + Integer.toString(i));
57 | if (subRes != null) {
58 | result.addAll(subRes);
59 | }
60 | }
61 | return result;
62 | }
63 |
64 | public static void main(String[] args) {
65 | // System.out.println(RightSolution.findSchedules(3, 2, "??2??00"));
66 | // System.out.println(RightSolution.findSchedules(56, 8, "??8????"));
67 | // System.out.println(RightSolution.findSchedules(24, 4, "08??840"));
68 | System.out.println(RightSolution.findSchedules(13, 2, "??2??00"));
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/workschedule/Solution.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.workschedule;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Solution {
7 |
8 | public static List findSchedules(int workHours, int dayHours, String pattern) {
9 | Long daysToSolve = pattern.chars().filter(ch -> ch =='?').count();
10 | Integer usedHours = 0;
11 | for(int i = 0; i < pattern.toCharArray().length; i++) {
12 | if(Character.isDigit(pattern.toCharArray()[i])) {
13 | usedHours += Character.getNumericValue(pattern.toCharArray()[i]);
14 | }
15 | }
16 | Integer remainingHours = workHours - usedHours;
17 |
18 | List schedule = new ArrayList<>();
19 |
20 | List permutedDays = permuteDays(remainingHours, daysToSolve, dayHours);
21 | for(int i = 0; i < permutedDays.size(); i++) {
22 | String newSch = permutedDays.get(i);
23 | String cpPattern = pattern;
24 | for(Character ch: newSch.toCharArray()) {
25 | cpPattern = cpPattern.replaceFirst("\\?", String.valueOf(ch));
26 | }
27 | schedule.add(cpPattern);
28 | }
29 |
30 | return schedule;
31 | }
32 |
33 | private static List permuteDays(Integer remainingHours, Long daysToSolve, Integer dayHours) {
34 | List permuted = new ArrayList<>();
35 |
36 | if(remainingHours % daysToSolve == 0
37 | && remainingHours/daysToSolve == dayHours) {
38 | StringBuilder sb = new StringBuilder();
39 | for(int i = 0; i < daysToSolve; i++) {
40 | sb.append(remainingHours/daysToSolve);
41 | }
42 | permuted.add(sb.toString());
43 | } else if(remainingHours < daysToSolve/dayHours){
44 | for(int i = 0; i < daysToSolve; i++) {
45 |
46 | }
47 | } else {
48 | for(int i = 0; i <= remainingHours; i++) {
49 | permuted.add(i + "" + (remainingHours-i));
50 | }
51 | }
52 | return permuted;
53 | }
54 |
55 | private static List permute(String str, int l, int r, List lst) {
56 |
57 | if (l == r) {
58 | lst.add(str);
59 | } else {
60 | for (int i = l; i <= r; i++) {
61 | str = swap(str,l,i);
62 | permute(str, l+1, r, lst);
63 | str = swap(str,l,i);
64 | }
65 | }
66 | return lst;
67 | }
68 |
69 | public static String swap(String a, int i, int j) {
70 | char temp;
71 | char[] charArray = a.toCharArray();
72 | temp = charArray[i] ;
73 | charArray[i] = charArray[j];
74 | charArray[j] = temp;
75 | return String.valueOf(charArray);
76 | }
77 |
78 | public static void main(String[] args) {
79 | //System.out.println(findSchedules(3, 2, "??2??00"));
80 | // System.out.println(findSchedules(56, 8, "??8????"));
81 | System.out.println(findSchedules(24, 4, "08??840"));
82 | List lst = new ArrayList<>();
83 | // System.out.println(permute("ABC", 0, "ABC".length()-1, lst));
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/vh-fair/src/br/com/ironimedina/workschedule/Solution2.java:
--------------------------------------------------------------------------------
1 | package br.com.ironimedina.workschedule;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 |
7 | public class Solution2 {
8 |
9 | public static List findSchedules(int workHours, int dayHours, String pattern) {
10 | List res = new ArrayList<>();
11 | int questions = 7;
12 | for (char c : pattern.toCharArray()) {
13 | if (Character.isDigit(c)) {
14 | workHours -= Character.getNumericValue(c);
15 | questions--;
16 | }
17 | }
18 | if (workHours < 0) {
19 | return null;
20 | }
21 | DFS(workHours, dayHours, pattern.toCharArray(), 0, res, questions);
22 | return res;
23 | }
24 |
25 | private static void DFS(int workHours, int dayHours, char[] pattern, int charAt, List res, int questions) {
26 | if (charAt == 7) {
27 | if (workHours == 0) {
28 | res.add(String.valueOf(pattern));
29 | }
30 | } else if (questions * dayHours >= workHours) {
31 | if (pattern[charAt] == '?') {
32 | for (int i = 0; i <= dayHours; i++) {
33 | char[] newPattern = Arrays.copyOf(pattern, pattern.length);
34 | newPattern[charAt] = (char) (i + '0');
35 | DFS(workHours - i, dayHours, newPattern, charAt + 1, res, questions - 1);
36 | }
37 | } else {
38 | DFS(workHours, dayHours, pattern, charAt + 1, res, questions);
39 | }
40 | }
41 | }
42 |
43 | public static List findSchedule(int workHours, int dayHours, String pattern) {
44 | char[] pat = pattern.toCharArray();
45 | int target = workHours;
46 | int count = 0;
47 | List pos = new ArrayList<>();
48 | int id = 0;
49 | for (char one : pat) {
50 | if (one != '?')
51 | target -= Character.getNumericValue(one);
52 | else {
53 | count++;
54 | pos.add(id);
55 | }
56 | id++;
57 | }
58 | List> ans = new ArrayList<>();
59 | combinationSum(ans, new ArrayList(), count, target, dayHours);
60 | List res = new ArrayList<>();
61 | for (List one : ans) {
62 | StringBuilder sb = new StringBuilder(pattern);
63 | int j = 0;
64 | for (Integer i : one) {
65 | char c = (char) (i + '0');
66 | sb.setCharAt(pos.get(j), c);
67 | j++;
68 | }
69 | res.add(sb.toString());
70 | }
71 | return res;
72 | }
73 |
74 | private static void combinationSum(List> ans, List one, int count, int target, int limit) {
75 | if (count == 0 && target == 0) {
76 | ans.add(new ArrayList<>(one));
77 | return;
78 | } else if (count == 0)
79 | return;
80 | for (int i = 0; i <= limit; i++) {
81 | one.add(i);
82 | combinationSum(ans, one, count - 1, target - i, limit);
83 | one.remove(one.size() - 1);
84 | }
85 | }
86 |
87 | public static void main(String[] args) {
88 | String patter = "88?8?8?";
89 | System.out.println("-----------------------------------------------------");
90 | for (String one : findSchedules(54, 9, patter)) {
91 | System.out.print(one);
92 | int sum = 0;
93 | for (char ch : one.toCharArray()) {
94 | sum += Character.getNumericValue(ch);
95 | }
96 | System.out.println(" " + sum);
97 | }
98 | System.out.println("-----------------------------------------------------");
99 | System.out.println(findSchedules(3, 2, "??2??00"));
100 | System.out.println(findSchedules(56, 8, "??8????"));
101 | System.out.println(findSchedules(24, 4, "08??840"));
102 | System.out.println(findSchedules(13, 2, "??2??00"));
103 |
104 | System.out.println("");
105 | System.out.println(findSchedule(3, 2, "??2??00"));
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------