using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Mesnac.Compressor.Entity { public class DictionaryOperation { public Dictionary _dic=new Dictionary(); public Dictionary Dic { get { return _dic; } } public T find(int i) { lock (this) { if (_dic.ContainsKey(i)) { return _dic[i]; } else { return default(T); } } } public void Delete(int i) { lock (this) { if (_dic.ContainsKey(i)) { _dic.Remove(i); } } } /// /// 已经包好返回原来key,否则返回新key /// /// /// /// public int Add(int i,T t) { lock (this) { if (_dic.ContainsValue(t)) { foreach (KeyValuePair item in _dic) { if (item.Value.Equals(t)) { return item.Key; } } } if (!_dic.ContainsKey(i)) { _dic.Add(i, t); } else { i++; Add(i, t); } return i; } } } //站,先进先出 public class Queue { private readonly List _TrayQueue=new List(); public List TrayQueue { get { return _TrayQueue; } } #region 队列操作 //添加 public bool InsertQueue(T Tray) { foreach (T t in _TrayQueue) { if (t.Equals(Tray)) { return false; } } lock (this) { _TrayQueue.Add(Tray); } return true; } /// /// 出队 /// /// public T OutQueue() { T tyre = default(T); lock (this) { if (_TrayQueue != null && _TrayQueue.Count > 0) { tyre = _TrayQueue[0]; } } return tyre; } /// /// 删除第一个信息 /// /// public void DeleteTyre() { if (_TrayQueue.Count > 0) { T df = _TrayQueue[0]; lock (this) { _TrayQueue.RemoveAt(0); } } } /// /// 队列是否为空 /// /// public bool IsRFIDAvailable() { bool exist; lock (this) { exist = _TrayQueue.Count > 0; } return exist; } /// /// 处理超时则清空某些轮胎 /// /// public void ClearQueue(DateTime time) { lock (this) { for (int i = 0; i < _TrayQueue.Count; i++) { var tyre = _TrayQueue[i]; //if (tyre.InputTime < time) //{ _TrayQueue.RemoveAt(i); //} } } } #endregion } }