public void TestTwoItemsWithSameItemIdAreEqual() { var item1 = new Item(2009, new TimeSpan(10000)); var item2 = new Item(2009, TimeSpan.Zero); Assert.IsTrue(item1.Equals(item2)); Assert.IsTrue(item2.Equals(item1)); // one of the gurantees of equals Assert.IsFalse(item1.Equals(null)); Assert.AreNotSame(item1, item2); }
bool IsTomboy(Item item) { return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("tomboy")); }
private void DrawItem(Graphics g,Item item,Bar bar,bool hot,bool pressed) { SolidBrush textBrush = new SolidBrush(hot ? m_ViewStyle.BarItemHotTextColor : m_ViewStyle.BarItemTextColor); if(hot || item.Equals(m_StuckenItem)){ Rectangle iRect = new Rectangle(item.Bounds.Location,item.Bounds.Size); ItemsStyle itemStyle = bar.ItemsStyle; //--- If must use default item style ---------// //--- First load from ViewStyle if(bar.ItemsStyle == ItemsStyle.UseDefault){ itemStyle = m_ViewStyle.BarItemsStyle; } //--- If ViewStyle retuned UseDefault, set IconSelect as default if(itemStyle == ItemsStyle.UseDefault){ itemStyle = ItemsStyle.IconSelect; } //-------------------------------------------// //--- If item style is IconSelect if(itemStyle == ItemsStyle.IconSelect){ iRect = new Rectangle(((this.Width-32)/2)-1,item.Bounds.Y+2,34,34); } //------- Draw item -----------------------------------------------------------// //--- if not stucken(selected) item if(!item.Equals(m_StuckenItem)){ if(pressed){ g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemPressedColor),iRect); } else{ g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemHotColor),iRect); } } else{ //---- If stucken(selected) item g.FillRectangle(new SolidBrush(m_ViewStyle.BarItemSelectedColor),iRect); textBrush = new SolidBrush(m_ViewStyle.BarItemSelectedTextColor); } // Draw border g.DrawRectangle(new Pen(m_ViewStyle.BarItemBorderHotColor),iRect); //----------------------------------------------------------------------------// } else{ //this.Invalidate(new Rectangle(item.Bounds.X,item.Bounds.Y,item.Bounds.Width+1,item.Bounds.Height+1)); //g.FillRectangle(new SolidBrush(m_ViewStyle.BarClientAreaColor1),item.Bounds.X,item.Bounds.Y,item.Bounds.Width+1,item.Bounds.Height+1); } //---- Draw image ---------------------------// Rectangle imgRect = new Rectangle((this.Width-32)/2,item.Bounds.Y+4,32,32); if(item.ImageIndex > -1 && this.ImageList != null && item.ImageIndex < this.ImageList.Images.Count){ g.DrawImage((Image)ImageList.Images[item.ImageIndex],imgRect); } //--------------------------------------------// //---- Draw items text ---------------------------------------------------------------// Rectangle txtRect = new Rectangle(item.Bounds.X+2,imgRect.Bottom+3,item.Bounds.Width,item.Bounds.Bottom - imgRect.Bottom + 3); g.DrawString(item.Caption,bar.ItemsFont,textBrush,txtRect,bar.ItemsStringFormat); //-------------------------------------------------------------------------------------// }
public static bool IsSkype(Item item) { return item.Equals (Services.UniverseFactory.MaybeApplicationItemFromCommand ("skype")); }
/// <summary> /// Adds a given number of the given Item type to this Inventory /// </summary> /// <param name="type">The Item type to add</param> /// <param name="quantity">The number of items to add</param> public void addItem(Item type, int quantity) { if (quantity < 0 || type.Equals(Item.Nothing)) return; //bad arguments if (this.items[(int)type] == 0) { this.order[numTypes++] = (int)type; } this.items[(int)type] += quantity; total += quantity; // push event InventoryEventArgs args = new InventoryEventArgs(); args.type = type; args.quantity = quantity; pushEvent(args); }
/// <summary> /// Removes a given number of the given item type from this Inventory /// </summary> /// <param name="type">The Item type to remove</param> /// <param name="quantity">The number of items to remove</param> public void removeItem(Item type, int quantity) { if (quantity < 0 || type.Equals(Item.Nothing)) return; //bad arguments if (this.items[(int)type] <= quantity) { int i = 0; for (; order[i] != (int)type; i++) ; Array.Copy(order, i + 1, order, i, numTypes - 1 - i); order[numTypes - 1] = -1; numTypes--; // O(n) operation quantity = this.items[(int)type]; //remove all items of this type } this.items[(int)type] -= quantity; this.total -= quantity; // push event InventoryEventArgs args = new InventoryEventArgs(); args.type = type; args.quantity = -quantity; pushEvent(args); }
bool IsVinagre(Item item) { return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("vinagre")); }
/// <summary> /// Remove association between two items /// </summary> /// <param name="item">source item</param> /// <param name="name">attribute name (verb in terms of associative database model)</param> /// <param name="target">target item</param> /// <returns>true if association between this two items exists, false otherwise</returns> public bool Unlink(Item item, String name, Item target) { checkIfActive(); checkIfNotInverseLink(name); int id; if (!db.name2id.TryGetValue(name, out id)) { return false; } if (item.relations != null) { int offs = item.stringFields.Length + item.numericFields.Length; int l = offs, n = item.fieldIds.Length, r = n; while (l < r) { int m = (l + r) >> 1; if (item.fieldIds[m] < id) { l = m + 1; } else { r = m; } } while (r < n && item.fieldIds[r] == id) { if (target.Equals(item.relations.GetRaw(r - offs))) { item.relations.Remove(r - offs); item.fieldIds = Arrays.Remove(item.fieldIds, r); modify(item); removeLink(item, target, id); return true; } r += 1; } } else { if (db.root.relations.Unlink(new Key(((long)item.Oid << 32) | (uint)id), target)) { removeLink(item, target, id); item.fieldNames = null; return true; } } return false; }
void removeLink(Item source, Item target, int id) { Index index = (Index)db.storage.GetObjectByOID(id); index.Remove(new Key(target), source); if (target.relations != null) { int[] fieldIds = target.fieldIds; int nFields = fieldIds.Length; int nDeleted = 0; for (int i = target.stringFields.Length + target.numericFields.Length, j = 0; i < nFields; i++) { if (!source.Equals(target.relations.GetRaw(j))) { target.fieldIds[i - nDeleted] = fieldIds[i]; j += 1; } else { index = (Index)db.storage.GetObjectByOID(fieldIds[i]); index.Remove(new Key(source), target); target.relations.Remove(j); nDeleted += 1; } } if (nDeleted > 0) { fieldIds = new int[nFields -= nDeleted]; Array.Copy(target.fieldIds, 0, fieldIds, 0, nFields); target.fieldIds = fieldIds; modify(target); } } else { String name = db.id2name[id]; int inverseId = db.name2id[name.StartsWith("-") ? name.Substring(1) : ("-" + name)]; index = (Index)db.storage.GetObjectByOID(inverseId); index.Remove(new Key(source), target); target.fieldNames = null; db.root.relations.Remove(new Key(((long)target.Oid << 32) | (uint)inverseId), source); } }
public static bool IsTelepathy(Item item) { return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("empathy")); }
public static bool IsPidgin(Item item) { return item.Equals (Do.Platform.Services.UniverseFactory.MaybeApplicationItemFromCommand ("pidgin")); }