text: /*
   * MainHeaderList.cpp
   *
   *  Created on: 2022/03/26
   *      Author: iizuka
   */
  
  #include "main_header_store/store/MainHeaderList.h"
  
  namespace codablecash {
  
  MainHeaderList::MainHeaderList(const MainHeaderList& inst) : list(4) {
  	int maxLoop = inst.list.size();
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t fpos = inst.list.get(i);
  
  		this->list.addElement(fpos);
  	}
  }
  
  MainHeaderList::MainHeaderList() : list(4) {
  
  }
  
  MainHeaderList::~MainHeaderList() {
  
  }
  
  int MainHeaderList::binarySize() const {
  	int total = sizeof(uint32_t);
  	total += sizeof(uint64_t) * this->list.size();
  
  	return total;
  }
  
  void MainHeaderList::toBinary(ByteBuffer* out) const {
  	int maxLoop = this->list.size();
  	out->putInt(maxLoop);
  
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t fpos = this->list.get(i);
  		out->putLong(fpos);
  	}
  }
  
  MainHeaderList* MainHeaderList::fromBinary(ByteBuffer* in) {
  	MainHeaderList* value = new MainHeaderList();
  
  	int maxLoop = in->getInt();
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t fpos = in->getLong();
  		value->list.addElement(fpos);
  	}
  
  	return value;
  }
  
  IBlockObject* MainHeaderList::copyData() const noexcept {
  	return new MainHeaderList(*this);
  }
  
  void MainHeaderList::join(const MainHeaderList* value) noexcept {
  	const RawArrayPrimitive<uint64_t>* newList = &value->list;
  
  	int maxLoop = newList->size();
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t v = newList->get(i);
  		if(contains(v)){
  			continue;
  		}
  		this->list.addElement(v);
  	}
  }
  
  bool MainHeaderList::contains(uint64_t value) const noexcept {
  	int maxLoop = this->list.size();
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t v = this->list.get(i);
  		if(v == value){
  			return true;
  		}
  	}
  
  	return false;
  }
  
  void MainHeaderList::remove(uint64_t value) noexcept {
  	int index = indexof(value);
  
  	if(index >= 0){
  		this->list.remove(index);
  	}
  }
  
  int MainHeaderList::indexof(uint64_t value) const noexcept {
  	int maxLoop = this->list.size();
  	for(int i = 0; i != maxLoop; ++i){
  		uint64_t v = this->list.get(i);
  		if(v == value){
  			return i;
  		}
  	}
  
  	return -1;
  }
  
  bool MainHeaderList::isEmpty() const noexcept {
  	return this->list.size() == 0;
  }
  
  void MainHeaderList::add(uint64_t value) noexcept {
  	this->list.addElement(value);
  }
  
  int MainHeaderList::size() const noexcept {
  	return this->list.size();
  }
  
  uint64_t MainHeaderList::get(int pos) const noexcept {
  	return this->list.get(pos);
  }
  
  } /* namespace codablecash */
  