text:
    #pragma hdrstop
#endif

#include "wx/gbsizer.h"

//---------------------------------------------------------------------------

IMPLEMENT_DYNAMIC_CLASS(wxGBSizerItem, wxSizerItem)
IMPLEMENT_CLASS(wxGridBagSizer, wxFlexGridSizer)

const wxGBSpan wxDefaultSpan;

//---------------------------------------------------------------------------
// wxGBSizerItem
//---------------------------------------------------------------------------

wxGBSizerItem::wxGBSizerItem( int width,
                              int height,
                              const wxGBPosition& pos,
                              const wxGBSpan& span,
                              int flag,
                              int border,
                              wxObject* userData)
    : wxSizerItem(width, height, 0, flag, border, userData),
      m_pos(pos),
      m_span(span),
      m_gbsizer(NULL)
{
}

wxGBSizerItem::wxGBSizerItem( wxWindow *window,
                              const wxGBPosition& pos,
                              const wxGBSpan& span,
                              int flag,
                              int border,
                              wxObject* userData )
    : wxSizerItem(window, 0, flag, border, userData),
      m_pos(pos),
      m_span(span),
      m_gbsizer(NULL)
{
}

wxGBSizerItem::wxGBSizerItem( wxSizer *sizer,
                              const wxGBPosition& pos,
                              const wxGBSpan& span,
                              int flag,
                              int border,
                              wxObject* userData )
    : wxSizerItem(sizer, 0, flag, border, userData),
      m_pos(pos),
      m_span(span),
      m_gbsizer(NULL)
{
}

wxGBSizerItem::wxGBSizerItem()
    : wxSizerItem(),
      m_pos(-1,-1),
      m_span(-1,-1),
      m_gbsizer(NULL)
{
}

//---------------------------------------------------------------------------

void wxGBSizerItem::GetPos(int& row, int& col) const
{
    row = m_pos.GetRow();
    col = m_pos.GetCol();
}

void wxGBSizerItem::GetSpan(int& rowspan, int& colspan) const
{
    rowspan = m_span.GetRowspan();
    colspan = m_span.GetColspan();
}

bool wxGBSizerItem::SetPos( const wxGBPosition& pos )
{
    if (m_gbsizer)
    {
        wxCHECK_MSG( !m_gbsizer->CheckForIntersection(pos, m_span, this), false,
                 wxT("An item is already at that position") );
    }
    m_pos = pos;
    return true;
}

bool wxGBSizerItem::SetSpan( const wxGBSpan& span )
{
    if (m_gbsizer)
    {
        wxCHECK_MSG( !m_gbsizer->CheckForIntersection(m_pos, span, this), false,
                 wxT("An item is already at that position") );
    }
    m_span = span;
    return true;
}

inline bool InRange(int val, int min, int max)
{
    return (val >= min && val <= max);
}

bool wxGBSizerItem::Intersects(const wxGBSizerItem& other)
{
    return Intersects(other.GetPos(), other.GetSpan());
}

bool wxGBSizerItem::Intersects(const wxGBPosition& pos, const wxGBSpan& span)
{

    int row, col, endrow, endcol;
    int otherrow, othercol, otherendrow, otherendcol;

    GetPos(row, col);
    GetEndPos(endrow, endcol);

    otherrow = pos.GetRow();
    othercol = pos.GetCol();
    otherendrow = otherrow + span.GetRowspan() - 1;
    otherendcol = othercol + span.GetColspan() - 1;

    // is the other item's start or end in the range of this one?
    if (( InRange(otherrow, row, endrow) && InRange(othercol, col, endcol) ) ||
        ( InRange(otherendrow, row, endrow) && InRange(otherendcol, col, endcol) ))
        return true;

    // is this item's start or end in the range of the other one?
    if (( InRange(row, otherrow, otherendrow) && InRange(col, othercol, otherendcol) ) ||
        ( InRange(endrow, otherrow, otherendrow) && InRange(endcol, othercol, otherendcol) ))
        return true;

    return false;
}

void wxGBSizerItem::GetEndPos(int& row, int& col)
{
    row = m_pos.GetRow() + m_span.GetRowspan() - 1;
    col = m_pos.GetCol() + m_span.GetColspan() - 1;
}

//---------------------------------------------------------------------------
// wxGridBagSizer
//---------------------------------------------------------------------------

wxGridBagSizer::wxGridBagSizer(int vgap, int hgap )
    : wxFlexGridSizer(1, vgap, hgap),
      m_emptyCellSize(10,20)

{
}

wxSizerItem* wxGridBagSizer::Add( wxWindow *window,
                                  const wxGBPosition& pos, const wxGBSpan& span,
                                  int flag, int border,  wxObject* userData )
{
    wxGBSizerItem* item = new wxGBSizerItem(window, pos, span, flag, border, userData);
    if ( Add(item) )
        return item;
    else
    {
        delete item;
        return (wxSizerItem*)NULL;
    }
}

wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer,
                          const wxGBPosition& pos, const wxGBSpan& span,
                          int flag, int border,  wxObject* userData )
{
    wxGBSizerItem* item = new wxGBSizerItem(sizer, pos, span, flag, border, userData);
    if ( Add(item) )
        return item;
    else
    {
        delete item;
        return (wxSizerItem*)NULL;
    }
}

