Java Code Examples for java.net.URI.equals()

The following are Jave code examples for showing how to use equals() of the java.net.URI class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pac4j-plus   File: UriUtils.java   View Source Code Vote up 6 votes
/**
 * Compares two URIs for equality, ignoring default port numbers for selected protocols.
 * 
 * By default, {@link URI#equals(Object)} doesn't take into account default port numbers, so http://server:80/resource is a different
 * URI than http://server/resource.
 * 
 * And URLs should not be used for comparison, as written here:
 * http://stackoverflow.com/questions/3771081/proper-way-to-check-for-url-equality
 * 
 * @param uri1
 *            URI 1 to be compared.
 * @param uri2
 *            URI 2 to be compared.
 * 
 * @return True if both URIs are equal.
 */
public static boolean urisEqualAfterPortNormalization(final URI uri1, final URI uri2) {
    if (uri1 == null && uri2 == null) {
        return true;
    }
    if (uri1 == null || uri2 == null) {
        return false;
    }
    
    try {
        URI normalizedUri1 = normalizePortNumbersInUri(uri1);
        URI normalizedUri2 = normalizePortNumbersInUri(uri2);
        boolean eq = normalizedUri1.equals(normalizedUri2);
        return eq;
    } catch (URISyntaxException use) {
        logger.error("Cannot compare 2 URIs.", use);
        return false;    
    }
}
 
Example 2
Project: OpenJSharp   File: ExternalAttachmentsUnmarshaller.java   View Source Code Vote up 6 votes
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 3
Project: incubator-netbeans   File: XMLUtils.java   View Source Code Vote up 5 votes
public static Element saveExtendedUri(
        final ExtendedUri uri,
        final Element element) {
    final Document document = element.getOwnerDocument();
    
    element.setAttribute("size", Long.toString(uri.getSize()));
    element.setAttribute("md5", uri.getMd5());
    
    // the default uri would be either "local" (if it's present) or the
    // "remote" one
    Element uriElement = document.createElement("default-uri");
    if (uri.getLocal() != null) {
        uriElement.setTextContent(uri.getLocal().toString());
    } else {
        uriElement.setTextContent(uri.getRemote().toString());
    }
    element.appendChild(uriElement);
    
    // if the "local" uri is not null, we should save the "remote" uri as the
    // first alternate, unless it's the same as the local
    if ((uri.getLocal() != null) && !uri.getRemote().equals(uri.getLocal())) {
        uriElement = document.createElement("alternate-uri");
        
        uriElement.setTextContent(uri.getRemote().toString());
        element.appendChild(uriElement);
    }
    
    for (URI alternateUri: uri.getAlternates()) {
        if (!alternateUri.equals(uri.getRemote())) {
            uriElement = document.createElement("alternate-uri");
            
            uriElement.setTextContent(alternateUri.toString());
            element.appendChild(uriElement);
        }
    }
    
    return element;
}
 
Example 4
Project: incubator-netbeans   File: PathFinders.java   View Source Code Vote up 5 votes
private static synchronized boolean shouldIgnore (
        @NonNull final URI key,
        @NonNull final URI value) {
    if (!key.equals(currentKey)) {
        return false;
    }
    return currentValues.contains(value);
}
 
Example 5
Project: incubator-netbeans   File: PathFinders.java   View Source Code Vote up 5 votes
private static synchronized void ignore(
        @NonNull final URI key,
        @NonNull final URI value) {
    if (!key.equals(currentKey)) {
        currentKey = key;
        currentValues = new HashSet<URI>();
    }
    currentValues.add(value);
}
 
Example 6
Project: incubator-netbeans   File: ActionFilterNode.java   View Source Code Vote up 5 votes
private static synchronized boolean shouldIgnore (
        @NonNull final URI key,
        @NonNull final URI value) {
    if (!key.equals(currentKey)) {
        return false;
    }
    return currentValues.contains(value);
}
 
Example 7
Project: incubator-netbeans   File: ActionFilterNode.java   View Source Code Vote up 5 votes
private static synchronized void ignore(
        @NonNull final URI key,
        @NonNull final URI value) {
    if (!key.equals(currentKey)) {
        currentKey = key;
        currentValues = new HashSet<URI>();
    }
    currentValues.add(value);
}
 
Example 8
Project: incubator-netbeans   File: ParentChildCollocationQuery.java   View Source Code Vote up 5 votes
@Override public boolean areCollocated(URI file1, URI file2) {
    if (file1.equals(file2)) {
        return true;
    }
    String f1 = file1.toString();
    if (!f1.endsWith("/")) {
        f1 += "/";
    }
    String f2 = file2.toString();
    if (!f2.endsWith("/")) {
        f2 += "/";
    }
    return f1.startsWith(f2) || f2.startsWith(f1);
}
 
