Java Code Examples for java.util.Map#hashCode()

The following examples show how to use java.util.Map#hashCode() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Initializes this instance, determining the name of the set that will be used
 * and instantiating it.
 *
 * @param prefix basis for the generation of a unique set name
 */
private void setup(String prefix) {
    RequestContext context = getContext();
    helper = new SessionSetHelper(context.getRequest());

    if (StringUtils.isBlank(prefix)) {
        prefix = getListable().getClass().getName();
    }
    decl = prefix;

    Map params = getParamMap();
    if (!params.isEmpty()) {
        decl = decl + params.hashCode();
    }

    set = SessionSetHelper.lookupAndBind(context.getRequest(),
        decl);

}
 
Example 2
Source Project: RetrofitGO   File: OneReponsitory.java    License: Apache License 2.0 6 votes vote down vote up
public Flowable<Resource<MovieModel>> loadOneData(Map<String, String> params) {
    String mCacheKey = this.getClass().getName()
            + "." + Thread.currentThread().getStackTrace()[2].getMethodName()
            + "." + params.hashCode();
    return new CommonNetBoundResource<MovieModel>(CachePolicyMode.POLICY_NETWORK_ELSE_CACHE) {
        @NonNull
        @Override
        protected Flowable fetchFromNet() {
            return mOneWebService.getMovie(params).compose(RxHelper::handleResponse);
        }

        @Override
        protected String getCacheKey() {
            return mCacheKey;
        }
    }.getFlowable();
}
 
Example 3
Source Project: gcs   File: TrueTypeEmbedder.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Returns an uppercase 6-character unique tag for the given subset.
 */
public String getTag(Map<Integer, Integer> gidToCid)
{
    // deterministic
    long num = gidToCid.hashCode();

    // base25 encode
    StringBuilder sb = new StringBuilder();
    do
    {
        long div = num / 25;
        int mod = (int)(num % 25);
        sb.append(BASE25.charAt(mod));
        num = div;
    } while (num != 0 && sb.length() < 6);

    // pad
    while (sb.length() < 6)
    {
        sb.insert(0, 'A');
    }

    sb.append('+');
    return sb.toString();
}
 
Example 4
Source Project: sambox   File: FontUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return an uppercase 6-character unique tag for the given subset.
 */
public static String getTag(Map<Integer, Integer> gidToCid)
{
    // deterministic
    long num = gidToCid.hashCode();

    // base25 encode
    StringBuilder sb = new StringBuilder();
    do
    {
        long div = num / 25;
        int mod = (int) (num % 25);
        sb.append(BASE25.charAt(mod));
        num = div;
    } while (num != 0 && sb.length() < 6);

    // pad
    while (sb.length() < 6)
    {
        sb.insert(0, 'A');
    }

    return sb.append('+').toString();
}
 
Example 5
Source Project: PdfBox-Android   File: TrueTypeEmbedder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns an uppercase 6-character unique tag for the given subset.
 */
public String getTag(Map<Integer, Integer> gidToCid)
{
    // deterministic
    long num = gidToCid.hashCode();

    // base25 encode
    StringBuilder sb = new StringBuilder();
    do
    {
        long div = num / 25;
        int mod = (int)(num % 25);
        sb.append(BASE25.charAt(mod));
        num = div;
    } while (num != 0 && sb.length() < 6);

    // pad
    while (sb.length() < 6)
    {
        sb.insert(0, 'A');
    }

    sb.append('+');
    return sb.toString();
}
 
Example 6
/**
 * Initializes this instance, determining the name of the set that will be used
 * and instantiating it.
 *
 * @param prefix basis for the generation of a unique set name
 */
private void setup(String prefix) {
    RequestContext context = getContext();
    helper = new SessionSetHelper(context.getRequest());

    if (StringUtils.isBlank(prefix)) {
        prefix = getListable().getClass().getName();
    }
    decl = prefix;

    Map params = getParamMap();
    if (!params.isEmpty()) {
        decl = decl + params.hashCode();
    }

    set = SessionSetHelper.lookupAndBind(context.getRequest(),
        decl);

}
 
Example 7
Source Project: AsciidocFX   File: ChartBuilderService.java    License: Apache License 2.0 6 votes vote down vote up
public boolean chartBuild(String chartContent, String imagesDir, String imageTarget, Map<String, String> optMap) {

        if (!imageTarget.endsWith(".png")) {
            return false;
        }

        Integer cacheHit = current.getCache().get(imageTarget);
        int hashCode = (imageTarget + imagesDir + chartContent).hashCode() + optMap.hashCode();

        if (Objects.nonNull(cacheHit))
            if (hashCode == cacheHit) {
                return false;
            }

        current.getCache().put(imageTarget, hashCode);

        currentRoot = current.currentTab().getParentOrWorkdir();
        imagePath = currentRoot.resolve(imageTarget);

        return true;
    }
 