wxSizerItem* wxGridBagSizer::Add( int width, int height,
                          const wxGBPosition& pos, const wxGBSpan& span,
                          int flag, int border,  wxObject* userData )
{
    wxGBSizerItem* item = new wxGBSizerItem(width, height, pos, span, flag, border, userData);
    if ( Add(item) )
        return item;
    else
    {
        delete item;
        return (wxSizerItem*)NULL;
    }
}

wxSizerItem* wxGridBagSizer::Add( wxGBSizerItem *item )
{
    wxCHECK_MSG( !CheckForIntersection(item), NULL,
                 wxT("An item is already at that position") );
    m_children.Append(item);
    item->SetGBSizer(this);
    if ( item->GetWindow() )
        item->GetWindow()->SetContainingSizer( this );

    return item;
}

//---------------------------------------------------------------------------

wxSize wxGridBagSizer::GetCellSize(int row, int col) const
{
    wxCHECK_MSG( (row < m_rows) && (col < m_cols),
                 wxDefaultSize,
                 wxT("Invalid cell."));
    return wxSize( m_colWidths[col], m_rowHeights[row] );
}

wxGBPosition wxGridBagSizer::GetItemPosition(wxWindow *window)
{
    wxGBPosition badpos(-1,-1);
    wxGBSizerItem* item = FindItem(window);
    wxCHECK_MSG(item, badpos, wxT("Failed to find item."));
    return item->GetPos();
}

wxGBPosition wxGridBagSizer::GetItemPosition(wxSizer *sizer)
{
    wxGBPosition badpos(-1,-1);
    wxGBSizerItem* item = FindItem(sizer);
    wxCHECK_MSG(item, badpos, wxT("Failed to find item."));
    return item->GetPos();
}

wxGBPosition wxGridBagSizer::GetItemPosition(size_t index)
{
    wxGBPosition badpos(-1,-1);
    wxSizerItemList::compatibility_iterator node = m_children.Item( index );
    wxCHECK_MSG( node, badpos, _T("Failed to find item.") );
    wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
    return item->GetPos();
}

bool wxGridBagSizer::SetItemPosition(wxWindow *window, const wxGBPosition& pos)
{
    wxGBSizerItem* item = FindItem(window);
    wxCHECK_MSG(item, false, wxT("Failed to find item."));
    return item->SetPos(pos);
}

bool wxGridBagSizer::SetItemPosition(wxSizer *sizer, const wxGBPosition& pos)
{
    wxGBSizerItem* item = FindItem(sizer);
    wxCHECK_MSG(item, false, wxT("Failed to find item."));
    return item->SetPos(pos);
}

bool wxGridBagSizer::SetItemPosition(size_t index, const wxGBPosition& pos)
{
    wxSizerItemList::compatibility_iterator node = m_children.Item( index );
    wxCHECK_MSG( node, false, _T("Failed to find item.") );
    wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
    return item->SetPos(pos);
}

wxGBSpan wxGridBagSizer::GetItemSpan(wxWindow *window)
{
    wxGBSpan badspan(-1,-1);
    wxGBSizerItem* item = FindItem(window);
    wxCHECK_MSG( item, badspan, _T("Failed to find item.") );
    return item->GetSpan();
}

wxGBSpan wxGridBagSizer::GetItemSpan(wxSizer *sizer)
{
    wxGBSpan badspan(-1,-1);
    wxGBSizerItem* item = FindItem(sizer);
    wxCHECK_MSG( item, badspan, _T("Failed to find item.") );
    return item->GetSpan();
}

wxGBSpan wxGridBagSizer::GetItemSpan(size_t index)
{
    wxGBSpan badspan(-1,-1);
    wxSizerItemList::compatibility_iterator node = m_children.Item( index );
    wxCHECK_MSG( node, badspan, _T("Failed to find item.") );
    wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
    return item->GetSpan();
}

bool wxGridBagSizer::SetItemSpan(wxWindow *window, const wxGBSpan& span)
{
    wxGBSizerItem* item = FindItem(window);
    wxCHECK_MSG(item, false, wxT("Failed to find item."));
    return item->SetSpan(span);
}

bool wxGridBagSizer::SetItemSpan(wxSizer *sizer, const wxGBSpan& span)
{
    wxGBSizerItem* item = FindItem(sizer);
    wxCHECK_MSG(item, false, wxT("Failed to find item."));
    return item->SetSpan(span);
}

bool wxGridBagSizer::SetItemSpan(size_t index, const wxGBSpan& span)
{
    wxSizerItemList::compatibility_iterator node = m_children.Item( index );
    wxCHECK_MSG( node, false, _T("Failed to find item.") );
    wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
    return item->SetSpan(span);
}

wxGBSizerItem* wxGridBagSizer::FindItem(wxWindow* window)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        if ( item->GetWindow() == window )
            return item;
        node = node->GetNext();
    }
    return NULL;
}

wxGBSizerItem* wxGridBagSizer::FindItem(wxSizer* sizer)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        if ( item->GetSizer() == sizer )
            return item;
        node = node->GetNext();
    }
    return NULL;
}

