@Override public String toString() { return "problem(" + getSource() + ": " + getMessage() + ")"; }
@Nls(capitalization = Nls.Capitalization.Sentence) private String toMessage(Collection<ConfigProblem> problems) { StringBuilder sb = new StringBuilder(); boolean first = true; for (ConfigProblem problem : problems) { if (first) { first = false; } else { sb.append(P4Bundle.getString("config.message.separator")); } sb.append(problem.getMessage()); } return sb.toString(); }
@Override public int hashCode() { int code = getMessage().hashCode() + (isError() ? 100 : 101); if (getSource() != null) { code += getSource().hashCode(); } return code; }
@Override public Component getListCellRendererComponent(JList<? extends ConfigProblem> list, ConfigProblem problem, int index, boolean isSelected, boolean cellHasFocus) { // TODO allow selection, and show selection differently. cell.setForeground(problem.isError() ? JBColor.RED : UIUtil.getTextAreaForeground()); cell.setBackground(UIUtil.getListBackground(isSelected)); cell.setText(problem.getMessage()); return cell; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof ConfigProblem)) { return false; } ConfigProblem that = (ConfigProblem) o; return isError() == that.isError() && // Not perfect: the source can change, which changes the // equality. But this will do. As long as the source object // has correct equality / hashCode semantics, and it isn't used // as the key for a hash table when the source changes, this // will work. EqualUtil.isEqual(getSource(), that.getSource()) && getMessage().equals(that.getMessage()); }
Set<String> problemText = new HashSet<>(); for (ConfigProblem configProblem : PartValidation.findAllProblems(part)) { if (!problemText.contains(configProblem.getMessage())) { problemText.add(configProblem.getMessage()); problemListModel.addElement(configProblem); if (configProblem.isError()) {
return getMessage().compareTo(that.getMessage());
@Test void getters_1() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Foo bar", true); assertEquals("Foo bar", cp.getMessage()); assertEquals(part, cp.getSource()); assertTrue(cp.isError()); assertEquals( "problem(" + part + ": Foo bar)", cp.toString()); }
@Test void getters_2() { MockConfigPart part = new MockConfigPart(); ConfigProblem cp = new ConfigProblem(part, "Too bad", false); assertFalse(cp.isError()); assertEquals("Too bad", cp.getMessage()); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); part.withUsername("u"); assertEquals(part, cp.getSource()); assertEquals( "problem(" + part + ": Too bad)", cp.toString()); }