/** * If some or all of the children of this name are versions, returns the latest version among * them. * * @return ContentName The latest version component */ public ContentName getLatestVersionChildName() { // of the available names in _children that are version components, // find the latest one (version-wise) // names are sorted, so the last one that is a version should be the latest version // ListIterator previous doesn't work unless you've somehow gotten it to point at the end... ContentName theName = null; ContentName latestName = null; CCNTime latestTimestamp = null; Iterator<ContentName> it = _children.iterator(); // TODO these are sorted -- we just need to iterate through them in reverse order. Having // trouble finding something like C++'s reverse iterators to do that (linked list iterators // can go backwards -- but you have to run them to the end first). while (it.hasNext()) { theName = it.next(); if (VersioningProfile.isVersionComponent(theName.component(0))) { if (null == latestName) { latestName = theName; latestTimestamp = VersioningProfile.getVersionComponentAsTimestamp(theName.component(0)); } else { CCNTime thisTimestamp = VersioningProfile.getVersionComponentAsTimestamp(theName.component(0)); if (thisTimestamp.after(latestTimestamp)) { latestName = theName; latestTimestamp = thisTimestamp; } } } } return latestName; }
/** * Returns the latest version available under this prefix as a CCNTime object. * * @return CCNTime Latest child version as CCNTime */ public CCNTime getLatestVersionChildTime() { ContentName latestVersion = getLatestVersionChildName(); if (null != latestVersion) { return VersioningProfile.getVersionComponentAsTimestamp(latestVersion.component(0)); } return null; }
/** * Create a VersionNumber from a byte array, such as from a ContentName component. * * @param versionComponent */ public VersionNumber(byte[] versionComponent) { _version = VersioningProfile.getVersionComponentAsTimestamp(versionComponent); _versionComponent = copyOf(versionComponent, versionComponent.length); _binaryTime = _version.toBinaryTimeAsLong(); }