Example 9
Project: openjdk-jdk10   File: T6440333.java   View Source Code Vote up 5 votes
void test(String... args) throws IOException {
    File path = test_src.getCanonicalFile();
    File src = new File(new File(path, "."), "T6440333.java");
    JavaFileObject fo = fm.getJavaFileObjects(src).iterator().next();
    URI expect = src.getCanonicalFile().toURI();
    System.err.println("Expect " + expect);
    System.err.println("Found  " + fo.toUri());
    if (!expect.equals(fo.toUri())) {
        throw new AssertionError();
    }
}
 
Example 10
Project: openjdk-jdk10   File: Test.java   View Source Code Vote up 5 votes
static void eq0(URI u, URI v) throws URISyntaxException {
    testCount++;
    if (!u.equals(v))
        throw new RuntimeException("Not equal: " + u + " " + v);
    int uh = u.hashCode();
    int vh = v.hashCode();
    if (uh != vh)
        throw new RuntimeException("Hash codes not equal: "
                                   + u + " " + Integer.toHexString(uh) + " "
                                   + v + " " + Integer.toHexString(vh));
    out.println();
    out.println(u + " == " + v
                + "  [" + Integer.toHexString(uh) + "]");
}
 
Example 11
Project: AndroidBackendlessChat   File: GraphObjectAdapter.java   View Source Code Vote up 5 votes
private void downloadProfilePicture(final String profileId, URI pictureURI, final ImageView imageView) {
    if (pictureURI == null) {
        return;
    }

    // If we don't have an imageView, we are pre-fetching this image to store in-memory because we
    // think the user might scroll to its corresponding list row. If we do have an imageView, we
    // only want to queue a download if the view's tag isn't already set to the URL (which would mean
    // it's already got the correct picture).
    boolean prefetching = imageView == null;
    if (prefetching || !pictureURI.equals(imageView.getTag())) {
        if (!prefetching) {
            // Setting the tag to the profile ID indicates that we're currently downloading the
            // picture for this profile; we'll set it to the actual picture URL when complete.
            imageView.setTag(profileId);
            imageView.setImageResource(getDefaultPicture());
        }

        ImageRequest.Builder builder = new ImageRequest.Builder(context.getApplicationContext(), pictureURI)
                .setCallerTag(this)
                .setCallback(
                        new ImageRequest.Callback() {
                            @Override
                            public void onCompleted(ImageResponse response) {
                                processImageResponse(response, profileId, imageView);
                            }
                        });

        ImageRequest newRequest = builder.build();
        pendingRequests.put(profileId, newRequest);

        ImageDownloader.downloadAsync(newRequest);
    }
}
 
Example 12
Project: openjdk-jdk10   File: UriImportExport.java   View Source Code Vote up 5 votes
/**
 * Test URI -> Path -> URI
 */
static void testUri(String s) throws Exception {
    URI uri = URI.create(s);
    log.println(uri);
    Path path = Paths.get(uri);
    log.println("  --> " + path);
    URI result = path.toUri();
    log.println("  --> " + result);
    if (!result.equals(uri)) {
        log.println("FAIL: Expected " + uri + ", got " + result);
        failures++;
    }
    log.println();
}
 
Example 13
Project: iTAP-controller   File: OFSwitch.java   View Source Code Vote up 5 votes
@Override
public boolean hasAnotherMaster() {

	//TODO: refactor get connection to not throw illegal arg exceptions
	IOFConnection mainCxn = this.getConnection(OFAuxId.MAIN);

	if(mainCxn != null) {

		// Determine the local URI
		InetSocketAddress address = (InetSocketAddress) mainCxn.getLocalInetAddress();
		URI localURI = URIUtil.createURI(address.getHostName(), address.getPort());

		for(Entry<URI,Map<OFAuxId, OFBsnControllerConnection>> entry : this.controllerConnections.entrySet()) {

			// Don't check our own controller connections
			URI uri = entry.getKey();
			if(!localURI.equals(uri)){

				// We only care for the MAIN connection
				Map<OFAuxId, OFBsnControllerConnection> cxns = this.controllerConnections.get(uri);
				OFBsnControllerConnection controllerCxn = cxns.get(OFAuxId.MAIN);

				if(controllerCxn != null) {
					// If the controller id disconnected or not master we know it is not connected
					if(controllerCxn.getState() == OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED
							&& controllerCxn.getRole() == OFControllerRole.ROLE_MASTER){
						return true;
					}
				} else {
					log.warn("Unable to find controller connection with aux id "
							+ "MAIN for switch {} on controller with URI {}.",
							this, uri);
				}
			}
		}
	}
	return false;
}
 
Example 14
Project: lams   File: RedirectLocations.java   View Source Code Vote up 5 votes
/**
 * Removes a URI from the collection.
 */
public boolean remove(final URI uri) {
    boolean removed = this.unique.remove(uri);
    if (removed) {
        Iterator<URI> it = this.all.iterator();
        while (it.hasNext()) {
            URI current = it.next();
            if (current.equals(uri)) {
                it.remove();
            }
        }
    }
    return removed;
}
 
Example 15
Project: FirefoxData-android   File: RedirectLocations.java   View Source Code Vote up 5 votes
/**
 * Removes a URI from the collection.
 */
