<commit_before><?php

namespace Versionable\Http\Header;

class Collection implements CollectionInterface, \Iterator, \SeekableIterator, \Countable, \ArrayAccess
{
  /**
   *
   * @var array Array of \Versionable\Http\Header\HeaderInterface
   */
  protected $headers = array();

  /**
   *
   * @var integer Position of pointer 
   */
  protected $position = 0;

  public function add(HeaderInterface $header)
  {
    $this->headers[$header->getName()] = $header;
  }

  public function remove($name)
  {
    if ($this->has($name))
    {
      unset($this->headers[$name]);

      return true;
    }

    return false;
  }

  public function get($name)
  {
    if ($this->has($name))
    {
      return $this->headers[$name];
    }

    return false;
  }

  public function has($name)
  {
    return isset($this->headers[$name]);
  }

  public function toArray()
  {
    $headers = array();
    
    foreach($this->header as $header)
    {
      $headers[] = $header->toString();
    }
    
    return $headers;
  }


  /**
   *
   * @return boolean
   */
  public function rewind()
  {
    $this->setPosition(0);

    return reset($this->headers);
  }

  /**
   *
   * @return mixed
   */
  public function next()
  {
    $pos = $this->getPostion();
    $this->setPosition(--$pos);

    return next($this->headers);
  }

  /**
   *
   * @return boolean
   */
  public function current()
  {
    return current($this->headers);
  }

  /**
   *
   * @return mixed
   */
  public function key()
  {
    return key($this->headers);
  }

  /**
   *
   * @return boolean
   */
  public function valid()
  {
    return $this->current() !== false;
  }

  /**
   *
   * @return integer
   */
  public function count()
  {
    return count($this->headers);
  }

  public function seek($position)
  {
    if(isset($this->headers[$position]))
    {
      return $this->headers[$position];
    }

    return false;
  }

  public function offsetSet($offset, $value)
  {
    $this->headers[$offset] = $value;
  }

  public function offsetExists($offset)
  {
    return isset($this->headers[$offset]);
  }

  public function offsetUnset($offset)
  {
    unset($this->headers[$offset]);
  }

  public function offsetGet($offset)
  {
    return $this->seek($offset);
  }

  /**
   *
   * @param integer $position
   */
  protected function setPosition($position)
  {
    $this->position = (int)$position;
  }

  /**
   *
   * @return integer
   */
  protected function getPostion()
  {
    return $this->position;
  }
  
  public function parse($name, $value)
  {
    $class_name = '\\Versionable\\Http\\Header\\' . \str_replace('-', '', $name);
    if (\class_exists($class_name))
    {
      $header = new $class_name($value);
    }
    else
    {
      $header = new Header($name, $value);
    }
    
    $this->add($header);
  }
}<commit_msg>Build correct header<commit_after><?php

namespace Versionable\Http\Header;

class Collection implements CollectionInterface, \Iterator, \SeekableIterator, \Countable, \ArrayAccess
{
  /**
   *
   * @var array Array of \Versionable\Http\Header\HeaderInterface
   */
  protected $headers = array();

  /**
   *
   * @var integer Position of pointer 
   */
  protected $position = 0;

  public function add(HeaderInterface $header)
  {
    $this->headers[$header->getName()] = $header;
  }

  public function remove($name)
  {
    if ($this->has($name))
    {
      unset($this->headers[$name]);

      return true;
    }

    return false;
  }

  public function get($name)
  {
    if ($this->has($name))
    {
      return $this->headers[$name];
    }

    return false;
  }

  public function has($name)
  {
    return isset($this->headers[$name]);
  }

  public function toArray()
  {
    $headers = array();
    
    foreach($this->header as $header)
    {
      $headers[] = $header->toString();
    }
    
    return $headers;
  }


  /**
   *
   * @return boolean
   */
  public function rewind()
  {
    $this->setPosition(0);

    return reset($this->headers);
  }

  /**
   *
   * @return mixed
   */
  public function next()
  {
    $pos = $this->getPostion();
    $this->setPosition(--$pos);

    return next($this->headers);
  }

  /**
   *
   * @return boolean
   */
  public function current()
  {
    return current($this->headers);
  }

  /**
   *
   * @return mixed
   */
  public function key()
  {
    return key($this->headers);
  }

  /**
   *
   * @return boolean
   */
  public function valid()
  {
    return $this->current() !== false;
  }

  /**
   *
   * @return integer
   */
  public function count()
  {
    return count($this->headers);
  }

  public function seek($position)
  {
    if(isset($this->headers[$position]))
    {
      return $this->headers[$position];
    }

    return false;
  }

  public function offsetSet($offset, $value)
  {
    $this->headers[$offset] = $value;
  }

  public function offsetExists($offset)
  {
    return isset($this->headers[$offset]);
  }

  public function offsetUnset($offset)
  {
    unset($this->headers[$offset]);
  }

  public function offsetGet($offset)
  {
    return $this->seek($offset);
  }

  /**
   *
   * @param integer $position
   */
  protected function setPosition($position)
  {
    $this->position = (int)$position;
  }

  /**
   *
   * @return integer
   */
  protected function getPostion()
  {
    return $this->position;
  }
  
  public function parse($name, $value)
  {
    $class_name = '\Versionable\Http\CustomHeader\\' . \str_replace('-', '', $name);
    if (\class_exists($class_name))
    {
      $header = new $class_name($value);
    }
    else
    {
      $header = new Header($name, $value);
    }
    
    $this->add($header);
  }
}
{'fraction_non_alphanumeric': 0.16631393298059965, 'fraction_numerical': 0.0007054673721340388, 'mean_word_length': 2.3796185935637664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096743', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1851, 'n_words': 358}