Example 8
Source Project: businessworks   File: ProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
IndicesCallbackFilter(List<Method> methods) {
  final Map<Object, Integer> indices = Maps.newHashMap();
  for (int i = 0; i < methods.size(); i++) {
    indices.put(MethodWrapper.create(methods.get(i)), i);
  }
  this.indices = indices;
  this.hashCode = indices.hashCode();
}
 
Example 9
Source Project: gemfirexd-oss   File: OptionSet.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments =
        new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments );
    return detectedOptions.hashCode()
        ^ thisOptionsToArguments.hashCode()
        ^ nonOptionArguments.hashCode();
}
 
Example 10
Source Project: lucene-solr   File: Clause.java    License: Apache License 2.0 5 votes vote down vote up
Clause(Map<String, Object> original, Condition tag, Condition globalTag, boolean isStrict, Put put, boolean nodeSetPresent) {
  this.hashCode = original.hashCode();
  this.original = original;
  this.tag = tag;
  this.globalTag = globalTag;
  this.globalTag.clause = this;
  this.type = null;
  this.hasComputedValue = false;
  this.strict = isStrict;
  derivedFrom = null;
  this.put = put;
  this.nodeSetPresent = nodeSetPresent;
}
 
Example 11
Source Project: cuba   File: AbstractWindow.java    License: Apache License 2.0 5 votes vote down vote up
protected int getScreenHashCode(Screen screen) {
    ScreenContext screenContext = UiControllerUtils.getScreenContext(screen);
    WindowInfo windowInfo = screenContext.getWindowInfo();

    Map<String, Object> params = getFrame().getContext().getParams();
    return windowInfo.hashCode() + (params != null ? params.hashCode() : 0);
}
 
Example 12
/**
 * Gets the {@link ConnectionAdapter} that corresponds to the given {@link ConnectionInformation} and {@link Operator}.
 * Uses the {@link ValueProviderHandlerRegistry#injectValues(ConnectionInformation, Operator, boolean) injection mechanism}
 * to create a fully functional adapter and {@link #validate(Function, Function) validates} the adapter before
 * returning it. If the validation fails, will throw a {@link ConnectionAdapterException} with the given operator,
 * connection information's name and type, as well as the {@link ValidationResult}.
 *
 * @param connection
 * 		the connection; must not be {@code null}
 * @param operator
 * 		the operator for context; may be {@code null}
 * @return the adapter, never {@code null}
 * @throws ConnectionAdapterException
 * 		if a {@link #validate(Function, Function) validation} on the injected values fails
 * @throws ConfigurationException
 * 		if an error occurs
 * @see ValueProviderHandlerRegistry#injectValues(ConnectionInformation, Operator, boolean)
 * @see #create(String, Map)
 */
public T getAdapter(ConnectionInformation connection, Operator operator) throws ConnectionAdapterException, ConfigurationException {
	ConnectionCacheHash hash = new ConnectionCacheHash();
	try {
		Repository repo = connection.getRepository();
		if (repo != null) {
			hash.location = new RepositoryLocationBuilder().withExpectedDataEntryType(ConnectionEntry.class).buildFromPathComponents(repo.getName(),
					new String[]{Folder.CONNECTION_FOLDER_NAME, connection.getConfiguration().getName()}).getAbsoluteLocation();
		} else {
			hash.location = connection.getConfiguration().getName();
		}
	} catch (MalformedRepositoryLocationException e) {
		// ignore
	}
	ConnectionConfiguration configuration = ValidationUtil.requireNonNull(connection, "connection").getConfiguration();
	Map<String, ConfigurationParameter> keyMap = configuration.getKeyMap();

	Map<String, String> valueMap = ValueProviderHandlerRegistry.getInstance().injectValues(connection, operator, false);
	ValidationResult validation = validate(valueMap::get, keyMap::get);
	if (validation.getType() == ResultType.FAILURE) {
		throw new ConnectionAdapterException(operator, configuration, validation);
	}
	// remove all null values and get rid of group prefix
	Map<String, String> adapterMap = valueMap.entrySet().stream().filter(e ->  e.getValue() != null)
			.collect(Collectors.toMap(e -> e.getKey().substring(e.getKey().indexOf('.') + 1), Entry::getValue));
	if (operator != null && operator.getProcess() != null) {
		hash.paramHash = adapterMap.hashCode();
		T cachedAdapter = findAdapter(operator.getProcess(), getConfigurableClass(), hash);
		if (cachedAdapter != null) {
			return cachedAdapter;
		}
	}
	T adapter = create(configuration.getName(), adapterMap);
	if (operator != null && operator.getProcess() != null) {
		registerAdapter(operator.getProcess(), hash, adapter);
	}
	return adapter;
}
 
