eclipse - How to implement multi interfaces from a jar file in java? -


this question has answer here:

i have created class , import interfaces how rest, should do?

here have doesn't work 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 2 methods: 1 creating new      * queues , 1 cleaning after them. in `createqueue`, create      * new processingqueue, performing necessary initialization of queue      * before returned. `createqueue` called multiple times during our      * automated tests. in `stopqueue`, perform cleanup required queue      * created `createqueue` method. (e.g., stop threads, if necessary      * solution.) `stopqueue` called once each queue created      * `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;         }      }      /**      * processingqueue implementation receive unprocessed textual data      * multiple concurrent producers through `offer` method. queue      * must provide transformed version of data via `poll` method.      * transformation described below. queue, data received      * `poll` must fifo (first-in, first-out) respect calls      * `offer`; i.e., first items in should first items out. if      * data available, `poll` must remove queue , return it. if no      * data available, `poll` must return null.      */     class processingqueueclass implements processingqueue {          processingqueuefactoryclass openfactory = new processingqueuefactoryclass();         processingqueue newqueue = openfactory.createqueue();          /**the linkify transformation should find raw urls prefixed "http(s)://" in          * input text , convert them html links. example,          * http://www.example.com becomes <a href="http://www.example.com">www.example.com</a>. not include scheme          * (http(s)://) in anchor text. urls within html links          * should not modified. can assume input text contains multiple words          * separated 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 = "";              (int = 0; < 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);             // need add transformedstring our queue, should create?;              //how 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 lazy dog foo www.bar.com  //                 <a href=\"http://myfavorite.com\">my favorite</a> " //                 + "these aren't droids you're looking for.";          //solution sol = new solution();         //processingqueueclass pqs = sol.new processingqueueclass();         //pqs.linkifytransformation(s);   }  } 

here details might help.

revmetrix linkify queue coding problem input , output of string data transformation. queue must correctly handle concurrent operations reasonable performance. implement processingqueue , processingqueuefactory jar. processingqueue implementation receive unprocessed textual data multiple concurrent producers through offer method. queue must provide transformed version of data via poll method. queue, data received poll must fifo (first-in, first-out) respect calls offer;

in general, when implement interface in java need implement it's methods , define body methods defined in interface.

if don't want implement of interface's methods bodies, change class abstract class , mark methods abstract too.

i don't know how familiar interfaces , classes in java, think reading tutorials http://tutorials.jenkov.com/java/interfaces.html helpful.

[edit after question changed]

the classcastexception happening here:

return (processingqueue) newqueue; 

because illegally cast instance of queue<string> interface of type processingqueue. cast can not happen because queue<string> or none of it's parents didn't implement processingqueue interface.

but due assignment specification, implementation not right.

you should implement 1 class implement processingqueue , implement processingqueuefactory (til did part).

you should not create instances of processingqueuefactoryclass , processingqueue in processingqueueclass class, remove these 2 line:

processingqueuefactoryclass openfactory = new processingqueuefactoryclass(); processingqueue newqueue = openfactory.createqueue(); 

also should keep queue of linkified strings in processingqueue class. move following line public processingqueue createqueue() method processingqueue class:

queue<string> newqueue = new linkedlist<string>(); 

to

class processingqueueclass implements processingqueue {     queue<string> newqueue = new linkedlist<string>();     ... } 

in public boolean offer(string s) should result of linkifytransformation(s); , add newqueue , in public string poll() method remove , return first item of newqueue maintain fifo paradigm.

now processingqueuefactoryclass: class have 2 simple methods. work of createqueue() method simple: create , instance of processingqueueclass class , return it.

and other method stopqueue(processingqueue p): method gets instance of processingqueue argument. because class processingqueueclass implemented processingqueue, runtime type of input argument of type processingqueueclass. , because have queue<string> member variable in processingqueueclass class, purpose of method clear queue<string> newqueue items , release it.

hope helpful,

good luck.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -