下面列出了java.util.ArrayList#hashCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void testOffHeapAutoFree()
{
long sum = 0;
long constructed = 0;
while(true)
{
ArrayList list = new ArrayList();
for(int i=0;i<1000;i++)
{
list.add(new OffHeapTest(100));
constructed++;
}
sum += list.hashCode();
if ((constructed & ((1 << 10) - 1)) == 0)
{
System.out.println("constructed: "+constructed+", freed: "+ OffHeapCleaner.getInstance().getFreedCount());
}
if (constructed < 0)
{
break;
}
}
System.out.println("sum: "+sum);
}
public void testOffHeapAutoFreeAfterRealloc()
{
long sum = 0;
long constructed = 0;
while(true)
{
ArrayList list = new ArrayList();
for(int i=0;i<1000;i++)
{
OffHeapTest e = new OffHeapTest(100);
list.add(e);
e.reallocate(200);
constructed++;
}
sum += list.hashCode();
if ((constructed & ((1 << 10) - 1)) == 0)
{
System.out.println("constructed: "+constructed+", freed: "+ OffHeapCleaner.getInstance().getFreedCount());
}
if (constructed < 0)
{
break;
}
}
System.out.println("sum: "+sum);
}
boolean haveContentsChanged() {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Marking contacts as not changed.");
return false;
}
final long startTime = SystemClock.uptimeMillis();
final int contactCount = mManager.getContactCount();
if (contactCount > ContactsDictionaryConstants.MAX_CONTACTS_PROVIDER_QUERY_LIMIT) {
// If there are too many contacts then return false. In this rare case it is impossible
// to include all of them anyways and the cost of rebuilding the dictionary is too high.
// TODO: Sort and check only the most recent contacts?
return false;
}
if (contactCount != mManager.getContactCountAtLastRebuild()) {
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : Count changed from "
+ mManager.getContactCountAtLastRebuild() + " to " + contactCount);
}
return true;
}
final ArrayList<String> names = mManager.getValidNames(Contacts.CONTENT_URI);
if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
return true;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : No change detected in "
+ (SystemClock.uptimeMillis() - startTime) + " ms)");
}
return false;
}
boolean haveContentsChanged() {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Marking contacts as not changed.");
return false;
}
final long startTime = SystemClock.uptimeMillis();
final int contactCount = mManager.getContactCount();
if (contactCount > ContactsDictionaryConstants.MAX_CONTACTS_PROVIDER_QUERY_LIMIT) {
// If there are too many contacts then return false. In this rare case it is impossible
// to include all of them anyways and the cost of rebuilding the dictionary is too high.
// TODO: Sort and check only the most recent contacts?
return false;
}
if (contactCount != mManager.getContactCountAtLastRebuild()) {
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : Count changed from "
+ mManager.getContactCountAtLastRebuild() + " to " + contactCount);
}
return true;
}
final ArrayList<String> names = mManager.getValidNames(Contacts.CONTENT_URI);
if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
return true;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : No change detected in "
+ (SystemClock.uptimeMillis() - startTime) + " ms)");
}
return false;
}
public void testOffHeapAutoFreeManual()
{
long sum = 0;
long constructed = 0;
while(true)
{
ArrayList list = new ArrayList();
for(int i=0;i<1000;i++)
{
list.add(new OffHeapTest(100));
constructed++;
}
sum += list.hashCode();
for(int i=0;i<1000;i++)
{
OffHeapTest t = (OffHeapTest) list.get(i);
t.destroy();
}
if ((constructed & ((1 << 10) - 1)) == 0)
{
System.out.println("constructed: "+constructed+", freed: "+ OffHeapCleaner.getInstance().getFreedCount());
}
if (constructed < 0)
{
break;
}
}
System.out.println("sum: "+sum);
}
public int hashCode() {
ArrayList<Integer> hs = new ArrayList<Integer>(2 + f2e.length + e2f.length);
hs.add(e().hashCode());
hs.add(f().hashCode());
for (Set<Integer> af2e : f2e)
hs.add(Arrays.hashCode(af2e.toArray()));
for (Set<Integer> ae2f : e2f)
hs.add(Arrays.hashCode(ae2f.toArray()));
return hs.hashCode();
}
boolean haveContentsChanged() {
if (!PermissionsUtil.checkAllPermissionsGranted(
mContext, Manifest.permission.READ_CONTACTS)) {
Log.i(TAG, "No permission to read contacts. Marking contacts as not changed.");
return false;
}
final long startTime = SystemClock.uptimeMillis();
final int contactCount = mManager.getContactCount();
if (contactCount > ContactsDictionaryConstants.MAX_CONTACTS_PROVIDER_QUERY_LIMIT) {
// If there are too many contacts then return false. In this rare case it is impossible
// to include all of them anyways and the cost of rebuilding the dictionary is too high.
// TODO: Sort and check only the most recent contacts?
return false;
}
if (contactCount != mManager.getContactCountAtLastRebuild()) {
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : Count changed from "
+ mManager.getContactCountAtLastRebuild() + " to " + contactCount);
}
return true;
}
final ArrayList<String> names = mManager.getValidNames(Contacts.CONTENT_URI);
if (names.hashCode() != mManager.getHashCodeAtLastRebuild()) {
return true;
}
if (DebugFlags.DEBUG_ENABLED) {
Log.d(TAG, "haveContentsChanged() : No change detected in "
+ (SystemClock.uptimeMillis() - startTime) + " ms)");
}
return false;
}