Example 13
Source Project: gemfirexd-oss   File: OptionSet.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int hashCode() {
    Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments =
        new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments );
    return detectedOptions.hashCode()
        ^ thisOptionsToArguments.hashCode()
        ^ nonOptionArguments.hashCode();
}
 
Example 14
/**
 * Adds a new web resource to mock a request.
 *
 * @param parameters
 * @param result
 */
public void setWebResource(Map<String, String> parameters, String result) {
	int hash = parameters.hashCode();
	if (this.webResources.containsKey(hash)) {
		logger.warn("Overwriting mocked result for parameters "
				+ parameters.toString());
	}
	this.webResources.put(hash, result.getBytes(StandardCharsets.UTF_8));
}
 
Example 15
Source Project: adventure   File: CompoundBinaryTagImpl.java    License: MIT License 4 votes vote down vote up
CompoundBinaryTagImpl(final Map<String, BinaryTag> tags) {
  this.tags = Collections.unmodifiableMap(tags);
  this.hashCode = tags.hashCode();
}
 
Example 16
Source Project: vespa   File: StateMetricContext.java    License: Apache License 2.0 4 votes vote down vote up
private StateMetricContext(Map<String, String> data) {
    this.data = data;
    this.hashCode = data.hashCode();
}
 
Example 17
Source Project: cqengine   File: MapEntity.java    License: Apache License 2.0 4 votes vote down vote up
public MapEntity(Map mapToWrap) {
    this(mapToWrap, mapToWrap.hashCode());
}
 
Example 18
Source Project: hawkular-agent   File: ResourceManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int compare(Resource<L> r1, Resource<L> r2) {
    // make sure we are looking at the same resource
    int c = r1.getID().compareTo(r2.getID());
    if (c != 0) {
        return c;
    }

    // see if the names changed
    c = r1.getName().compareTo(r2.getName());
    if (c != 0) {
        return c;
    }

    // see if the resource configuration property values are the same
    Collection<ResourceConfigurationPropertyInstance<L>> rcp1 = r1.getResourceConfigurationProperties();
    Collection<ResourceConfigurationPropertyInstance<L>> rcp2 = r2.getResourceConfigurationProperties();
    if (rcp1.size() == rcp2.size()) {
        if (!rcp1.isEmpty()) {
            Map<ResourceConfigurationPropertyInstance<L>, String> rcp1Map = new HashMap<>(rcp1.size());
            for (ResourceConfigurationPropertyInstance<L> rcp1Item : rcp1) {
                rcp1Map.put(rcp1Item, rcp1Item.getValue());
            }
            Map<ResourceConfigurationPropertyInstance<L>, String> rcp2Map = new HashMap<>(rcp2.size());
            for (ResourceConfigurationPropertyInstance<L> rcp2Item : rcp2) {
                rcp2Map.put(rcp2Item, rcp2Item.getValue());
            }
            if (!rcp1Map.equals(rcp2Map)) {
                return rcp1Map.hashCode() < rcp2Map.hashCode() ? -1 : 1;
            }
        }
    } else {
        return rcp1.size() < rcp2.size() ? -1 : 1;
    }

    // see if the general properties are the same
    if (!r1.getProperties().equals(r2.getProperties())) {
        return r1.getProperties().hashCode() < r2.getProperties().hashCode() ? -1 : 1;
    }

    // everything we care about didn't change - consider them the same resource
    return 0;
}
 
Example 19
Source Project: spork   File: SchemaTuple.java    License: Apache License 2.0 4 votes vote down vote up
protected int hashCodePiece(int hash, Map<String, Object> v, boolean isNull) {
    return isNull ? hash : 31 * hash + v.hashCode();
}
 
Example 20
public ConfigFeatureFlagValuesTransition(Map<Label, String> flagValues) {
  this(ImmutableSortedMap.copyOf(flagValues), flagValues.hashCode());
}