I have created a class and import my interfaces but how to do the rest, what should I do?
Here I have anything but it doesn't work I mean ClassCastExeption doesn't work
code example :
import java.util.LinkedList;
import java.util.Queue;
import com.revmetrix.code_test.linkify_queue.ProcessingQueue;
import com.revmetrix.code_test.linkify_queue.ProcessingQueueFactory;
public class Solution {
ProcessingQueue newQueue;
ProcessingQueueFactory runFactory;
Solution() {
ProcessingQueueFactoryClass runFactory = new ProcessingQueueFactoryClass();
ProcessingQueue newQueue = runFactory.createQueue();
}
/**Your ProcessingQueueFactory must contain two methods: one for creating new
* queues and one for cleaning up after them. In `createQueue`, just create a
* new ProcessingQueue, performing any necessary initialization of the queue
* before it is returned. `createQueue` will be called multiple times during our
* automated tests. In `stopQueue`, perform any cleanup required for a queue
* created by your `createQueue` method. (E.g., stop threads, if necessary for
* your solution.) `stopQueue` will be called once for each queue created with
* `createQueue`.
*/
class ProcessingQueueFactoryClass implements ProcessingQueueFactory {
public void stopQueue(ProcessingQueue p) {
}
// TODO encok burda sikinti var, queue yaratacam ama Proccesing Queue donderiyor bu
// asil eleman ekleyecegim queue yi ProcessingQueue nin icinde mi yaratcam?
// ProcessingQueue bi interface bu arada, bunu implement eden class ProcessingQueueClass yazdim
// onun icinde queue olsun dedim yine gormuyor zalim queue olarak
//bi loop var ProcessingQueue ile ProcessingQueueFactory arasinda, anlamadim!
public ProcessingQueue createQueue() {
Queue<String> newQueue = new LinkedList<String>();
return (ProcessingQueue) newQueue;
}
}
/**
* Your ProcessingQueue implementation will receive unprocessed textual data
* from multiple concurrent producers through its `offer` method. Your queue
* must provide a transformed version of the data via its `poll` method. The
* transformation is described below. As a queue, the data received from
* `poll` must be FIFO (first-in, first-out) with respect to calls to
* `offer`; i.e., the first items in should also be the first items out. If
* data is available, `poll` must remove it from queue and return it. If no
* data is available, then `poll` must return null.
*/
class ProcessingQueueClass implements ProcessingQueue {
ProcessingQueueFactoryClass openFactory = new ProcessingQueueFactoryClass();
ProcessingQueue newQueue = openFactory.createQueue();
/**The linkify transformation should find raw URLs prefixed with "http(s)://" in
* the input text and convert them to HTML links. For example,
* http://www.example.com becomes <a href="http://www.example.com">www.example.com</a>. Do not include the scheme
* (http(s)://) in the anchor text. Any URLs that are already within HTML links
* should not be modified. You can assume the input text contains multiple words
* separated by white space (i.e. spaces, new lines) or punctuations (commas,
* periods, etc.)
*/
public String linkifyTransformation(String s){
// System.out.println(s);
String[] splitArray = s.split(" ");
String transformedString = "";
for (int i = 0; i < splitArray.length; ++i) {
if (splitArray[i].startsWith("https://")) {
transformedString += "<a href=\"" + splitArray[i] + "\">"
+ splitArray[i].substring(8) + "</a> ";
} else if (splitArray[i].startsWith("http://")) {
transformedString += "<a href=\"" + splitArray[i] + "\">"
+ splitArray[i].substring(7) + "</a> ";
} else {
transformedString += splitArray[i] + " ";
}
}
//System.out.println(transformedString);
return transformedString;
}
public boolean offer(String s) {
//returns transformedString
linkifyTransformation(s);
// we need to add the transformedString to our Queue, Where should we create?;
//how to return true or false?
return false;
}
public String poll() {
return "";
}
}
public static void main(String[] args) {
// String s = "The quick http://www.brown.com/fox
// jumps https://over.com the lazy dog foo www.bar.com
// is <a href=\"http://myfavorite.com\">my favorite</a> "
// + "These aren't the droids you're looking for.";
//Solution sol = new Solution();
//ProcessingQueueClass pqs = sol.new ProcessingQueueClass();
//pqs.linkifyTransformation(s);
}
}
Here is some details which might help.
Revmetrix Linkify Queue Coding Problem the input and output of string data with a transformation. This queue must
correctly handle concurrent operations with reasonable performance. Implement ProcessingQueue and ProcessingQueueFactory from the JAR.
Your ProcessingQueue implementation will receive unprocessed textual data from multiple concurrent producers through its offer
method. Your queue
must provide a transformed version of the data via its poll
method. As a queue, the data received from poll
must be FIFO (first-in, first-out) with respect to calls to offer
;