public void testGetComponent() { Name name = new Name(expectedURI); Name.Component component2 = name.get(2); Assert.AssertTrue("Component at index 2 is incorrect", comp2.equals(component2)); }
/// <summary> /// Check if the component matches any of the exclude criteria. /// </summary> /// /// <param name="component">The name component to check.</param> /// <returns>True if the component matches any of the exclude criteria, /// otherwise false.</returns> public bool matches(Name.Component component) { for (int i = 0; i < entries_.Count; ++i) { if (get(i).getType() == net.named_data.jndn.Exclude.Type.ANY) { Exclude.Entry lowerBound = null; if (i > 0) { lowerBound = get(i - 1); } // Find the upper bound, possibly skipping over multiple ANY in a row. int iUpperBound; Exclude.Entry upperBound = null; for (iUpperBound = i + 1; iUpperBound < entries_.Count; ++iUpperBound) { if (get(iUpperBound).getType() == net.named_data.jndn.Exclude.Type.COMPONENT) { upperBound = get(iUpperBound); break; } } // If lowerBound != null, we already checked component equals lowerBound on the last pass. // If upperBound != null, we will check component equals upperBound on the next pass. if (upperBound != null) { if (lowerBound != null) { if (component.compare(lowerBound.getComponent()) > 0 && component.compare(upperBound.getComponent()) < 0) { return(true); } } else { if (component.compare(upperBound.getComponent()) < 0) { return(true); } } // Make i equal iUpperBound on the next pass. i = iUpperBound - 1; } else { if (lowerBound != null) { if (component.compare(lowerBound.getComponent()) > 0) { return(true); } } else { // entries_ has only ANY. return(true); } } } else { if (component.equals(get(i).getComponent())) { return(true); } } } return(false); }