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

The following examples show how to use java.util.Map#hashCode() . 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
Source File: ChartBuilderService.java    From AsciidocFX with 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 2
Source File: ListSessionSetHelper.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 3
Source File: OneReponsitory.java    From RetrofitGO with 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 4
Source File: TrueTypeEmbedder.java    From gcs with 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 5
Source File: TrueTypeEmbedder.java    From PdfBox-Android with 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
Source File: FontUtils.java    From sambox with 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 7
Source File: ListSessionSetHelper.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 8
Source File: OptionSet.java    From gemfirexd-oss with 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 9
Source File: MockBasicApiConnection.java    From Wikidata-Toolkit with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: ConnectionAdapterHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 11
Source File: AbstractWindow.java    From cuba with 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
Source File: Clause.java    From lucene-solr with 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 13
Source File: OptionSet.java    From gemfirexd-oss with 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
Source File: ProxyFactory.java    From businessworks with 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 15
Source File: MapEntity.java    From cqengine with Apache License 2.0 4 votes vote down vote up
public MapEntity(Map mapToWrap) {
    this(mapToWrap, mapToWrap.hashCode());
}
 
Example 16
Source File: StateMetricContext.java    From vespa with 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 File: ResourceManager.java    From hawkular-agent with 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 18
Source File: SchemaTuple.java    From spork with 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 19
Source File: ConfigFeatureFlagTransitionFactory.java    From bazel with Apache License 2.0 4 votes vote down vote up
public ConfigFeatureFlagValuesTransition(Map<Label, String> flagValues) {
  this(ImmutableSortedMap.copyOf(flagValues), flagValues.hashCode());
}
 
Example 20
Source File: CompoundBinaryTagImpl.java    From adventure with MIT License 4 votes vote down vote up
CompoundBinaryTagImpl(final Map<String, BinaryTag> tags) {
  this.tags = Collections.unmodifiableMap(tags);
  this.hashCode = tags.hashCode();
}