[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Java file iteration

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

Help me, /wsr/ i am currently having a problem regarding a Java-related project.

As part of a project in the practice of concurrency, we were taked with creating a project that by using multithreading, would recursively iterate through files in a directory and return a result of some kind.

I already have a good idea of how to make it concurrent (ExecutorService, in case you were wondering) but i am stuck as to how we're supposed to implement a given interface. The interface in question was:


public interface Result
{
/**
* The file ({@link Path}) of this result
* @return file ({@link Path}) of this result
*/
public Path path();

public int number();
}

Additionally, we had the main class Exam and a method defined as:

/**
* Finds a file that contains at most (no more than) n numbers and such that all
* numbers in the file are equal or greater than min.
*
* This method searches only for one (any) file in the directory
* (parameter dir) such that the condition above is respected.
* As soon as one such occurrence is found, the search can be
* stopped and the method can return immediately.
*
* As for method {@code findAll}, the search is recursive.
*/
public static Result findAny( Path dir, int n, int min )
{
throw new UnsupportedOperationException();
}


Where Result is the interface.

My idea for implementing the interface was that i would create a seperate class that would implement the interface Result. I would then in findAny create an object that would allow me to call its methods to return a Result

However, i have two major obstacles that i am facing. For one, neither path() or number() take on any arguments. How are they suppsoed to know what to return when they cannot take any arguments? Second of all, i am in doubt whether my new class should take on nay arguments. I now it should have a Path field to return as a value, but should it actually take on any arguments?

P.S we were not allowed to change the interfaces
>>
I don't understand the solution that you had in mind. What object would you have created in findAny? Why would you need your Result class to be anything but a pure data structure? You create your ExecutorService and pass it some Callable that returns an object with a Path and an int. Seems straightforward to me.
>>
>>343621
The idea i had was this: create another class called "myResult" for instance that implemented the interface Result. It would then have those two mehtods. I would then create an object of myResult, that allowed me to call upon said interface methods. But since neither number() or path() can be given any arguments (a File Path for instance) how can they know what to return?
>>
>>343696
I'm pretty sure that the number and path functions are just Getter methods for anything that inherits the interface.
>>
public static Result findAny( Path dir, int n, int min )
{
// do you stuff and calculations here that yield you
...
Path pathToCorrectFile = ... ;
int number = ... ;
return new Result {
public Path path(){
return pathToCorrectFile;
}

public int number(){
return number;
}
}
}

Sry for keeping it short, writing with phone
>>
>>343696
That wasn't your idea, that was how I told you to solve it the last time you created this thread.

Result is just an ADT, your worker thread creates one instead of returning a String. All the information a Result conveys is stored as a member variable, set by the constructor, and returned by the accessors.

I suggest you pay more attention in class, stop trying to pass of others' work as your own, and google "object orientation abstract datatypes".
>>
>>343532
https://archive.nyafuu.org/wsr/thread/339175/ for those playing along at home.
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.