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

The following examples show how to use java.util.ArrayList#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: TestPerformance.java    From reladomo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: TestPerformance.java    From reladomo with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: ContactsContentObserver.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: ContactsContentObserver.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: TestPerformance.java    From reladomo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: AbstractWordAlignment.java    From phrasal with GNU General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: ContactsContentObserver.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
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;
}