Добрый день или вечер всем! Пожалуйста не ругайте решение ужасное я это осознаю, но всё же как я проверял всё вроде работает в контексте условия задачи, пожалуйста помогите
package com.javarush.task.task15.task1527;
/*
Парсер реквестов
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Solution {
public static void main(String[] args) throws IOException {
//add your code here
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
String url = rd.readLine();
Pattern findObj = Pattern.compile("obj");
Matcher matcherObj = findObj.matcher(url);
if (!matcherObj.find()) {
Pattern pattern = Pattern.compile("\\?\\w+=\\d+\\&\\w+?\\&\\w+");
Matcher matcher = pattern.matcher(url);
String result = null;
while (matcher.find()) {
result = matcher.group();
}
String result2 = result.replaceAll("(&)", " ");
result2 = result2.replaceAll("\\d+", "");
result2 = result2.replaceAll("=", "");
result2 = result2.replaceAll("\\?", "");
System.out.println(result2);
} else {
String resultObj = null;
String resultObj2 = null;
if (url.matches("\\w+://\\w+.\\w+/\\w+/\\w+.\\w+\\?\\w+=\\d.\\d+&\\w+=\\w+")) {
Pattern obj = Pattern.compile("\\?\\w+=\\d.\\d+\\&\\w+");
Matcher matcher2 = obj.matcher(url);
while (matcher2.find()) {
resultObj = matcher2.group();
}
String test = resultObj;
resultObj2 = resultObj.replaceAll("&", " ");
resultObj2 = resultObj2.replaceAll("\\d+", "");
resultObj2 = resultObj2.replaceAll("=.", "");
resultObj2 = resultObj2.replaceAll("\\?", "");
test = test.replaceAll("(\\?\\w+=|&\\w+)", "");
double count = Double.parseDouble(test);
System.out.println(resultObj2);
alert(count);
}
else if (url.matches("\\w+://\\w+.\\w+/\\w+/\\w+.\\w+\\?\\w+=\\w+&\\w+=\\w+")) {
Pattern obj2 = Pattern.compile("\\?\\w+=\\w+&\\w+");
Matcher matcherObj2 = obj2.matcher(url);
while (matcherObj2.find()) {
resultObj = matcherObj2.group();
}
String string = resultObj;
resultObj2 = resultObj.replaceAll("&", " ");
resultObj2 = resultObj2.replaceAll("=\\w+", "");
resultObj2 = resultObj2.replaceAll("\\?", "");
string = string.replaceAll("(\\?\\w+=|&\\w+)", "");
System.out.println(resultObj2);
alert(string);
}
}
}
public static void alert (double value) {
System.out.println("double: " + value);
}
public static void alert (String value) {
System.out.println("String: " + value);
}
}