public boolean remove(final URI uri) {
    final boolean removed = this.unique.remove(uri);
    if (removed) {
        final Iterator<URI> it = this.all.iterator();
        while (it.hasNext()) {
            final URI current = it.next();
            if (current.equals(uri)) {
                it.remove();
            }
        }
    }
    return removed;
}
 
Example 16
Project: jdk8u-jdk   File: Test.java   View Source Code Vote up 5 votes
static void eq0(URI u, URI v) throws URISyntaxException {
    testCount++;
    if (!u.equals(v))
        throw new RuntimeException("Not equal: " + u + " " + v);
    int uh = u.hashCode();
    int vh = v.hashCode();
    if (uh != vh)
        throw new RuntimeException("Hash codes not equal: "
                                   + u + " " + Integer.toHexString(uh) + " "
                                   + v + " " + Integer.toHexString(vh));
    out.println();
    out.println(u + " == " + v
                + "  [" + Integer.toHexString(uh) + "]");
}
 
Example 17
Project: jdk8u-jdk   File: Test.java   View Source Code Vote up 5 votes
static void ne0(URI u, URI v) throws URISyntaxException {
    testCount++;
    if (u.equals(v))
        throw new RuntimeException("Equal: " + u + " " + v);
    out.println();
    out.println(u + " != " + v
                + "  [" + Integer.toHexString(u.hashCode())
                + " " + Integer.toHexString(v.hashCode())
                + "]");
}
 
Example 18
Project: fresco_floodlight   File: OFSwitch.java   View Source Code Vote up 5 votes
@Override
public boolean hasAnotherMaster() {

	//TODO: refactor get connection to not throw illegal arg exceptions
	IOFConnection mainCxn = this.getConnection(OFAuxId.MAIN);

	if(mainCxn != null) {

		// Determine the local URI
		InetSocketAddress address = (InetSocketAddress) mainCxn.getLocalInetAddress();
		URI localURI = URIUtil.createURI(address.getHostName(), address.getPort());

		for(Entry<URI,Map<OFAuxId, OFBsnControllerConnection>> entry : this.controllerConnections.entrySet()) {

			// Don't check our own controller connections
			URI uri = entry.getKey();
			if(!localURI.equals(uri)){

				// We only care for the MAIN connection
				Map<OFAuxId, OFBsnControllerConnection> cxns = this.controllerConnections.get(uri);
				OFBsnControllerConnection controllerCxn = cxns.get(OFAuxId.MAIN);

				if(controllerCxn != null) {
					// If the controller id disconnected or not master we know it is not connected
					if(controllerCxn.getState() == OFBsnControllerConnectionState.BSN_CONTROLLER_CONNECTION_STATE_CONNECTED
							&& controllerCxn.getRole() == OFControllerRole.ROLE_MASTER){
						return true;
					}
				} else {
					log.warn("Unable to find controller connection with aux id "
							+ "MAIN for switch {} on controller with URI {}.",
							this, uri);
				}
			}
		}
	}
	return false;
}
 
Example 19
Project: lambdora   File: LambdoraLdp.java   View Source Code Vote up 4 votes
private boolean isRoot(final URI internalURI) {
    return internalURI.equals(rootURI);
}
 
Example 20
Project: AndroidBackendlessChat   File: UserSettingsFragment.java   View Source Code Vote up 4 votes
private void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (isSessionOpen()) {
        connectedStateLabel.setTextColor(getResources().getColor(R.color.com_facebook_usersettingsfragment_connected_text_color));
        connectedStateLabel.setShadowLayer(1f, 0f, -1f,
                getResources().getColor(R.color.com_facebook_usersettingsfragment_connected_shadow_color));
        
        if (user != null) {
            ImageRequest request = getImageRequest();
            if (request != null) {
                URI requestUrl = request.getImageUri();
                // Do we already have the right picture? If so, leave it alone.
                if (!requestUrl.equals(connectedStateLabel.getTag())) {
                    if (user.getId().equals(userProfilePicID)) {
                        connectedStateLabel.setCompoundDrawables(null, userProfilePic, null, null);
                        connectedStateLabel.setTag(requestUrl);
                    } else {
                        ImageDownloader.downloadAsync(request);
                    }
                }
            }
            connectedStateLabel.setText(user.getName());
        } else {
            connectedStateLabel.setText(getResources().getString(
                    R.string.com_facebook_usersettingsfragment_logged_in));
            Drawable noProfilePic = getResources().getDrawable(R.drawable.com_facebook_profile_default_icon);
            noProfilePic.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            connectedStateLabel.setCompoundDrawables(null, noProfilePic, null, null);
        }
    } else {
        int textColor = getResources().getColor(R.color.com_facebook_usersettingsfragment_not_connected_text_color);
        connectedStateLabel.setTextColor(textColor);
        connectedStateLabel.setShadowLayer(0f, 0f, 0f, textColor);
        connectedStateLabel.setText(getResources().getString(
                R.string.com_facebook_usersettingsfragment_not_logged_in));
        connectedStateLabel.setCompoundDrawables(null, null, null, null);
        connectedStateLabel.setTag(null);
    }
}