На входе в метод string на выходе str. Как положено строка обрезана между табуляцией
package com.javarush.task.task22.task2201;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/*
Строки нитей или строковые нити? Вот в чем вопрос
*/
public class Solution {
public static void main(String[] args) {
new Solution();
}
public static final String FIRST_THREAD_NAME = "1#";
public static final String SECOND_THREAD_NAME = "2#";
private Thread thread1;
private Thread thread2;
private Thread thread3;
public Solution() {
initThreads();
}
protected void initThreads() {
this.thread1 = new Thread(new Task(this, "A\tB\tC\tD\tE\tF\tG\tH\tI"), FIRST_THREAD_NAME);
this.thread2 = new Thread(new Task(this, "J\tK\tL\tM\tN\tO\tP\tQ\tR\tS\tT\tU\tV\tW\tX\tY\tZ"), SECOND_THREAD_NAME);
this.thread3 = new Thread(new Task(this, "\t\t"), "3#");
Thread.setDefaultUncaughtExceptionHandler(new OurUncaughtExceptionHandler());
this.thread1.start();
this.thread2.start();
this.thread3.start();
}
public synchronized String getPartOfString(String string, String threadName) {
if (string==null && threadName.equals("1#")) throw new StringForFirstThreadTooShortException();
else if (string==null && threadName.equals("2#")) throw new StringForSecondThreadTooShortException();
else if (string==null && (!threadName.equals("1#") || !threadName.equals("#2"))) throw new RuntimeException();
else {
Pattern pattern = Pattern.compile("\t.*\t");
Matcher matcher = pattern.matcher(string);
boolean find = matcher.find();
if (!find && threadName.equals("1#")) throw new StringForFirstThreadTooShortException();
if (!find && threadName.equals("2#")) throw new StringForSecondThreadTooShortException();
if (!find && (!threadName.equals("1#") || !threadName.equals("#2"))) throw new RuntimeException();
String str = matcher.group().trim();
return str;
}
}
}