This repository was archived by the owner on Feb 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Completed solution #4
Open
tboychuk
wants to merge
56
commits into
master
Choose a base branch
from
exercise/completed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 38 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
8fe7434
Implement LinkedQueue.java
tboychuk f5a4dde
Fix logic to follow FIFO rule
tboychuk 1478575
Merge branch 'master' into exercise/completed
tboychuk 79f73f3
Merge branch 'master' into exercise/completed
tboychuk 3b46dca
Merge branch 'master' into exercise/completed
tboychuk e0fdefe
Implement exercise concurrent-linked-queue-simple
tboychuk a206bc0
Merge branch 'master' into exercise/completed
tboychuk 6195fcb
Merge branch 'master' into exercise/completed
tboychuk 755139b
Merge branch 'master' into exercise/completed
tboychuk ed6ab0e
Simplify class Node.java as a pure data structure, and hide it
tboychuk f2836e2
Merge branch 'master' into exercise/completed
tboychuk 210e2f6
Complete exercise
tboychuk ba95354
Merge branch 'master' into exercise/completed
tboychuk d7007bf
Merge branch 'master' into exercise/completed
tboychuk c7f1d80
Fix method add(int index, T element)
tboychuk fffd4df
Fix index at method remove()
tboychuk 791acad
Add comment for method findTail()
tboychuk 0f93579
Merge branch 'master' into exercise/completed
tboychuk 75ba68c
Fix LinkedList#set()
tboychuk 1569048
Merge branch 'master' into exercise/completed
tboychuk 8da56dd
Complete FileStats.java exercise
tboychuk 0c82e41
Merge branch 'master' into exercise/completed
tboychuk 0cca6c7
Remove redundant code from LinkedList#set()
tboychuk 6ec5e02
Simplify LinkedList#add(index, element)
tboychuk 4cbe0f5
Merge branch 'master' into exercise/completed
tboychuk cfc3847
Complete exercises
tboychuk 9105439
Merge branch 'master' into exercise/completed
tboychuk 461f803
Merge branch 'master' into exercise/completed
tboychuk 0d0cd0e
Merge branch 'master' into exercise/completed
tboychuk 8505265
Merge branch 'master' into exercise/completed
tboychuk 89a43cb
Upgrade LinkedList.java implementation
tboychuk 1392087
Merge branch 'master' into exercise/completed
tboychuk ee86666
Merge branch 'master' into exercise/completed
tboychuk c9f0244
Merge branch 'master' into exercise/completed
tboychuk 20c1aaf
Merge branch 'master' into exercise/completed
tboychuk da6aa0b
Upgrade LinkedList.java
tboychuk 9434e3d
Merge branch 'master' into exercise/completed
tboychuk afc5479
Merge branch 'master' into exercise/completed
tboychuk 4370c02
Update FileReaders.java
tboychuk c0fa442
Upgrade the implementation of LinkedList.java
tboychuk 36c2348
Upgrade the implementation of LinkedList.java
tboychuk bb74678
Upgrade the implementation of LinkedList.java
tboychuk 4b82d55
Merge branch 'master' into exercise/completed
tboychuk 7f13124
Merge branch 'master' into exercise/completed
tboychuk 7bba9c0
#6 add java functional features exercises with solutions
Shtramak 96b5af3
Merge pull request #10 from bobocode-projects/ticket/#6-completed
tboychuk 249b5cf
Merge branch 'master' into exercise/completed
tboychuk 92524fa
Merge branch 'master' into exercise/completed
tboychuk 3ee80b1
Implement new methods is CrazyLambdas.java
tboychuk 73beb18
Merge branch 'master' into exercise/completed
tboychuk b554fdc
Merge branch 'master' into exercise/completed
tboychuk 4068f38
GP-4 Create new exercise CrazyOptionals.java and upgrade Accounts.java
tboychuk 7cdc096
Merge pull request #16 from bobocode-projects/GP-4-CrazyOptionalExerc…
tboychuk 9394eef
Merge branch 'master' into exercise/completed
tboychuk c9bbe03
Merge branch 'master' into exercise/completed
tboychuk 606a6b5
Merge branch 'master' into exercise/completed
tboychuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
48 changes: 42 additions & 6 deletions
48
concurrent-linked-queue-simple/src/main/java/com/bobocode/ConcurrentLinkedQueue.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,65 @@ | ||
| package com.bobocode; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| /** | ||
| * This queue should be implemented using generic liked nodes. E.g. class Node<T>. In addition, this specific | ||
| * should be thread-safe, which means that queue can be used by different threads simultaneously, and should work correct. | ||
| * | ||
| * @param <T> a generic parameter | ||
| */ | ||
| public class ConcurrentLinkedQueue<T> implements Queue<T> { | ||
| static final class Node<T> { | ||
| private T element; | ||
| private Node<T> next; | ||
|
|
||
| static <T> Node<T> valueOf(T element) { | ||
| return new Node<>(element); | ||
| } | ||
|
|
||
| private Node(T element) { | ||
| this.element = element; | ||
| } | ||
| } | ||
|
|
||
| private Node<T> head; | ||
| private Node<T> tail; | ||
| private AtomicInteger size = new AtomicInteger(); | ||
|
|
||
| @Override | ||
| public void add(T element) { | ||
| throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method | ||
| synchronized public void add(T element) { | ||
| Node<T> newNode = Node.valueOf(element); | ||
| if (head == null) { | ||
| head = tail = newNode; | ||
| } else { | ||
| tail.next = newNode; | ||
| tail = newNode; | ||
| } | ||
| size.incrementAndGet(); | ||
| } | ||
|
|
||
| @Override | ||
| public T poll() { | ||
| throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method | ||
| synchronized public T poll() { | ||
| if (head != null) { | ||
| T element = head.element; | ||
| head = head.next; | ||
| if (head == null) { | ||
| tail = null; | ||
| } | ||
| size.decrementAndGet(); | ||
| return element; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int size() { | ||
| throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method | ||
| return size.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| throw new UnsupportedOperationException("This method is not implemented yet"); // todo: implement this method | ||
| return head == null; | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
file-reader/src/main/java/com/bobocode/FileReaderException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.bobocode; | ||
|
|
||
| public class FileReaderException extends RuntimeException { | ||
| public FileReaderException(String message, Exception e) { | ||
| super(message, e); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"getResource()"
Does this method retrieve a "resources" folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only, in our case files from folder
resourceswill be in the classpath, and that method allows to get aURLobject of any kind of resource (any file) by its name.You can check its javadoc for more details.