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 testSetValue() { IPreferenceArray prefs = new GenericItemPreferenceArray(3); Assert.AreEqual(3, prefs.Length()); prefs.SetValue(0, 1.0f); prefs.SetValue(1, 2.0f); prefs.SetValue(2, 3.0f); Assert.AreEqual(1.0f, prefs.GetValue(0), EPSILON); Assert.AreEqual(2.0f, prefs.GetValue(1), EPSILON); Assert.AreEqual(3.0f, prefs.GetValue(2), EPSILON); }
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; }