Java URI Value Check isPrefix(final URI source, final URI other)

Here you can find the source of isPrefix(final URI source, final URI other)

Description

Checks whether the source URI is a prefix of the other URI.

License

Open Source License

Parameter

Parameter Description
source the source URI to check
other the URI to check the source against

Return

true if the source is a prefix of the other URI, false otherwise

Declaration

public static boolean isPrefix(final URI source, final URI other) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2000-2016 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

import java.net.URI;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

public class Main {
    /**//from w w w  .j  a v a2 s  .c o  m
     * Checks whether the source URI is a prefix of the other URI.
     * 
     * @param source
     *                the source URI to check
     * @param other
     *                the URI to check the source against
     * 
     * @return true if the source is a prefix of the other URI, false
     *         otherwise
     * */
    public static boolean isPrefix(final URI source, final URI other) {
        if ((source.getScheme() == null && other.getScheme() != null)
                || !source.getScheme().equals(other.getScheme())) {
            return false;
        }

        final IPath sourcePath = new Path(source.getPath());
        final IPath otherPath = new Path(other.getPath());
        return sourcePath.isPrefixOf(otherPath);
    }
}

Related

  1. isLocalURI(URI uri)
  2. isModuleURI(URI uri)
  3. isNormalized(String uriName)
  4. isOnTrustedUriWhiteList(final URI uri)
  5. isOriginForm(URI uri)
  6. isProjectCacheURI(java.net.URI uri)
  7. isRedirectEndpointUriValid(String redirectUri)
  8. isRedisSSLScheme(URI uri)
  9. isRemoteNamespace(URI ns)