wxGBSizerItem* wxGridBagSizer::FindItemAtPosition(const wxGBPosition& pos)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        if ( item->Intersects(pos, wxDefaultSpan) )
            return item;
        node = node->GetNext();
    }
    return NULL;
}

wxGBSizerItem* wxGridBagSizer::FindItemAtPoint(const wxPoint& pt)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        wxRect rect(item->GetPosition(), item->GetSize());
        rect.Inflate(m_hgap, m_vgap);
        if ( rect.Contains(pt) )
            return item;
        node = node->GetNext();
    }
    return NULL;
}

wxGBSizerItem* wxGridBagSizer::FindItemWithData(const wxObject* userData)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        if ( item->GetUserData() == userData )
            return item;
        node = node->GetNext();
    }
    return NULL;
}

//---------------------------------------------------------------------------

// Figure out what all the min row heights and col widths are, and calculate
// min size from that.
wxSize wxGridBagSizer::CalcMin()
{
    int idx;

    if (m_children.GetCount() == 0)
        return m_emptyCellSize;

    m_rowHeights.Empty();
    m_colWidths.Empty();

    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        if ( item->ShouldAccountFor() )
        {
            int row, col, endrow, endcol;

            item->GetPos(row, col);
            item->GetEndPos(endrow, endcol);

            // fill heights and widths upto this item if needed
            while ( m_rowHeights.GetCount() <= (size_t)endrow )
                m_rowHeights.Add(m_emptyCellSize.GetHeight());
            while ( m_colWidths.GetCount() <= (size_t)endcol )
                m_colWidths.Add(m_emptyCellSize.GetWidth());

            // See if this item increases the size of its row(s) or col(s)
            wxSize size(item->CalcMin());
            for (idx=row; idx <= endrow; idx++)
                m_rowHeights[idx] = wxMax(m_rowHeights[idx], size.GetHeight() / (endrow-row+1));
            for (idx=col; idx <= endcol; idx++)
                m_colWidths[idx] = wxMax(m_colWidths[idx], size.GetWidth() / (endcol-col+1));
        }
        node = node->GetNext();
    }

    AdjustForOverflow();
    AdjustForFlexDirection();

    // Now traverse the heights and widths arrays calcing the totals, including gaps
    int width = 0;
    m_cols = m_colWidths.GetCount();
    for (idx=0; idx < m_cols; idx++)
        width += m_colWidths[idx] + ( idx == m_cols-1 ? 0 : m_hgap );

    int height = 0;
    m_rows = m_rowHeights.GetCount();
    for (idx=0; idx < m_rows; idx++)
        height += m_rowHeights[idx] + ( idx == m_rows-1 ? 0 : m_vgap );

    m_calculatedMinSize = wxSize(width, height);
    return m_calculatedMinSize;
}

void wxGridBagSizer::RecalcSizes()
{
    if (m_children.GetCount() == 0)
        return;

    wxPoint pt( GetPosition() );
    wxSize  sz( GetSize() );

    m_rows = m_rowHeights.GetCount();
    m_cols = m_colWidths.GetCount();
    int idx, width, height;

    AdjustForGrowables(sz, m_calculatedMinSize, m_rows, m_cols);

    // Find the start positions on the window of the rows and columns
    wxArrayInt rowpos;
    rowpos.Add(0, m_rows);
    int y = pt.y;
    for (idx=0; idx < m_rows; idx++)
    {
        height = m_rowHeights[idx] + m_vgap;
        rowpos[idx] = y;
        y += height;
    }

    wxArrayInt colpos;
    colpos.Add(0, m_cols);
    int x = pt.x;
    for (idx=0; idx < m_cols; idx++)
    {
        width = m_colWidths[idx] + m_hgap;
        colpos[idx] = x;
        x += width;
    }

    // Now iterate the children, setting each child's dimensions
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        int row, col, endrow, endcol;
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();

        if ( item->ShouldAccountFor() )
        {
            item->GetPos(row, col);
            item->GetEndPos(endrow, endcol);

            height = 0;
            for(idx=row; idx <= endrow; idx++)
                height += m_rowHeights[idx];
            height += (endrow - row) * m_vgap; // add a vgap for every row spanned

            width = 0;
            for (idx=col; idx <= endcol; idx++)
                width += m_colWidths[idx];
            width += (endcol - col) * m_hgap; // add a hgap for every col spanned

            SetItemBounds(item, colpos[col], rowpos[row], width, height);
        }

        node = node->GetNext();
    }
}

