public void testCompare() throws Exception { assertEquals(0, CompareUtils.compare(null, null)); assertEquals(-1, CompareUtils.compare(null, "hello")); assertEquals(1, CompareUtils.compare("hello", null)); assertEquals(0, CompareUtils.compare("hello", "hello")); assertEquals("hello".compareTo("world"), CompareUtils.compare("hello", "world")); }
@Override protected int mainCompare(@Nonnull final String sElement1, @Nonnull final String sElement2) { // The longer, the earlier in the results int ret = CompareUtils.compare(sElement2.length(), sElement1.length()); if (ret == 0) { // Important to compare the content as well because with ret==0, // elements would eventually be removed (e.g. from a TreeMap) ret = sElement1.compareTo(sElement2); } return ret; }
/** * Returns selected value index. This method is overriden by WebComboBox to fix issue with "null" * value from the model being ignored if selected. By default (in JComboBox) this method will not * return index of "null" value in the model if it is selected. * * @return index of the selected value */ @Override public int getSelectedIndex() { final Object sObject = dataModel.getSelectedItem(); int i; Object obj; for (i = 0; i < dataModel.getSize(); i++) { obj = dataModel.getElementAt(i); if (CompareUtils.equals(obj, sObject)) { return i; } } return -1; }
protected Diff<Document, Diff<Fieldable, DocumentDiff>> compare( IndexReader reader1, IndexReader reader2, String keyFieldName) throws IOException, ParseException { Diff<Document, Diff<Fieldable, DocumentDiff>> result = new Diff<Document, Diff<Fieldable, DocumentDiff>>(); for (int docId = 0; docId < reader1.numDocs(); docId++) { if (!reader1.isDeleted(docId)) { Document doc1 = reader1.document(docId); Field keyField = doc1.getField(keyFieldName); if (keyField == null) { throw new IllegalArgumentException( "Key field " + keyFieldName + " should be defined in all docs in the index"); } Document doc2 = findByKey(reader2, keyField); if (doc2 == null) { result.addAdded(doc1); } else { Diff<Fieldable, DocumentDiff> diff = CompareUtils.diff(keyField.stringValue(), doc1, doc2); if (!diff.isEquals()) { result.addDiff(diff); } } } } for (int docId = 0; docId < reader2.numDocs(); docId++) { if (!reader2.isDeleted(docId)) { Document doc2 = reader2.document(docId); Field keyField = doc2.getField(keyFieldName); if (keyField == null) { throw new IllegalArgumentException( "Key field '" + keyFieldName + "' should be defined in all docs in the index"); } Document doc1 = findByKey(reader1, keyField); if (doc1 == null) { result.addRemoved(doc2); } } } return result; }
// The tck uses only get & post requests protected void processTCKReq(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOGGER.entering(LOG_CLASS, "servlet entry"); PortletRequest portletReq = (PortletRequest) request.getAttribute("javax.portlet.request"); PortletResponse portletResp = (PortletResponse) request.getAttribute("javax.portlet.response"); PortletConfig portletConfig = (PortletConfig) request.getAttribute("javax.portlet.config"); long svtTid = Thread.currentThread().getId(); long reqTid = (Long) portletReq.getAttribute(THREADID_ATTR); PrintWriter writer = ((MimeResponse) portletResp).getWriter(); JSR286DispatcherReqRespTestCaseDetails tcd = new JSR286DispatcherReqRespTestCaseDetails(); // Create result objects for the tests /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_containsHeader */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.containsHeader must return false" */ TestResult tr0 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_CONTAINSHEADER); try { boolean ok = response.containsHeader("Accept"); tr0.setTcSuccess(ok == false); } catch (Exception e) { tr0.appendTcDetail(e.toString()); } tr0.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectURL1 */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.encodeRedirectURL must return null" */ TestResult tr1 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL1); try { String isval = response.encodeRedirectURL("http://www.cnn.com/"); CompareUtils.stringsEqual(isval, null, tr1); } catch (Exception e) { tr1.appendTcDetail(e.toString()); } tr1.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeRedirectUrl */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.encodeRedirectUrl must return null" */ TestResult tr2 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEREDIRECTURL); try { String isval = response.encodeRedirectUrl("http://www.cnn.com/"); CompareUtils.stringsEqual(isval, null, tr2); } catch (Exception e) { tr2.appendTcDetail(e.toString()); } tr2.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeURL1 */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.encodeURL must provide the same */ /* functionality as ResourceResponse.encodeURL" */ TestResult tr3 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL1); try { String turl = "http://www.apache.org/"; String hval = (String) response.encodeURL(turl); String pval = (String) portletResp.encodeURL(turl); CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr3); } catch (Exception e) { tr3.appendTcDetail(e.toString()); } tr3.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_encodeUrl */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.encodeUrl must provide the same */ /* functionality as ResourceResponse.encodeURL" */ TestResult tr4 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ENCODEURL); try { String turl = "http://www.apache.org/"; String hval = (String) response.encodeUrl(turl); String pval = (String) portletResp.encodeURL(turl); CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr4); } catch (Exception e) { tr4.appendTcDetail(e.toString()); } tr4.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getBufferSize */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.getBufferSize must provide the same */ /* functionality as ResourceResponse.getBufferSize" */ TestResult tr5 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETBUFFERSIZE); try { int hval = response.getBufferSize(); int pval = ((ResourceResponse) portletResp).getBufferSize(); String str = "Value " + hval + " from " + "HttpServletResponse" + " does not equal value " + pval + " + ResourceResponse"; if (hval != pval) { tr5.appendTcDetail(str); } tr5.setTcSuccess(hval == pval); } catch (Exception e) { tr5.appendTcDetail(e.toString()); } tr5.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getCharacterEncoding */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.getCharacterEncoding must provide */ /* the same functionality as ResourceResponse.getCharacterEncoding" */ TestResult tr6 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCHARACTERENCODING); try { String hval = response.getCharacterEncoding(); String pval = ((ResourceResponse) portletResp).getCharacterEncoding(); CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr6); } catch (Exception e) { tr6.appendTcDetail(e.toString()); } tr6.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getContentType */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.getContentType must provide the */ /* same functionality as ResourceResponse.getContentType" */ TestResult tr7 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETCONTENTTYPE); try { String hval = response.getContentType(); String pval = ((ResourceResponse) portletResp).getContentType(); CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr7); } catch (Exception e) { tr7.appendTcDetail(e.toString()); } tr7.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_getLocale */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.getLocale must provide the same */ /* functionality as ResourceResponse.getLocale" */ TestResult tr8 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_GETLOCALE); try { Locale hl = response.getLocale(); Locale pl = ((MimeResponse) portletResp).getLocale(); String hval = hl.getDisplayName(); String pval = pl.getDisplayName(); CompareUtils.stringsEqual("HttpServletResponse", hval, "ResourceResponse", pval, tr8); } catch (Exception e) { tr8.appendTcDetail(e.toString()); } tr8.writeTo(writer); /* TestCase: V2DispatcherReqRespTests4_SPEC2_19_IncludeServletResourceResponse_isCommitted */ /* Details: "In a target servlet of a include in the Resource phase, */ /* the method HttpServletResponse.isCommitted must provide the same */ /* functionality as ResourceResponse.isCommitted" */ TestResult tr9 = tcd.getTestResultFailed( V2DISPATCHERREQRESPTESTS4_SPEC2_19_INCLUDESERVLETRESOURCERESPONSE_ISCOMMITTED); try { boolean hval = response.isCommitted(); boolean pval = ((ResourceResponse) portletResp).isCommitted(); String str = "Value " + hval + " from " + "HttpServletResponse" + " does not equal value " + pval + " + ResourceResponse"; if (hval != pval) { tr9.appendTcDetail(str); } tr9.setTcSuccess(hval == pval); } catch (Exception e) { tr9.appendTcDetail(e.toString()); } tr9.writeTo(writer); }
private void updateHints() { String text = classSearchField.getText().trim(); // Ignore empty text if (text.trim().length() == 0) { hideHints(); return; } // Updating hints window if needed if (!CompareUtils.equals(lastSearchedText, text)) { // Saving old selection Object oldSelection = classSearchHintsList.getSelectedValue(); // Clearing list DefaultListModel model = (DefaultListModel) classSearchHintsList.getModel(); model.clear(); // Look for classes List<JarEntry> found = jarStructure.findSimilarEntries( text, new Filter<JarEntry>() { @Override public boolean accept(JarEntry object) { return object.getType().equals(JarEntryType.javaEntry); } }); if (found.size() > 0) { classSearchField.setForeground(Color.BLACK); // Filling list with results for (JarEntry entry : found) { model.addElement(entry); } // Updating visible rows classSearchHintsList.setVisibleRowCount(Math.min(model.size(), 10)); // Restoring selection if possible int index = oldSelection != null ? model.indexOf(oldSelection) : 0; classSearchHintsList.setSelectedIndex(index != -1 ? index : 0); // Packing popup classSearchHintsPopup.pack(); // Displaying hints window if (!classSearchHintsPopup.isVisible()) { classSearchHintsPopup.setVisible(true); } } else { classSearchField.setForeground(Color.RED); // Hiding hints window if (classSearchHintsPopup.isVisible()) { classSearchHintsPopup.setVisible(false); } } lastSearchedText = text; } }