Example usage for java.net URI hashCode

List of usage examples for java.net URI hashCode

Introduction

In this page you can find the example usage for java.net URI hashCode.

Prototype

public int hashCode() 

Source Link

Document

Returns a hash-code value for this URI.

Usage

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com");
    System.out.println("URI      : " + uri);
    System.out.println(uri.hashCode());
}

From source file:fusion.Fusion.java

private static void getSameAsLinks(File file) throws FileNotFoundException, IOException, AlignmentException {

    AlignmentParser a = new AlignmentParser();
    Alignment o = a.parse(file.toURI());
    for (Cell c : o) {

        java.net.URI value1 = c.getObject1AsURI(); // getLocalFromUri(
        java.net.URI value2 = c.getObject2AsURI();
        // keeps only the end of URI ?

        if (!distinctURLs.containsKey(value1.hashCode()))
            distinctURLs.put(value1.hashCode(), value1);
        if (!distinctURLs.containsKey(value2.hashCode()))
            distinctURLs.put(value2.hashCode(), value2);

        links.add(new SameAsLink(distinctURLs.get(value1.hashCode()), distinctURLs.get(value2.hashCode()))); // adding same as links
    }/*from  ww w . j a  v  a 2 s .  c  o  m*/

    // ADD SOURCES
    //detecter sources (et demander infos a l'utilisateur ?)

    for (Integer intName : distinctURLs.keySet()) {
        URI name = distinctURLs.get(intName);
        Source source = sources.get(name.getHost()); // detecter la source
        Instance instance = new Instance(name, source);

        instances.put(instance.getUri(), instance);
    }

}

From source file:eu.openanalytics.rsb.component.EmailDepositHandler.java