// Sometimes CalcMin can result in some rows or cols having too much space in
// them because as it traverses the items it makes some assumptions when
// items span to other cells.  But those assumptions can become invalid later
// on when other items are fitted into the same rows or columns that the
// spanning item occupies. This method tries to find those situations and
// fixes them.
void wxGridBagSizer::AdjustForOverflow()
{
    int row, col;

    for (row=0; row<(int)m_rowHeights.GetCount(); row++)
    {
        int rowExtra=INT_MAX;
        int rowHeight = m_rowHeights[row];
        for (col=0; col<(int)m_colWidths.GetCount(); col++)
        {
            wxGBPosition pos(row,col);
            wxGBSizerItem* item = FindItemAtPosition(pos);
            if ( !item || !item->ShouldAccountFor() )
                continue;

            int endrow, endcol;
            item->GetEndPos(endrow, endcol);

            // If the item starts in this position and doesn't span rows, then
            // just look at the whole item height
            if ( item->GetPos() == pos && endrow == row )
            {
                int itemHeight = item->CalcMin().GetHeight();
                rowExtra = wxMin(rowExtra, rowHeight - itemHeight);
                continue;
            }

            // Otherwise, only look at spanning items if they end on this row
            if ( endrow == row )
            {
                // first deduct the portions of the item that are on prior rows
                int itemHeight = item->CalcMin().GetHeight();
                for (int r=item->GetPos().GetRow(); r<row; r++)
                    itemHeight -= (m_rowHeights[r] + GetHGap());

                if ( itemHeight < 0 )
                    itemHeight = 0;

                // and check how much is left
                rowExtra = wxMin(rowExtra, rowHeight - itemHeight);
            }
        }
        if ( rowExtra && rowExtra != INT_MAX )
            m_rowHeights[row] -= rowExtra;
    }

    // Now do the same thing for columns
    for (col=0; col<(int)m_colWidths.GetCount(); col++)
    {
        int colExtra=INT_MAX;
        int colWidth = m_colWidths[col];
        for (row=0; row<(int)m_rowHeights.GetCount(); row++)
        {
            wxGBPosition pos(row,col);
            wxGBSizerItem* item = FindItemAtPosition(pos);
            if ( !item || !item->ShouldAccountFor() )
                continue;

            int endrow, endcol;
            item->GetEndPos(endrow, endcol);

            if ( item->GetPos() == pos && endcol == col )
            {
                int itemWidth = item->CalcMin().GetWidth();
                colExtra = wxMin(colExtra, colWidth - itemWidth);
                continue;
            }

            if ( endcol == col )
            {
                int itemWidth = item->CalcMin().GetWidth();
                for (int c=item->GetPos().GetCol(); c<col; c++)
                    itemWidth -= (m_colWidths[c] + GetVGap());

                if ( itemWidth < 0 )
                    itemWidth = 0;

                colExtra = wxMin(colExtra, colWidth - itemWidth);
            }
        }
        if ( colExtra && colExtra != INT_MAX )
            m_colWidths[col] -= colExtra;
    }
}

//---------------------------------------------------------------------------

bool wxGridBagSizer::CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem)
{
    return CheckForIntersection(item->GetPos(), item->GetSpan(), excludeItem);
}

bool wxGridBagSizer::CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem)
{
    wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
        node = node->GetNext();

        if ( excludeItem && item == excludeItem )
            continue;

        if ( item->Intersects(pos, span) )
            return true;

    }
    return false;
}

// Assumes a 10x10 grid, and returns the first empty cell found.  This is
// really stupid but it is only used by the Add methods that match the base
// class virtuals, which should normally not be used anyway...
wxGBPosition wxGridBagSizer::FindEmptyCell()
{
    int row, col;

    for (row=0; row<10; row++)
        for (col=0; col<10; col++)
        {
            wxGBPosition pos(row, col);
            if ( !CheckForIntersection(pos, wxDefaultSpan) )
                return pos;
        }
    return wxGBPosition(-1, -1);
}

//---------------------------------------------------------------------------

// The Add base class virtuals should not be used with this class, but
// we'll try to make them automatically select a location for the item
// anyway.

