com.am.job.HashMapParams Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of job-core Show documentation
Show all versions of job-core Show documentation
The basic core of thread asynchrony is independent of the platform and facilitates the further realization of thread asynchrony in Android or HarmonyOS.
The newest version!
/*
* Copyright (C) 2021 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.am.job;
import java.lang.ref.WeakReference;
import java.util.HashMap;
/**
* 使用HashMap实现的任务参数
* Created by Alex on 2021/3/12.
*/
class HashMapParams extends HashMapDataArray implements BaseJob.Params {
private final HashMap> mWeakParams = new HashMap<>();
private boolean contains(int key) {
return mWeakParams.containsKey(key);
}
@Override
public void clearWeak() {
mWeakParams.clear();
}
@Override
public void putWeak(int key, Object value) {
if (value == null) {
mWeakParams.remove(key);
return;
}
mWeakParams.put(key, new WeakReference<>(value));
}
@Override
public V getWeak(int key, V defaultValue) {
if (contains(key)) {
final WeakReference