@PostConstruct
public void setupChannelAdapters() throws URISyntaxException {
    final List<DepositEmailConfiguration> depositEmailConfigurations = getConfiguration()
            .getDepositEmailAccounts();/*from  w w  w.  j a  v  a  2  s  .  c  o  m*/

    if ((depositEmailConfigurations == null) || (depositEmailConfigurations.isEmpty())) {
        return;
    }

    for (final DepositEmailConfiguration depositEmailConfiguration : depositEmailConfigurations) {
        final PeriodicTrigger trigger = new PeriodicTrigger(depositEmailConfiguration.getPollingPeriod(),
                TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(5000L);

        AbstractMailReceiver mailReceiver = null;

        final URI emailAccountURI = depositEmailConfiguration.getAccountURI();
        if (StringUtils.equals(emailAccountURI.getScheme(), "pop3")) {
            mailReceiver = new Pop3MailReceiver(emailAccountURI.toString());
        } else if (StringUtils.equals(emailAccountURI.getScheme(), "imap")) {
            mailReceiver = new ImapMailReceiver(emailAccountURI.toString());
            ((ImapMailReceiver) mailReceiver).setShouldMarkMessagesAsRead(true);
        } else {
            throw new IllegalArgumentException("Invalid email account URI: " + emailAccountURI);
        }

        mailReceiver.setBeanFactory(beanFactory);
        mailReceiver.setBeanName("rsb-email-ms-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        mailReceiver.setShouldDeleteMessages(true);
        mailReceiver.setMaxFetchSize(1);
        mailReceiver.afterPropertiesSet();
        final MailReceivingMessageSource fileMessageSource = new MailReceivingMessageSource(mailReceiver);
        final HeaderSettingMessageSourceWrapper<javax.mail.Message> messageSource = new HeaderSettingMessageSourceWrapper<javax.mail.Message>(
                fileMessageSource, EMAIL_CONFIG_HEADER_NAME, depositEmailConfiguration);

        final SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter();
        channelAdapter.setBeanFactory(beanFactory);
        channelAdapter.setBeanName("rsb-email-ca-" + emailAccountURI.getHost() + emailAccountURI.hashCode());
        channelAdapter.setOutputChannel(emailDepositChannel);
        channelAdapter.setSource(messageSource);
        channelAdapter.setTrigger(trigger);
        channelAdapter.afterPropertiesSet();
        channelAdapter.start();

        getLogger().info("Started channel adapter: " + channelAdapter);

        channelAdapters.add(channelAdapter);
    }
}

From source file:org.apache.hadoop.filecache.TrackerDistributedCacheManager.java

/**
 * Get the locally cached file or archive; it could either be
 * previously cached (and valid) or copy it from the {@link FileSystem} now.
 *
 * @param cache the cache to be localized, this should be specified as
 * new URI(scheme://scheme-specific-part/absolute_path_to_file#LINKNAME).
 * @param conf The Configuration file which contains the filesystem
 * @param subDir The base cache subDir where you want to localize the 
 *  files/archives/*from  w  ww .  j  a  va 2  s .co  m*/
 * @param fileStatus The file status on the dfs.
 * @param isArchive if the cache is an archive or a file. In case it is an
 *  archive with a .zip or .jar or .tar or .tgz or .tar.gz extension it will
 *  be unzipped/unjarred/untarred automatically
 *  and the directory where the archive is unzipped/unjarred/untarred is
 *  returned as the Path.
 *  In case of a file, the path to the file is returned
 * @param confFileStamp this is the hdfs file modification timestamp to verify
 * that the file to be cached hasn't changed since the job started
 * @param isPublic to know the cache file is accessible to public or private
 * @return the path to directory where the archives are unjarred in case of
 * archives, the path to the file where the file is copied locally
 * @throws IOException
 */
Path getLocalCache(URI cache, Configuration conf, String subDir, FileStatus fileStatus, boolean isArchive,
        long confFileStamp, boolean isPublic, CacheFile file) throws IOException {
    String key;
    String user = getLocalizedCacheOwner(isPublic);
    key = getKey(cache, conf, confFileStamp, user, isArchive);
    CacheStatus lcacheStatus;
    Path localizedPath = null;
    Path localPath = null;
    synchronized (cachedArchives) {
        lcacheStatus = cachedArchives.get(key);
        if (lcacheStatus == null) {
            // was never localized
            String uniqueString = (String.valueOf(random.nextLong()) + "_" + cache.hashCode() + "_"
                    + (confFileStamp % Integer.MAX_VALUE));
            String cachePath = new Path(subDir, new Path(uniqueString, makeRelative(cache, conf))).toString();
            localPath = lDirAllocator.getLocalPathForWrite(cachePath, fileStatus.getLen(), trackerConf,
                    isPublic);
            lcacheStatus = new CacheStatus(new Path(localPath.toString().replace(cachePath, "")), localPath,
                    new Path(subDir), uniqueString, isPublic ? null : user, key);
            cachedArchives.put(key, lcacheStatus);
        }

        //mark the cache for use.
        file.setStatus(lcacheStatus);
        lcacheStatus.incRefCount();
    }

    try {
        // do the localization, after releasing the global lock
        synchronized (lcacheStatus) {
            if (!lcacheStatus.isInited()) {
                if (isPublic) {
                    localizedPath = localizePublicCacheObject(conf, cache, confFileStamp, lcacheStatus,
                            fileStatus, isArchive);
                } else {
                    localizedPath = localPath;
                    if (!isArchive) {
                        //for private archives, the lengths come over RPC from the 
                        //JobLocalizer since the JobLocalizer is the one who expands
                        //archives and gets the total length
                        lcacheStatus.size = fileStatus.getLen();

                        // Increase the size and sub directory count of the cache
                        // from baseDirSize and baseDirNumberSubDir.
                        baseDirManager.addCacheInfoUpdate(lcacheStatus);
                    }
                }
                lcacheStatus.initComplete();
            } else {
                localizedPath = checkCacheStatusValidity(conf, cache, confFileStamp, lcacheStatus, fileStatus,
                        isArchive);
            }
        }
    } catch (IOException ie) {
        lcacheStatus.decRefCount();
        throw ie;
    }
    return localizedPath;
}

From source file:org.gatherdata.commons.model.impl.UniqueEntitySupport.java

public int hashCode(UniqueEntity entity) {
    final URI uid = entity.getUid();
    final int prime = 31;
    int result = 1;
    result = prime * result + ((uid == null) ? 0 : uid.hashCode());
    return result;
}

From source file:org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry.java

@SuppressFBWarnings(value = "DMI_BLOCKING_METHODS_ON_URL", justification = "Method call has been optimized, but we still need URLs as a fallback")
@Override/*from w  w w.jav a2 s  .  c o  m*/
public int hashCode() {
    // Performance optimization to avoid domain name resolution
    final URI uri = getURI();
    return uri != null ? uri.hashCode() : url.hashCode();
}