From: Xuan B. <med...@us...> - 2007-05-21 17:16:19
|
Update of /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22008/src/org/tm4j/topicmap/utils Modified Files: XTMWriter.java Log Message: Rework and optimize getResourceID() to be only of O(n) performance instead of O(n^2) performance. Index: XTMWriter.java =================================================================== RCS file: /cvsroot/tm4j/tm4j/src/org/tm4j/topicmap/utils/XTMWriter.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** XTMWriter.java 21 May 2007 17:07:06 -0000 1.46 --- XTMWriter.java 21 May 2007 17:16:17 -0000 1.47 *************** *** 860,880 **** */ protected String getResourceID(TopicMapObject tmo, Locator srcLoc) { ! if (!(srcLoc instanceof URILocator)) return null; String ret = null; Iterator srcLocs = tmo.getSourceLocators().iterator(); while (srcLocs.hasNext()) { Locator tmoResLoc = (Locator)srcLocs.next(); - Locator tmResLoc = srcLoc; ! if ((tmoResLoc == null) || (tmResLoc == null) || ! !(tmoResLoc instanceof URILocator) || ! !(tmResLoc instanceof URILocator)) { continue; } URILocator uTmoResLoc = (URILocator) tmoResLoc; - URILocator uTmResLoc = (URILocator) tmResLoc; - String tmAddress = getDocumentPart(uTmResLoc.getAddress()); if (getDocumentPart(uTmoResLoc.getAddress()).equals(tmAddress)) { --- 860,882 ---- */ protected String getResourceID(TopicMapObject tmo, Locator srcLoc) { ! if (!(srcLoc instanceof URILocator)) ! return null; ! String ret = null; + Locator tmResLoc = srcLoc; + + URILocator uTmResLoc = (URILocator) tmResLoc; + String tmAddress = getDocumentPart(uTmResLoc.getAddress()); + Iterator srcLocs = tmo.getSourceLocators().iterator(); while (srcLocs.hasNext()) { Locator tmoResLoc = (Locator)srcLocs.next(); ! if (!(tmoResLoc instanceof URILocator)) { // if (tmoResLoc instanceof URILocator) returns true, then it is guaranteed that tmoResLoc!=null. Furthermore, tmoResLoc==null is not allowed anyway, is it? continue; } URILocator uTmoResLoc = (URILocator) tmoResLoc; if (getDocumentPart(uTmoResLoc.getAddress()).equals(tmAddress)) { *************** *** 885,904 **** } } ! ! if (tmo instanceof Topic) { ! Iterator it = ((Topic) tmo).getSubjectIndicators().iterator(); ! ! while (it.hasNext()) { ! Object o = it.next(); ! ! if (o instanceof URILocator) { ! URILocator l = (URILocator) o; ! ! if (getDocumentPart(l.getAddress()).equals(tmAddress)) { ! ret = l.getFragment(); ! ! if (!enableNiceIDs||!looksLikeBeingAutoGenerated(ret)) { ! return ret; ! } } } --- 887,906 ---- } } ! } ! ! if (tmo instanceof Topic) { ! Iterator it = ((Topic) tmo).getSubjectIndicators().iterator(); ! ! while (it.hasNext()) { ! Object o = it.next(); ! ! if (o instanceof URILocator) { ! URILocator l = (URILocator) o; ! ! if (getDocumentPart(l.getAddress()).equals(tmAddress)) { ! ret = l.getFragment(); ! ! if (!enableNiceIDs||!looksLikeBeingAutoGenerated(ret)) { ! return ret; } } *************** *** 906,909 **** --- 908,912 ---- } } + return ret; } *************** *** 967,970 **** --- 970,976 ---- /* * $Log$ + * Revision 1.47 2007/05/21 17:16:17 mediumnet + * Rework and optimize getResourceID() to be only of O(n) performance instead of O(n^2) performance. + * * Revision 1.46 2007/05/21 17:07:06 mediumnet * Fix a little typo. |