wxSizerItem* wxGridBagSizer::Add( wxWindow *window, int, int flag, int border, wxObject* userData )
{
    return Add(window, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}

wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer, int, int flag, int border, wxObject* userData )
{
    return Add(sizer, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}

wxSizerItem* wxGridBagSizer::Add( int width, int height, int, int flag, int border, wxObject* userData )
{
    return Add(width, height, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
}

// The Insert nad Prepend base class virtuals that are not appropriate for
// this class and should not be used.  Their implementation in this class
// simply fails.

wxSizerItem* wxGridBagSizer::Add( wxSizerItem * )
{
    wxFAIL_MSG(wxT("Invalid Add form called."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Prepend( wxWindow *, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Prepend( wxSizer *, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Prepend( int, int, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Prepend( wxSizerItem * )
{
    wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Insert( size_t, wxWindow *, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizer *, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Insert( size_t, int, int, int, int, int, wxObject*  )
{
    wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizerItem * )
{
    wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
    return (wxSizerItem*)NULL;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------


text:
<?php

namespace Sule\BankStatements\Collector;

use Carbon\Carbon;

interface WebInterface
{
    /**
     * Return the HTTP Client.
     *
     * @return \GuzzleHttp\ClientInterface
     */
    public function client();

    /**
     * Return the HTTP Cookie Jar.
     *
     * @return \GuzzleHttp\Cookie\CookieJarInterface
     */
    public function getCookieJar();

    /**
     * Return default HTTP request options.
     *
     * @param  bool  $isMobile
     * @return Array
     */
    public function getRequestOptions($isMobile = false);

    /**
     * Set the temporary storage path.
     *
     * @param  string  $path
     * @return void
     */
    public function setTempStoragePath($path);

    /**
     * Set the base URL.
     *
     * @param  string  $uri
     * @return void
     */
    public function setBaseUri($uri);

    /**
     * Set the base URL.
     *
     * @param  string  $userId
     * @param  string  $password
     * @return void
     */
    public function setCredential($userId, $password);

    /**
     * Set additional entity params.
     *
     * @param  array  $params
     * @return void
     */
    public function setAdditionalEntityParams(Array $params);

    /**
     * The landing page.
     *
     * @return int
     * @throws \RuntimeException
     */
    public function landing();

    /**
     * Do login.
     *
     * @return int
     * @throws \RuntimeException
     */
    public function login();

    /**
     * Save state for later use.
     *
     * @param  string  $identifier
     * @return bool
     */
    public function saveState($identifier);

    /**
     * Restore state saved earlier.
     *
     * @param  string  $identifier
     * @param  bool    $removeTempStorage
     * @return bool
     */
    public function restoreState($identifier, $removeTempStorage = true);

    /**
     * Do collect.
     *
     * @param  \Carbon\Carbon  $startDate
     * @param  \Carbon\Carbon  $endDate
     * @return \Illuminate\Support\Collection
     * @throws \RuntimeException
     */
    public function collect(Carbon $startDate, Carbon $endDate);

    /**
     * Do logout.
     *
     * @return int
     * @throws \RuntimeException
     */
    public function logout();
}

redpajama_set_name: RedPajamaGithub


text:
{-# OPTIONS_JHC -fno-prelude -fffi #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Foreign.Marshal.Utils
-- Copyright   :  (c) The FFI task force 2001
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  ffi@haskell.org
-- Stability   :  provisional
-- Portability :  portable
--
-- Utilities for primitive marshaling
--
-----------------------------------------------------------------------------

module Foreign.Marshal.Utils (
  -- * General marshalling utilities

  -- ** Combined allocation and marshalling
  --
  with,          -- :: Storable a => a -> (Ptr a -> IO b) -> IO b
  new,           -- :: Storable a => a -> IO (Ptr a)

  -- ** Marshalling of Boolean values (non-zero corresponds to 'True')
  --
  fromBool,      -- :: Num a => Bool -> a
  toBool,	 -- :: Num a => a -> Bool

  -- ** Marshalling of Maybe values
  --
  maybeNew,      -- :: (      a -> IO (Ptr a))
		 -- -> (Maybe a -> IO (Ptr a))
  maybeWith,     -- :: (      a -> (Ptr b -> IO c) -> IO c)
		 -- -> (Maybe a -> (Ptr b -> IO c) -> IO c)
  maybePeek,     -- :: (Ptr a -> IO        b )
		 -- -> (Ptr a -> IO (Maybe b))

  -- ** Marshalling lists of storable objects
  --
  withMany,      -- :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res

  -- ** Haskellish interface to memcpy and memmove
  -- | (argument order: destination, source)
  --
  copyBytes,     -- :: Ptr a -> Ptr a -> Int -> IO ()
  moveBytes     -- :: Ptr a -> Ptr a -> Int -> IO ()

) where

import Foreign.Ptr	        ( Ptr, nullPtr )
import Foreign.Storable		( Storable(poke) )
import Foreign.C.Types    	( CSize )
import Foreign.Marshal.Alloc 	( malloc, alloca )
import Jhc.Basics
import Jhc.Monad
import Jhc.Num
import Jhc.Order
import Jhc.Inst.Storable()

-- combined allocation and marshalling
-- -----------------------------------

-- |Allocate a block of memory and marshal a value into it
-- (the combination of 'malloc' and 'poke').
-- The size of the area allocated is determined by the 'Foreign.Storable.sizeOf'
-- method from the instance of 'Storable' for the appropriate type.
--
-- The memory may be deallocated using 'Foreign.Marshal.Alloc.free' or
-- 'Foreign.Marshal.Alloc.finalizerFree' when no longer required.
--
new     :: Storable a => a -> IO (Ptr a)
new val  =
  do
    ptr <- malloc
    poke ptr val
    return ptr

-- |@'with' val f@ executes the computation @f@, passing as argument
-- a pointer to a temporarily allocated block of memory into which
-- 'val' has been marshalled (the combination of 'alloca' and 'poke').
--
-- The memory is freed when @f@ terminates (either normally or via an
-- exception), so the pointer passed to @f@ must /not/ be used after this.
--
with       :: Storable a => a -> (Ptr a -> IO b) -> IO b
with val f  =
  alloca $ \ptr -> do
    poke ptr val
    res <- f ptr
    return res

-- marshalling of Boolean values (non-zero corresponds to 'True')
-- -----------------------------

-- |Convert a Haskell 'Bool' to its numeric representation
--
fromBool       :: Num a => Bool -> a
fromBool False  = 0
fromBool True   = 1

-- |Convert a Boolean in numeric representation to a Haskell value
--
toBool :: Num a => a -> Bool
toBool  = (/= 0)

-- marshalling of Maybe values
-- ---------------------------

-- |Allocate storage and marshall a storable value wrapped into a 'Maybe'
--
-- * the 'nullPtr' is used to represent 'Nothing'
--
maybeNew :: (      a -> IO (Ptr a))
	 -> (Maybe a -> IO (Ptr a))
maybeNew  = maybe (return nullPtr)

-- |Converts a @withXXX@ combinator into one marshalling a value wrapped
-- into a 'Maybe', using 'nullPtr' to represent 'Nothing'.
--
maybeWith :: (      a -> (Ptr b -> IO c) -> IO c)
	  -> (Maybe a -> (Ptr b -> IO c) -> IO c)
maybeWith  = maybe ($ nullPtr)

-- |Convert a peek combinator into a one returning 'Nothing' if applied to a
-- 'nullPtr'
--
maybePeek                           :: (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek peek ptr | ptr == nullPtr  = return Nothing
		   | otherwise       = do a <- peek ptr; return (Just a)

-- marshalling lists of storable objects
-- -------------------------------------

-- |Replicates a @withXXX@ combinator over a list of objects, yielding a list of
-- marshalled objects
--
withMany :: (a -> (b -> res) -> res)  -- withXXX combinator for one object
	 -> [a]			      -- storable objects
	 -> ([b] -> res)	      -- action on list of marshalled obj.s
	 -> res
withMany _       []     f = f []
withMany withFoo (x:xs) f = withFoo x $ \x' ->
			      withMany withFoo xs (\xs' -> f (x':xs'))

-- Haskellish interface to memcpy and memmove
-- ------------------------------------------

-- |Copies the given number of bytes from the second area (source) into the
-- first (destination); the copied areas may /not/ overlap
--
copyBytes               :: Ptr a -> Ptr a -> Int -> IO ()
copyBytes dest src size  = memcpy dest src (fromIntegral size)

-- |Copies the given number of elements from the second area (source) into the
-- first (destination); the copied areas /may/ overlap
--
moveBytes               :: Ptr a -> Ptr a -> Int -> IO ()
moveBytes dest src size  = memmove dest src (fromIntegral size)

-- auxilliary routines
-- -------------------

-- |Basic C routines needed for memory copying
--
foreign import ccall  "string.h memcpy" memcpy  :: Ptr a -> Ptr a -> CSize -> IO ()
foreign import ccall  "string.h memmove" memmove :: Ptr a -> Ptr a -> CSize -> IO ()

maybe :: b -> (a -> b) -> Maybe a -> b
maybe n f m = case m of
    Just x -> f x
    Nothing -> n


text:
"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = createRender;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _enzyme = require("enzyme");

var React = _interopRequireWildcard(require("react"));

var _RenderMode = require("./RenderMode");

/**
 * Generate a render to string function.
 * @deprecated to remvoe in v5
 */
function createRender() {
  var options1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var _options1$render = options1.render,
      render = _options1$render === void 0 ? _enzyme.render : _options1$render,
      other1 = (0, _objectWithoutProperties2.default)(options1, ["render"]);

  var renderWithContext = function renderWithContext(node) {
    var options2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    return render(React.createElement(_RenderMode.RenderContext, null, node), (0, _extends2.default)({}, other1, {}, options2));
  };

  return renderWithContext;
}


text:
package com.peterphi.std.guice.hibernate.entitycollection;

import com.google.inject.Inject;
import com.peterphi.std.guice.database.annotation.Transactional;
import com.peterphi.std.guice.hibernate.dao.HibernateDao;
import com.peterphi.std.guice.hibernate.webquery.ConstrainedResultSet;
import com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery;
import com.peterphi.std.guice.testing.GuiceUnit;
import com.peterphi.std.guice.testing.com.peterphi.std.guice.testing.annotations.GuiceConfig;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Hibernate;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@RunWith(GuiceUnit.class)
@GuiceConfig(config = "hibernate-tests-in-memory-hsqldb.properties", classPackages = ParentEntity.class)
public class EntityCollectionTest
{
	@Inject
	ParentDao dao;

	@Inject
	HibernateDao<ChildEntity, Long> rDao;

	@Inject
	HibernateDao<AlternateIdReferencingEntity, Long> altDao;

	/**
	 * Simple test that using HQL works
	 *
	 * @throws Exception
	 */
	@Test
	public void testEmptyDb() throws Exception
	{
		List<Long> ids = dao.getIdsByQuery("select q.id FROM parent_entity q");

		assertEquals(0, ids.size());
	}

	@Test
	public void testRetrieveEmbeddable()
	{
		altDao.getById(1L);
	}

	@Test
	public void testChildCriteria() throws Exception
	{
		load();

		// N.B. not in a Transaction, so whatever's returned from the find call can't be filled in any further
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children.flag", true)
					                                                              .limit(1000)
					                                                              .logSQL(true));

			System.out.println("SQL: " + resultset.getSql());
			System.out.println("SQL Statements: " + resultset.getSql().size());

			List<ParentEntity> results = resultset.getList();

			System.out.println(results);

			assertEquals("Should only need 2 SQL statements", 2, resultset.getSql().size());

			for (ParentEntity result : results)
			{
				System.out.println(result.getId() +
				                   " - children " +
				                   result.getChildren().stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));

				assertEquals("each parent should have 3 children", 3, result.getChildren().size());
			}

			assertEquals("should be 2 parent entities", 2, results.size());
		}
	}

	@Test
	public void testMultipleAliases() throws Exception
	{
		load();

		// Test fetching with multiple aliases
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children[a].flag", true)
					                                                              .or(or -> or
							                                                                        .isNull("children[b].friend.id")
							                                                                        .neq("children[b].friend.id",
							                                                                         1234)).limit(1000)
					                                                              .logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), '\n'));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			assertEquals("Should have 2 result match", 2, resultset.getList().size());
			assertEquals("Should need 2 SQL statements", 2, resultset.getSql().size());

			assertEquals("constraining query should have 2 independent joins to Child",
			             2,
			             StringUtils.countMatches(resultset.getSql().get(0).toLowerCase(), "left outer join child_entity"));
		}
	}

	@Test
	public void testOneExplicitAlias() throws Exception
	{
		load();

		// Test fetching with multiple aliases
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children[a].flag", true)
					                                                              .or(or -> or
							                                                                        .isNull("children[a].friend.id")
							                                                                        .neq("children[a].friend.id",
							                                                                         1234))
					                                                              .limit(1000)
					                                                              .logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), '\n'));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			assertEquals("Should have 2 result match", 2, resultset.getList().size());
			assertEquals("Should need 2 SQL statements", 2, resultset.getSql().size());

			assertEquals("constraining query should have 1 join to Child",
			             1,
			             StringUtils.countMatches(resultset.getSql().get(0).toLowerCase(), "left outer join child_entity"));
		}
	}

	@Test
	public void testImplicitAliases() throws Exception
	{
		load();

		// Test fetching with multiple aliases
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children.flag", true)
					                                                              .or(or -> or
							                                                                        .isNull("children.friend.id")
							                                                                        .neq("children.friend.id",
							                                                                         1234))
					                                                              .limit(1000)
					                                                              .logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), '\n'));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			assertEquals("Should have 2 result match", 2, resultset.getList().size());
			assertEquals("Should need 2 SQL statements", 2, resultset.getSql().size());

			assertEquals("constraining query should have 1 join to Child",
			             1,
			             StringUtils.countMatches(resultset.getSql().get(0).toLowerCase(), "left outer join child_entity"));
		}
	}

	@Test
	public void testLoadGraphCorrectlyIdentifiesNoCollectionJoins() throws Exception
	{
		load();

		// N.B. not in a Transaction, so whatever's returned from the find call is final
		{
			// Expand a non-collection join
			final ConstrainedResultSet<ChildEntity> resultset = rDao.find(new WebQuery().dbfetch("friend").logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), "\n"));

			assertEquals("should be 1 query", 1, resultset.getSql().size());
		}
	}

	@Test
	public void testFetchingWorksWithNoConstraints() throws Exception
	{
		load();

		// N.B. not in a Transaction, so whatever's returned from the find call is final
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery().logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), "\n"));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			List<ParentEntity> results = resultset.getList();

			System.out.println(results);

			assertEquals("Should only need 1 SQL statement (get entities)", 1, resultset.getSql().size());

			for (ParentEntity result : results)
			{
				System.out.println(result.getId() +
				                   " - children " +
				                   result.getChildren().stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));

				assertEquals("each parent should have 3 children", 3, result.getChildren().size());
			}

			assertEquals("should be 2 parent entities", 2, results.size());
		}
	}

	@Test
	public void testLoadGraphWorksWithConstraintsAndNoLimit() throws Exception
	{
		load();

		// N.B. not in a Transaction, so whatever's returned from the find call is final
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery().eq("children.flag", true).logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), "\n"));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			List<ParentEntity> results = resultset.getList();

			System.out.println(results);

			assertEquals("Should only need 1 SQL statement", 1, resultset.getSql().size());

			for (ParentEntity result : results)
			{
				System.out.println(result.getId() +
				                   " - children " +
				                   result.getChildren().stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));

				assertEquals("each parent should have 3 children", 3, result.getChildren().size());
			}

			assertEquals("should be 2 parent entities", 2, results.size());
		}
	}

	@Test
	public void testExpandOnlyPullsBackRequestedData() throws Exception
	{
		load();

		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children.flag", true)
					                                                              .dbfetch("none")
					                                                              .logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), "\n"));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			assertEquals("Should only need 1 SQL statement", 1, resultset.getSql().size());
		}
	}

	@Test
	public void testLoadGraphWorksWithConstraintsAndLimit() throws Exception
	{
		load();

		// N.B. not in a Transaction, so whatever's returned from the find call is final
		{
			final ConstrainedResultSet<ParentEntity> resultset = dao.find(new WebQuery()
					                                                              .eq("children.flag", true)
					                                                              .limit(1000)
					                                                              .logSQL(true));

			System.out.println("SQL: " + StringUtils.join(resultset.getSql(), "\n"));
			System.out.println("SQL Statements: " + resultset.getSql().size());

			List<ParentEntity> results = resultset.getList();

			System.out.println(results);

			assertEquals("Should only need 2 SQL statements (get IDs, get entities)", 2, resultset.getSql().size());

			for (ParentEntity result : results)
			{
				System.out.println(result.getId() +
				                   " - children " +
				                   result.getChildren().stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));

				assertEquals("each parent should have 3 children", 3, result.getChildren().size());
			}

			assertEquals("should be 2 parent entities", 2, results.size());
		}
	}

	@Test
	public void testChildHQL() throws Exception
	{
		load();

		final List<ParentEntity> results = dao.getByQuery(
				"SELECT DISTINCT parent FROM parent_entity parent JOIN FETCH parent.children children JOIN parent.children child WHERE child.flag = true");

		for (ParentEntity result : results)
		{
			System.out.println(result.getId() +
			                   " - children " +
			                   result.getChildren().stream().map(c -> c.getId().toString()).collect(Collectors.joining(",")));
			assertEquals(3, result.getChildren().size());
		}

		assertEquals(2, results.size());
	}

	@Transactional
	public List<Long> load()
	{
		List<Long> parentIds = new ArrayList<>();

		{
			ParentEntity p1 = new ParentEntity();
			p1.setCapacity(2);
			p1.setId(dao.save(p1));

			ChildEntity c1 = new ChildEntity();
			c1.setParent(p1);
			c1.setFlag(true);
			c1.setId(rDao.save(c1));

			ChildEntity c2 = new ChildEntity();
			c2.setParent(p1);
			c2.setFlag(true);
			c2.setId(rDao.save(c2));

			ChildEntity c3 = new ChildEntity();
			c3.setParent(p1);
			c3.setFlag(false);
			c3.setId(rDao.save(c3));

			parentIds.add(p1.getId());
		}

		{
			ParentEntity p2 = new ParentEntity();
			p2.setCapacity(2);
			p2.setId(dao.save(p2));

			ChildEntity c1 = new ChildEntity();
			c1.setParent(p2);
			c1.setFlag(true);
			c1.setId(rDao.save(c1));

			ChildEntity c2 = new ChildEntity();
			c2.setParent(p2);
			c2.setFlag(true);
			c2.setId(rDao.save(c2));

			ChildEntity c3 = new ChildEntity();
			c3.setParent(p2);
			c3.setFlag(false);
			c3.setId(rDao.save(c3));

			parentIds.add(p2.getId());
		}

		return parentIds;
	}

	@Test
	public void testGetById() throws Exception
	{
		List<Long> ids = load();

		final ParentEntity entity = dao.getById(ids.get(0));

		assertTrue("Parent should be initialised", Hibernate.isInitialized(entity));
		assertTrue("Parent.Children should be initialised", Hibernate.isInitialized(entity.getChildren()));
		for (ChildEntity childEntity : entity.getChildren())
		{
			assertTrue("ChildEntity should be initialised", Hibernate.isInitialized(childEntity));
		}
	}

	@Test
	public void testGetListByIds() throws Exception
	{
		List<Long> ids = load();

		final List<ParentEntity> entities = dao.getListById(ids);

		for (ParentEntity entity : entities)
		{
			assertTrue("Parent should be initialised", Hibernate.isInitialized(entity));
			assertTrue("Parent.Children should be initialised", Hibernate.isInitialized(entity.getChildren()));
			for (ChildEntity childEntity : entity.getChildren())
			{
				assertTrue("ChildEntity should be initialised", Hibernate.isInitialized(childEntity));
			}
		}
	}

	@Test
	public void testFilledDb() throws Exception
	{
		// Find a Q where 0 != count(child.flag=false) AND q.capacity > count(r.flag=true)
		final String query = "SELECT q.id FROM parent_entity q WHERE q.capacity > (SELECT COUNT(r.id) FROM child_entity r WHERE r.parent=q.id AND r.flag=true) AND 0 <> (SELECT COUNT(r.id) FROM child_entity r WHERE r.parent=q.id AND r.flag=false)";

		ParentEntity p1;
		{
			p1 = new ParentEntity();
			p1.setCapacity(2);
			p1 = dao.getById(dao.save(p1));
		}

		List<Long> ids;

		ids = dao.getIdsByQuery(query);
		assertEquals(0, ids.size());

		{
			ChildEntity r = new ChildEntity();
			r.setParent(p1);
			r.setFlag(true);

			rDao.save(r);
		}

		ids = dao.getIdsByQuery(query);
		assertEquals(0, ids.size());

		{
			ChildEntity r = new ChildEntity();
			r.setParent(p1);
			r.setFlag(false);

			rDao.save(r);
		}

		// One Q should match now
		ids = dao.getIdsByQuery(query);
		assertEquals(1, ids.size());

		{
			ChildEntity r = new ChildEntity();
			r.setParent(p1);
			r.setFlag(true);

			rDao.save(r);
		}

		// Now none should match again

		ids = dao.getIdsByQuery(
				"SELECT q.id FROM parent_entity q WHERE q.capacity > (SELECT COUNT(r.id) FROM child_entity r WHERE r.parent=q.id AND r.flag=true) AND (SELECT COUNT(r.id) FROM child_entity r WHERE r.parent=q.id AND r.flag=false) <> 0");

		assertEquals(0, ids.size());
	}
}


text:
package version

const (
	// APID version number
	VERSION_NUMBER = "0.0.26"
)