task 5
This commit is contained in:
parent
aac002fb3a
commit
fb452c0f70
@ -24,14 +24,14 @@ public abstract class AbstractCompany
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
public static bool operator +(AbstractCompany company, DrawningBoat boat)
|
||||
public static int operator +(AbstractCompany company, DrawningBoat boat)
|
||||
{
|
||||
return company._collection?.Insert(boat) ?? false;
|
||||
return company._collection?.Insert(boat) ?? -1;
|
||||
}
|
||||
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
public static DrawningBoat? operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
public DrawningBoat? GetRandomObject()
|
||||
|
@ -10,9 +10,9 @@ public interface ICollectionGenericObjects<T> where T : class
|
||||
{
|
||||
int Count { get; }
|
||||
int SetMaxCount { set; }
|
||||
bool Insert(T obj);
|
||||
bool Insert(T obj, int position);
|
||||
bool Remove(int position);
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
T? Remove(int position);
|
||||
|
||||
T? Get(int position);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : c
|
||||
|
||||
return null;
|
||||
}
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
//todo
|
||||
for (int i = 0; i < Count; i++)
|
||||
@ -44,19 +44,19 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : c
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
//todo
|
||||
if (!(position > 0 && position < _collection.Length))
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_collection[position] == null)
|
||||
@ -68,7 +68,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : c
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,22 +77,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : c
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < _collection.Length) || _collection[position] == null )
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
T? deletedElement = _collection[position];
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
return deletedElement;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public partial class FormBoatCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningBoat)
|
||||
if (_company + drawningBoat != -1)
|
||||
{
|
||||
MessageBox.Show(("Объект добавлен"));
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -100,7 +100,7 @@ public partial class FormBoatCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos)
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user