package util;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Util {
public static String in(){
try{
System.out.print("> ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
return in.readLine();
}catch(Exception e){return "";}
}
public static String implode(Object[] o, String glue) {
String s = "";
for(int i = 0; i < o.length; i++){
s += o[i];
if(o.length-i > 1)
s += glue;
}
return s;
}
public static int indexOf(Pattern pattern, String s) {
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.start() : -1;
}
public static <T> void printStat(Map<T, Integer> m, PrintStream p) {
ArrayList<Entry<T, Integer>> l = new ArrayList<>(m.entrySet());
Collections.sort(l, new Comparator<Entry<T, Integer>>() {
@Override
public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
return Integer.compare(o2.getValue(), o1.getValue());
}
});
for(Entry<T, Integer> e : l){
p.println(e.getValue()+"\t"+e.getKey().toString());
}
}
}