Exemplo n.º 1
0
        private static IPreferenceArray cloneAndMergeInto(IPreferenceArray delegatePrefs,
                                                          long itemID,
                                                          long newUserID,
                                                          float value)
        {
            int length    = delegatePrefs == null ? 0 : delegatePrefs.Length();
            int newLength = length + 1;
            IPreferenceArray newPreferenceArray = new GenericItemPreferenceArray(newLength);

            // Set item ID once
            newPreferenceArray.SetItemID(0, itemID);

            int positionToInsert = 0;

            while (positionToInsert < length && newUserID > delegatePrefs.GetUserID(positionToInsert))
            {
                positionToInsert++;
            }

            for (int i = 0; i < positionToInsert; i++)
            {
                newPreferenceArray.SetUserID(i, delegatePrefs.GetUserID(i));
                newPreferenceArray.SetValue(i, delegatePrefs.GetValue(i));
            }
            newPreferenceArray.SetUserID(positionToInsert, newUserID);
            newPreferenceArray.SetValue(positionToInsert, value);
            for (int i = positionToInsert + 1; i < newLength; i++)
            {
                newPreferenceArray.SetUserID(i, delegatePrefs.GetUserID(i - 1));
                newPreferenceArray.SetValue(i, delegatePrefs.GetValue(i - 1));
            }

            return(newPreferenceArray);
        }
 public void testItemID()
 {
     IPreferenceArray prefs = new GenericItemPreferenceArray(3);
     Assert.AreEqual(3, prefs.Length());
     prefs.SetUserID(0, 1L);
     prefs.SetUserID(1, 2L);
     prefs.SetUserID(2, 3L);
     Assert.AreEqual(1L, prefs.GetUserID(0));
     Assert.AreEqual(2L, prefs.GetUserID(1));
     Assert.AreEqual(3L, prefs.GetUserID(2));
 }
        public void testItemID()
        {
            IPreferenceArray prefs = new GenericItemPreferenceArray(3);

            Assert.AreEqual(3, prefs.Length());
            prefs.SetUserID(0, 1L);
            prefs.SetUserID(1, 2L);
            prefs.SetUserID(2, 3L);
            Assert.AreEqual(1L, prefs.GetUserID(0));
            Assert.AreEqual(2L, prefs.GetUserID(1));
            Assert.AreEqual(3L, prefs.GetUserID(2));
        }
  private static IPreferenceArray cloneAndMergeInto(IPreferenceArray delegatePrefs,
                                                   long itemID,
                                                   long newUserID,
                                                   float value) {

    int length = delegatePrefs == null ? 0 : delegatePrefs.Length();
    int newLength = length + 1;
    IPreferenceArray newPreferenceArray = new GenericItemPreferenceArray(newLength);

    // Set item ID once
    newPreferenceArray.SetItemID(0, itemID);

    int positionToInsert = 0;
    while (positionToInsert < length && newUserID > delegatePrefs.GetUserID(positionToInsert)) {
      positionToInsert++;
    }

    for (int i = 0; i < positionToInsert; i++) {
      newPreferenceArray.SetUserID(i, delegatePrefs.GetUserID(i));
      newPreferenceArray.SetValue(i, delegatePrefs.GetValue(i));
    }
    newPreferenceArray.SetUserID(positionToInsert, newUserID);
    newPreferenceArray.SetValue(positionToInsert, value);
    for (int i = positionToInsert + 1; i < newLength; i++) {
      newPreferenceArray.SetUserID(i, delegatePrefs.GetUserID(i - 1));
      newPreferenceArray.SetValue(i, delegatePrefs.GetValue(i - 1));
    }

    return newPreferenceArray;
  }