下面列出了java.util.Map#hashCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
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();
}
/**
* 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();
}
/**
* @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();
}
/**
* 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();
}
/**
* 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);
}
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;
}
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();
}
@Override
public int hashCode() {
Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments =
new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments );
return detectedOptions.hashCode()
^ thisOptionsToArguments.hashCode()
^ nonOptionArguments.hashCode();
}
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;
}
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);
}
/**
* 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;
}
@Override
public int hashCode() {
Map<AbstractOptionSpec<?>, List<String>> thisOptionsToArguments =
new HashMap<AbstractOptionSpec<?>, List<String>>( optionsToArguments );
return detectedOptions.hashCode()
^ thisOptionsToArguments.hashCode()
^ nonOptionArguments.hashCode();
}
/**
* 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));
}
CompoundBinaryTagImpl(final Map<String, BinaryTag> tags) {
this.tags = Collections.unmodifiableMap(tags);
this.hashCode = tags.hashCode();
}
private StateMetricContext(Map<String, String> data) {
this.data = data;
this.hashCode = data.hashCode();
}
public MapEntity(Map mapToWrap) {
this(mapToWrap, mapToWrap.hashCode());
}
@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;
}
protected int hashCodePiece(int hash, Map<String, Object> v, boolean isNull) {
return isNull ? hash : 31 * hash + v.hashCode();
}
public ConfigFeatureFlagValuesTransition(Map<Label, String> flagValues) {
this(ImmutableSortedMap.copyOf(flagValues), flagValues.hashCode());
}