Add additions
This commit is contained in:
parent
879902a606
commit
28468bcf41
80
AccordionBus/BusCollectionForm.form
Normal file
80
AccordionBus/BusCollectionForm.form
Normal file
@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AccordionBus.BusCollectionForm">
|
||||
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="8de60" binding="toolsPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="4" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="5fb24" class="javax.swing.JTextField" binding="textField">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="4c213" class="javax.swing.JButton" binding="buttonRemoveBus">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Удалить автобус"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2fbac" class="javax.swing.JButton" binding="buttonAddBus">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Добавить автобус"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ef2b7" class="javax.swing.JButton" binding="buttonRefreshCollection">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=" Обновить коллекцию"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ddf17" class="javax.swing.JLabel" binding="toolsLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Инструменты"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="37e63" class="javax.swing.JButton" binding="buttonGenerateBus">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Сгенерировать автобус"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="8237" binding="pictureBoxCollection" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
92
AccordionBus/BusCollectionForm.java
Normal file
92
AccordionBus/BusCollectionForm.java
Normal file
@ -0,0 +1,92 @@
|
||||
package AccordionBus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
// Форма для работы с набором объектов класса DrawingBus
|
||||
public class BusCollectionForm extends JFrame {
|
||||
// Набор объектов
|
||||
private final BusGenericCollection<DrawingBus, DrawingObjectBus> _buses;
|
||||
// Выбранный автобус
|
||||
public DrawingBus SelectedBus;
|
||||
private FrameBusGeneric frameBusGeneric;
|
||||
|
||||
private JPanel mainPanel;
|
||||
public JPanel getMainPanel() {
|
||||
return mainPanel;
|
||||
}
|
||||
private JPanel pictureBoxCollection;
|
||||
private JButton buttonAddBus;
|
||||
private JTextField textField;
|
||||
private JButton buttonRemoveBus;
|
||||
private JButton buttonRefreshCollection;
|
||||
private JPanel toolsPanel;
|
||||
private JLabel toolsLabel;
|
||||
private JButton buttonGenerateBus;
|
||||
|
||||
// Конструктор
|
||||
public BusCollectionForm() {
|
||||
pictureBoxCollection.setSize(new Dimension(700, 450));
|
||||
_buses = new BusGenericCollection<>(pictureBoxCollection.getWidth(), pictureBoxCollection.getHeight());
|
||||
|
||||
buttonAddBus.addActionListener(e -> {
|
||||
FrameAccordionBus frameAccordionBus = new FrameAccordionBus();
|
||||
frameAccordionBus.setVisible(true);
|
||||
frameAccordionBus.accordionBusForm.buttonSelectBus.addActionListener(ev -> {
|
||||
SelectedBus = frameAccordionBus.accordionBusForm.drawingBus;
|
||||
frameAccordionBus.dispose();
|
||||
if (SelectedBus != null) {
|
||||
if (_buses.plus(SelectedBus) > -2) {
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getMainPanel(), "Объект добавлен", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(this.getMainPanel(), " Объект не добавлен", "Ошибка", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
buttonRemoveBus.addActionListener(e -> {
|
||||
Object[] options = {"Да", "Нет"};
|
||||
int n = JOptionPane.showOptionDialog(this.getMainPanel(), "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
|
||||
if (n == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int pos = Integer.parseInt(textField.getText());
|
||||
if (_buses.minus(pos) != null) {
|
||||
Refresh();
|
||||
JOptionPane.showMessageDialog(this.getMainPanel(), "Объект удален", "Успех", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(this.getMainPanel(), "Не удалось удалить объект", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(this.getMainPanel(), "Неверное значение", "Ошибка", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
buttonRefreshCollection.addActionListener(e -> {
|
||||
Refresh();
|
||||
});
|
||||
|
||||
buttonGenerateBus.addActionListener(e -> {
|
||||
if (frameBusGeneric != null) {
|
||||
frameBusGeneric.dispose();
|
||||
}
|
||||
|
||||
frameBusGeneric = new FrameBusGeneric();
|
||||
frameBusGeneric.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
// Обновить картинку
|
||||
public void Refresh() {
|
||||
Graphics g = mainPanel.getGraphics();
|
||||
mainPanel.paint(g);
|
||||
_buses.ShowBuses(g);
|
||||
}
|
||||
}
|
96
AccordionBus/BusGenericCollection.java
Normal file
96
AccordionBus/BusGenericCollection.java
Normal file
@ -0,0 +1,96 @@
|
||||
package AccordionBus;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
// Параметризованный класс для набора объектов DrawingBus
|
||||
public class BusGenericCollection<T extends DrawingBus, U extends IMoveableObject> {
|
||||
// Ширина окна прорисовки
|
||||
private final int _pictureWidth;
|
||||
|
||||
// Высота окна прорисовки
|
||||
private final int _pictureHeight;
|
||||
|
||||
// Размер занимаемого объектом места (ширина)
|
||||
private final int _placeSizeWidth = 215;
|
||||
|
||||
// Размер занимаемого объектом места (высота)
|
||||
private final int _placeSizeHeight = 50;
|
||||
|
||||
// Набор объектов
|
||||
private final SetGeneric<T> _collection;
|
||||
|
||||
// Конструктор
|
||||
public BusGenericCollection(int picWidth, int picHeight) {
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
// Перегрузка оператора сложения
|
||||
public int plus(T obj) {
|
||||
if (obj == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return _collection.Insert(obj);
|
||||
}
|
||||
|
||||
// Перегрузка оператора вычитания
|
||||
public T minus(int pos) {
|
||||
T obj = _collection.Get(pos);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
_collection.Remove(pos);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
// Получение объекта IMoveableObject
|
||||
public U GetU(int pos)
|
||||
{
|
||||
return (U)_collection.Get(pos).GetMoveableObject();
|
||||
}
|
||||
|
||||
// Вывод всего набора объектов
|
||||
public void ShowBuses(Graphics g) {
|
||||
DrawBackground(g);
|
||||
DrawObjects(g);
|
||||
}
|
||||
|
||||
// Метод отрисовки фона
|
||||
private void DrawBackground(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setStroke(new BasicStroke(3));
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) {
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++) {
|
||||
// Линия разметки места
|
||||
g2d.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g2d.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g) {
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++) {
|
||||
// Получение объекта
|
||||
var obj = _collection.Get(i);
|
||||
if (obj != null) {
|
||||
// Установка позиции
|
||||
obj.SetPosition(
|
||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
||||
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
|
||||
);
|
||||
// Прорисовка объекта
|
||||
obj.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
AccordionBus/BusGenericForm.form
Normal file
31
AccordionBus/BusGenericForm.form
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="AccordionBus.BusGenericForm">
|
||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="b0cd2" class="javax.swing.JButton" binding="buttonGenerateBus">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="10" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Сгенерировать автоубс"/>
|
||||
</properties>
|
||||
</component>
|
||||
<hspacer id="19ae4">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<vspacer id="68bda">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
86
AccordionBus/BusGenericForm.java
Normal file
86
AccordionBus/BusGenericForm.java
Normal file
@ -0,0 +1,86 @@
|
||||
package AccordionBus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class BusGenericForm {
|
||||
private DrawingBus drawingBus;
|
||||
private SetBusGeneric<EntityBus, IDrawingDoors> _busGeneric;
|
||||
|
||||
private JPanel pictureBox;
|
||||
public JPanel getPictureBox() {
|
||||
return pictureBox;
|
||||
}
|
||||
private JButton buttonGenerateBus;
|
||||
|
||||
// Конструктор
|
||||
public BusGenericForm() {
|
||||
_busGeneric = new SetBusGeneric<>(15, 15);
|
||||
|
||||
buttonGenerateBus.addActionListener(e -> {
|
||||
addEntityBus();
|
||||
addDrawingDoors();
|
||||
|
||||
drawingBus = _busGeneric.NewBus(pictureBox.getWidth(), pictureBox.getHeight());
|
||||
drawingBus.SetPosition((pictureBox.getWidth() - drawingBus.GetWidth()) / 2, (pictureBox.getHeight() - drawingBus.GetHeigth()) / 2);
|
||||
Draw();
|
||||
});
|
||||
}
|
||||
|
||||
// Добавить объект-сущность в набор
|
||||
private void addEntityBus() {
|
||||
Random random = new Random();
|
||||
EntityBus entityBus;
|
||||
|
||||
if (random.nextBoolean()) {
|
||||
entityBus = new EntityBus(random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
}
|
||||
else {
|
||||
entityBus = new EntityAccordionBus(random.nextInt(100, 300),
|
||||
random.nextInt(1000, 3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(),
|
||||
random.nextBoolean());
|
||||
}
|
||||
|
||||
_busGeneric.Insert(entityBus);
|
||||
}
|
||||
|
||||
// Добавить тип отрисовки дверей в набор
|
||||
public void addDrawingDoors() {
|
||||
Random random = new Random();
|
||||
IDrawingDoors drawingDoors;
|
||||
|
||||
switch (random.nextInt(0, 3)) {
|
||||
case 0:
|
||||
drawingDoors = new DrawingDoorsTypeOne();
|
||||
break;
|
||||
case 1:
|
||||
drawingDoors = new DrawingDoorsTypeTwo();
|
||||
break;
|
||||
case 2:
|
||||
drawingDoors = new DrawingDoorsTypeThree();
|
||||
break;
|
||||
default:
|
||||
drawingDoors = new DrawingDoorsTypeOne();
|
||||
break;
|
||||
}
|
||||
drawingDoors.setNumDoors(random.nextInt(3, 6));
|
||||
|
||||
_busGeneric.Insert(drawingDoors);
|
||||
}
|
||||
|
||||
public void Draw() {
|
||||
if (drawingBus == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Graphics g = pictureBox.getGraphics();
|
||||
pictureBox.paint(g);
|
||||
drawingBus.DrawTransport(g);
|
||||
}
|
||||
}
|
21
AccordionBus/FrameBusCollection.java
Normal file
21
AccordionBus/FrameBusCollection.java
Normal file
@ -0,0 +1,21 @@
|
||||
package AccordionBus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FrameBusCollection extends JFrame {
|
||||
public BusCollectionForm busCollectionForm;
|
||||
|
||||
public FrameBusCollection() {
|
||||
super();
|
||||
setTitle("Набор автобусов");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
busCollectionForm = new BusCollectionForm();
|
||||
setContentPane(busCollectionForm.getMainPanel());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setPreferredSize(new Dimension(900, 500));
|
||||
setLocation(500, 500);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
21
AccordionBus/FrameBusGeneric.java
Normal file
21
AccordionBus/FrameBusGeneric.java
Normal file
@ -0,0 +1,21 @@
|
||||
package AccordionBus;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class FrameBusGeneric extends JFrame {
|
||||
public BusGenericForm busGenericForm;
|
||||
|
||||
public FrameBusGeneric() {
|
||||
super();
|
||||
setTitle("Генерация автобуса");
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
busGenericForm = new BusGenericForm();
|
||||
setContentPane(busGenericForm.getPictureBox());
|
||||
setDefaultLookAndFeelDecorated(false);
|
||||
setPreferredSize(new Dimension(900, 500));
|
||||
setLocation(500, 500);
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
54
AccordionBus/SetBusGeneric.java
Normal file
54
AccordionBus/SetBusGeneric.java
Normal file
@ -0,0 +1,54 @@
|
||||
package AccordionBus;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
// Дополнительный параметризованный набор объектов
|
||||
public class SetBusGeneric<T extends EntityBus, U extends IDrawingDoors> {
|
||||
// Набор объектов от первого параметра
|
||||
private final T[] _buses;
|
||||
public int BusesCount;
|
||||
|
||||
// Набор объектов от второго параметра
|
||||
private final U[] _doors;
|
||||
public int DoorsCount;
|
||||
|
||||
// Конструктор
|
||||
public SetBusGeneric(int busesCount, int doorsCount) {
|
||||
_buses = (T[]) new EntityBus[busesCount];
|
||||
_doors = (U[]) new IDrawingDoors[doorsCount];
|
||||
}
|
||||
|
||||
// Добавление объекта в первый набор
|
||||
public int Insert(T bus) {
|
||||
// Проверка на вместимость
|
||||
if (BusesCount >= _buses.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
_buses[BusesCount++] = bus;
|
||||
return BusesCount;
|
||||
}
|
||||
|
||||
// Добавление объекта во второй набор
|
||||
public int Insert(U door) {
|
||||
// Проверка на вместимость
|
||||
if (DoorsCount >= _doors.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
_doors[DoorsCount++] = door;
|
||||
return DoorsCount;
|
||||
}
|
||||
|
||||
// Создание объекта класса прорисовки
|
||||
public DrawingBus NewBus(int pictureWidth, int pictureHeight) {
|
||||
Random random = new Random();
|
||||
T bus = _buses[random.nextInt(BusesCount)];
|
||||
U door = _doors[random.nextInt(DoorsCount)];
|
||||
|
||||
if (bus instanceof EntityAccordionBus) {
|
||||
return new DrawingAccordionBus(bus, door, pictureWidth, pictureHeight);
|
||||
}
|
||||
return new DrawingBus(bus, door, pictureWidth, pictureHeight);
|
||||
}
|
||||
}
|
79
AccordionBus/SetGeneric.java
Normal file
79
AccordionBus/SetGeneric.java
Normal file
@ -0,0 +1,79 @@
|
||||
package AccordionBus;
|
||||
|
||||
// Параметризованный набор рбъектов
|
||||
public class SetGeneric<T extends Object> {
|
||||
// Массив объектов, которые храним
|
||||
private final Object[] _places;
|
||||
|
||||
// Количество объектов в массиве
|
||||
public int Count;
|
||||
|
||||
// Конструктор
|
||||
public SetGeneric(int count) {
|
||||
_places = new Object[count];
|
||||
Count = count;
|
||||
}
|
||||
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T bus) {
|
||||
return Insert(bus, 0);
|
||||
}
|
||||
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T bus, int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Проверка, что элемент массива по этой позиции пустой
|
||||
if (_places[position] != null) {
|
||||
// Проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int index = -1;
|
||||
for (int i = position + 1; i < Count; i++) {
|
||||
if (_places[i] == null) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Проверка, если пустого элемента нет
|
||||
if (index == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
int j = index - 1;
|
||||
while (j >= position) {
|
||||
_places[j + 1] = _places[j];
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
||||
// Вставка по позиции
|
||||
_places[position] = bus;
|
||||
return position;
|
||||
}
|
||||
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public boolean Remove(int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Получение объекта из набора по позиции
|
||||
public T Get(int position) {
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= Count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (T)_places[position];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user