| | |
| | | System.out.println(News.print()); |
| | | } |
| | | |
| | | interface NewsSupport<T> { boolean execute(T t); } |
| | | interface NewsSupport<T> { |
| | | boolean execute(T t); |
| | | } |
| | | |
| | | private static final NewsQueue<NewsDomain> NEWS_QUEUE = new NewsQueue<>(NewsDomain.class, 1024); |
| | | |
| | |
| | | private int head; |
| | | private int tail; |
| | | |
| | | { this.head = 0; this.tail = 0; } |
| | | { |
| | | this.head = 0; |
| | | this.tail = 0; |
| | | } |
| | | |
| | | public NewsQueue(Class<T> cls, int capacity) { |
| | | this.cls = cls; |
| | |
| | | } |
| | | this.reform(); |
| | | this.arr[this.tail] = t; |
| | | this.tail ++; |
| | | this.tail++; |
| | | return true; |
| | | } |
| | | |
| | |
| | | this.reform(); |
| | | } |
| | | this.arr[this.tail] = t; |
| | | this.tail ++; |
| | | this.tail++; |
| | | return true; |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | T t = this.arr[this.head]; |
| | | this.head ++; |
| | | this.head++; |
| | | this.reform(); |
| | | return t; |
| | | } |
| | | |
| | | private void reform() { |
| | | for (int i = this.head; i < this.tail; i++) { |
| | | this.arr[i-this.head] = this.arr[i]; |
| | | this.arr[i - this.head] = this.arr[i]; |
| | | } |
| | | this.tail -= this.head; |
| | | this.head = 0; |
| | |
| | | return false; |
| | | } |
| | | String systemMsg = replace(msg, args); |
| | | if (systemMsg.equals(wrkMast.getSystemMsg())) { |
| | | if (!systemMsg.equals(wrkMast.getSystemMsg())) { |
| | | wrkMast.setSystemMsg(systemMsg); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | |
| | | return NEWS_QUEUE.offer(new NewsDomain(level, replace(msg, args), (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()))); |
| | | } |
| | | |
| | | public static String replace(String str, Object[] objs){ |
| | | public static String replace(String str, Object[] objs) { |
| | | if (null == objs || objs.length == 0 || null == str || "".equals(str.trim())) { |
| | | return str; |
| | | } else { |
| | | StringBuilder sb = new StringBuilder(str); |
| | | for (Object obj : objs) { |
| | | int idx = sb.indexOf("{}"); |
| | | if (idx == -1) { break; } |
| | | if (idx == -1) { |
| | | break; |
| | | } |
| | | sb.replace(idx, idx + 2, String.valueOf(obj)); |
| | | } |
| | | return sb.toString(); |
| | |
| | | ERROR(3), |
| | | ; |
| | | public int idx; |
| | | |
| | | NewsLevel(int idx) { |
| | | this.idx = idx; |
| | | } |