text:
/*
 * Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
 *              Tuesday, June 16, 1998
 *
 * Purpose:	"All" selection dataspace I/O functions.
 */

#include "H5Smodule.h"          /* This source code file is part of the H5S module */

#include "H5private.h"		/* Generic Functions			*/
#include "H5Eprivate.h"		/* Error handling		        */
#include "H5Iprivate.h"		/* ID Functions		                */
#include "H5Spkg.h"		/* Dataspace functions			*/
#include "H5VMprivate.h"         /* Vector functions                     */

/* Static function prototypes */

/* Selection callbacks */
static herr_t H5S__all_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection);
static herr_t H5S__all_get_seq_list(const H5S_t *space, unsigned flags,
    H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes,
    size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len);
static herr_t H5S__all_release(H5S_t *space);
static htri_t H5S__all_is_valid(const H5S_t *space);
static hssize_t H5S__all_serial_size(const H5S_t *space, H5F_t *f);
static herr_t H5S__all_serialize(const H5S_t *space, uint8_t **p, H5F_t *f);
static herr_t H5S__all_deserialize(H5S_t *space, uint32_t version, uint8_t flags,
    const uint8_t **p);
static herr_t H5S__all_bounds(const H5S_t *space, hsize_t *start, hsize_t *end);
static herr_t H5S__all_offset(const H5S_t *space, hsize_t *off);
static int H5S__all_unlim_dim(const H5S_t *space);
static htri_t H5S__all_is_contiguous(const H5S_t *space);
static htri_t H5S__all_is_single(const H5S_t *space);
static htri_t H5S__all_is_regular(const H5S_t *space);
static void H5S__all_adjust_u(H5S_t *space, const hsize_t *offset);
static herr_t H5S__all_project_scalar(const H5S_t *space, hsize_t *offset);
static herr_t H5S__all_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset);
static herr_t H5S__all_iter_init(H5S_sel_iter_t *iter, const H5S_t *space);

/* Selection iteration callbacks */
static herr_t H5S__all_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords);
static herr_t H5S__all_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end);
static hsize_t H5S__all_iter_nelmts(const H5S_sel_iter_t *iter);
static htri_t H5S__all_iter_has_next_block(const H5S_sel_iter_t *iter);
static herr_t H5S__all_iter_next(H5S_sel_iter_t *sel_iter, hsize_t nelem);
static herr_t H5S__all_iter_next_block(H5S_sel_iter_t *sel_iter);
static herr_t H5S__all_iter_release(H5S_sel_iter_t *sel_iter);

/* Selection properties for "all" selections */
const H5S_select_class_t H5S_sel_all[1] = {{
    H5S_SEL_ALL,

    /* Methods on selection */
    H5S__all_copy,
    H5S__all_get_seq_list,
    H5S__all_release,
    H5S__all_is_valid,
    H5S__all_serial_size,
    H5S__all_serialize,
    H5S__all_deserialize,
    H5S__all_bounds,
    H5S__all_offset,
    H5S__all_unlim_dim,
    NULL,
    H5S__all_is_contiguous,
    H5S__all_is_single,
    H5S__all_is_regular,
    H5S__all_adjust_u,
    H5S__all_project_scalar,
    H5S__all_project_simple,
    H5S__all_iter_init,
}};

/* Iteration properties for "all" selections */
static const H5S_sel_iter_class_t H5S_sel_iter_all[1] = {{
    H5S_SEL_ALL,

    /* Methods on selection iterator */
    H5S__all_iter_coords,
    H5S__all_iter_block,
    H5S__all_iter_nelmts,
    H5S__all_iter_has_next_block,
    H5S__all_iter_next,
    H5S__all_iter_next_block,
    H5S__all_iter_release,
}};

/*-------------------------------------------------------------------------
 * Function:	H5S__all_iter_init
 *
 * Purpose:	Initializes iteration information for "all" selection.
 *
 * Return:	non-negative on success, negative on failure.
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, June 16, 1998
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5S__all_iter_init(H5S_sel_iter_t *iter, const H5S_t *space)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space && H5S_SEL_ALL == H5S_GET_SELECT_TYPE(space));
    HDassert(iter);

    /* Initialize the number of elements to iterate over */
    iter->elmt_left = H5S_GET_SELECT_NPOINTS(space);

    /* Start at the upper left location */
    iter->u.all.elmt_offset = 0;
    iter->u.all.byte_offset = 0;

    /* Initialize type of selection iterator */
    iter->type = H5S_sel_iter_all;

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_iter_init() */

/*-------------------------------------------------------------------------
 * Function:	H5S__all_iter_coords
 *
 * Purpose:	Retrieve the current coordinates of iterator for current
 *              selection
 *
 * Return:	non-negative on success, negative on failure
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 22, 2003
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5S__all_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords)
{
    herr_t ret_value = SUCCEED;        /* Return value */

    FUNC_ENTER_STATIC

    /* Check args */
    HDassert(iter);
    HDassert(coords);

    /* Calculate the coordinates for the current iterator offset */
    if(H5VM_array_calc(iter->u.all.elmt_offset, iter->rank, iter->dims, coords) < 0)
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't retrieve coordinates")

done:
    FUNC_LEAVE_NOAPI(ret_value)
}   /* H5S__all_iter_coords() */

/*-------------------------------------------------------------------------
 * Function:	H5S__all_iter_block
 *
 * Purpose:	Retrieve the current block of iterator for current
 *              selection
 *
 * Return:	non-negative on success, negative on failure
 *
 * Programmer:	Quincey Koziol
 *              Monday, June 2, 2003
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5S__all_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end)
{
    unsigned u;                 /* Local index variable */

    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);
    HDassert(start);
    HDassert(end);

    for(u = 0; u < iter->rank; u++) {
        /* Set the start of the 'all' block */
        /* (Always '0' coordinates for now) */
        start[u] = 0;

        /* Compute the end of the 'all' block */
        /* (Always size of the extent for now) */
        end[u] = iter->dims[u] - 1;
    } /* end for */

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_iter_block() */

/*-------------------------------------------------------------------------
 * Function:	H5S__all_iter_nelmts
 *
 * Purpose:	Return number of elements left to process in iterator
 *
 * Return:	non-negative number of elements on success, zero on failure
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, June 16, 1998
 *
 *-------------------------------------------------------------------------
 */
static hsize_t
H5S__all_iter_nelmts(const H5S_sel_iter_t *iter)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);

    FUNC_LEAVE_NOAPI(iter->elmt_left)
}   /* H5S__all_iter_nelmts() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_iter_has_next_block
 PURPOSE
    Check if there is another block left in the current iterator
 USAGE
    htri_t H5S__all_iter_has_next_block(iter)
        const H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
 RETURNS
    Non-negative (TRUE/FALSE) on success/Negative on failure
 DESCRIPTION
    Check if there is another block available in the selection iterator.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
H5S__all_iter_has_next_block(const H5S_sel_iter_t H5_ATTR_UNUSED *iter)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);

    FUNC_LEAVE_NOAPI(FALSE)
}   /* H5S__all_iter_has_next_block() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_iter_next
 PURPOSE
    Increment selection iterator
 USAGE
    herr_t H5S__all_iter_next(iter, nelem)
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
        hsize_t nelem;              IN: Number of elements to advance by
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Advance selection iterator to the NELEM'th next element in the selection.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_iter_next(H5S_sel_iter_t *iter, hsize_t nelem)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);
    HDassert(nelem > 0);

    /* Increment the iterator */
    iter->u.all.elmt_offset += nelem;
    iter->u.all.byte_offset += (nelem * iter->elmt_size);

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_iter_next() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_iter_next_block
 PURPOSE
    Increment selection iterator to next block
 USAGE
    herr_t H5S__all_iter_next_block(iter)
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Advance selection iterator to the next block in the selection.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);

    FUNC_LEAVE_NOAPI(FAIL)
}   /* H5S__all_iter_next_block() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_iter_release
 PURPOSE
    Release "all" selection iterator information for a dataspace
 USAGE
    herr_t H5S__all_iter_release(iter)
        H5S_sel_iter_t *iter;       IN: Pointer to selection iterator
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Releases all information for a dataspace "all" selection iterator
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_iter_release(H5S_sel_iter_t H5_ATTR_UNUSED * iter)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(iter);

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_iter_release() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_release
 PURPOSE
    Release all selection information for a dataspace
 USAGE
    herr_t H5S__all_release(space)
        H5S_t *space;       IN: Pointer to dataspace
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Releases "all" selection information for a dataspace
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_release(H5S_t *space)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space);

    /* Reset the number of elements in the selection */
    space->select.num_elem = 0;

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_release() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_copy
 PURPOSE
    Copy a selection from one dataspace to another
 USAGE
    herr_t H5S__all_copy(dst, src)
        H5S_t *dst;  OUT: Pointer to the destination dataspace
        H5S_t *src;  IN: Pointer to the source dataspace
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Copies the 'all' selection information from the source
    dataspace to the destination dataspace.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_copy(H5S_t *dst, const H5S_t H5_ATTR_UNUSED *src, hbool_t H5_ATTR_UNUSED share_selection)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(src);
    HDassert(dst);

    /* Set number of elements in selection */
    dst->select.num_elem = (hsize_t)H5S_GET_EXTENT_NPOINTS(dst);

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5S__all_copy() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_is_valid
 PURPOSE
    Check whether the selection fits within the extent, with the current
    offset defined.
 USAGE
    htri_t H5S__all_is_valid(space);
        H5S_t *space;             IN: Dataspace pointer to query
 RETURNS
    TRUE if the selection fits within the extent, FALSE if it does not and
        Negative on an error.
 DESCRIPTION
    Determines if the current selection at the current offset fits within the
    extent for the dataspace.  Offset is irrelevant for this type of selection.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
H5S__all_is_valid(const H5S_t H5_ATTR_UNUSED *space)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(space);

    FUNC_LEAVE_NOAPI(TRUE)
} /* end H5S__all_is_valid() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_serial_size
 PURPOSE
    Determine the number of bytes needed to store the serialized "all"
        selection information.
 USAGE
    hssize_t H5S_all_serial_size(space, f)
        H5S_t *space;             IN: Dataspace pointer to query
        H5F_t *f;                 IN: File pointer
 RETURNS
    The number of bytes required on success, negative on an error.
 DESCRIPTION
    Determines the number of bytes required to serialize an "all"
    selection for storage on disk.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static hssize_t
H5S__all_serial_size (const H5S_t H5_ATTR_UNUSED *space, H5F_t H5_ATTR_UNUSED *f)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(space);

    /* Basic number of bytes required to serialize point selection:
     *  <type (4 bytes)> + <version (4 bytes)> + <padding (4 bytes)> +
     *      <length (4 bytes)> = 16 bytes
     */
    FUNC_LEAVE_NOAPI(16)
} /* end H5S__all_serial_size() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_serialize
 PURPOSE
    Serialize the current selection into a user-provided buffer.
 USAGE
    herr_t H5S__all_serialize(space, p, f)
        const H5S_t *space;     IN: Dataspace with selection to serialize
        uint8_t **p;            OUT: Pointer to buffer to put serialized
                                selection.  Will be advanced to end of
                                serialized selection.
        H5F_t *f;               IN: File pointer
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Serializes the current element selection into a buffer.  (Primarily for
    storing on disk).
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_serialize(const H5S_t *space, uint8_t **p, H5F_t H5_ATTR_UNUSED *f)
{
    uint8_t *pp = (*p);         /* Local pointer for decoding */

    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space);
    HDassert(p);
    HDassert(pp);

    /* Store the preamble information */
    UINT32ENCODE(pp, (uint32_t)H5S_GET_SELECT_TYPE(space)); /* Store the type of selection */
    UINT32ENCODE(pp, (uint32_t)H5S_ALL_VERSION_1);          /* Store the version number */
    UINT32ENCODE(pp, (uint32_t)0);  /* Store the un-used padding */
    UINT32ENCODE(pp, (uint32_t)0);  /* Store the additional information length */

    /* Update encoding pointer */
    *p = pp;

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_serialize() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_deserialize
 PURPOSE
    Deserialize the current selection from a user-provided buffer.
 USAGE
    herr_t H5S_all_deserialize(space, p)
        H5S_t *space;           IN/OUT: Dataspace pointer to place
                                selection into
        uint32_t version        IN: Selection version
        uint8_t flags           IN: Selection flags
        uint8 **p;              OUT: Pointer to buffer holding serialized
                                selection.  Will be advanced to end of
                                serialized selection.
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    Deserializes the current selection into a buffer.  (Primarily for retrieving
    from disk).
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_deserialize(H5S_t *space, uint32_t H5_ATTR_UNUSED version, uint8_t H5_ATTR_UNUSED flags,
        const uint8_t H5_ATTR_UNUSED **p)
{
    herr_t ret_value = SUCCEED;   /* return value */

    FUNC_ENTER_STATIC

    HDassert(space);
    HDassert(p);
    HDassert(*p);

    /* Change to "all" selection */
    if(H5S_select_all(space, TRUE) < 0)
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection")

done:
    FUNC_LEAVE_NOAPI(ret_value)
}   /* H5S__all_deserialize() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_bounds
 PURPOSE
    Gets the bounding box containing the selection.
 USAGE
    herr_t H5S__all_bounds(space, start, end)
        H5S_t *space;           IN: Dataspace pointer of selection to query
        hsize_t *start;         OUT: Starting coordinate of bounding box
        hsize_t *end;           OUT: Opposite coordinate of bounding box
 RETURNS
    Non-negative on success, negative on failure
 DESCRIPTION
    Retrieves the bounding box containing the current selection and places
    it into the user's buffers.  The start and end buffers must be large
    enough to hold the dataspace rank number of coordinates.  The bounding box
    exactly contains the selection, ie. if a 2-D element selection is currently
    defined with the following points: (4,5), (6,8) (10,7), the bounding box
    with be (4, 5), (10, 8).  Calling this function on a "none" selection
    returns fail.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_bounds(const H5S_t *space, hsize_t *start, hsize_t *end)
{
    unsigned rank;                  /* Dataspace rank */
    unsigned i;                     /* index variable */

    FUNC_ENTER_STATIC_NOERR

    HDassert(space);
    HDassert(start);
    HDassert(end);

    /* Get the dataspace extent rank */
    rank = space->extent.rank;

    /* Just copy over the complete extent */
    for(i = 0; i < rank; i++) {
        start[i] = 0;
        end[i] = space->extent.size[i] - 1;
    } /* end for */

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_bounds() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_offset
 PURPOSE
    Gets the linear offset of the first element for the selection.
 USAGE
    herr_t H5S__all_offset(space, offset)
        const H5S_t *space;     IN: Dataspace pointer of selection to query
        hsize_t *offset;        OUT: Linear offset of first element in selection
 RETURNS
    Non-negative on success, negative on failure
 DESCRIPTION
    Retrieves the linear offset (in "units" of elements) of the first element
    selected within the dataspace.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
    Calling this function on a "none" selection returns fail.
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_offset(const H5S_t H5_ATTR_UNUSED *space, hsize_t *offset)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(space);
    HDassert(offset);

    /* 'All' selections always start at offset 0 */
    *offset = 0;

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_offset() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_unlim_dim
 PURPOSE
    Return unlimited dimension of selection, or -1 if none
 USAGE
    int H5S__all_unlim_dim(space)
        H5S_t *space;           IN: Dataspace pointer to check
 RETURNS
    Unlimited dimension of selection, or -1 if none (never fails).
 DESCRIPTION
    Returns the index of the unlimited dimension in this selection, or -1
    if the selection has no unlimited dimension.  "All" selections are
    always unlimited in every dimension, though this is not reflected in
    other calls, where the selection is "clipped" against the current
    extent, so for consistency this function always returns -1.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static int
H5S__all_unlim_dim(const H5S_t H5_ATTR_UNUSED *space)
{
    FUNC_ENTER_STATIC_NOERR

    FUNC_LEAVE_NOAPI(-1)
} /* end H5S__all_unlim_dim() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_is_contiguous
 PURPOSE
    Check if a "all" selection is contiguous within the dataspace extent.
 USAGE
    htri_t H5S__all_is_contiguous(space)
        H5S_t *space;           IN: Dataspace pointer to check
 RETURNS
    TRUE/FALSE/FAIL
 DESCRIPTION
    Checks to see if the current selection in the dataspace is contiguous.
    This is primarily used for reading the entire selection in one swoop.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
H5S__all_is_contiguous(const H5S_t H5_ATTR_UNUSED *space)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(space);

    FUNC_LEAVE_NOAPI(TRUE)
}   /* H5S__all_is_contiguous() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_is_single
 PURPOSE
    Check if a "all" selection is a single block within the dataspace extent.
 USAGE
    htri_t H5S__all_is_single(space)
        H5S_t *space;           IN: Dataspace pointer to check
 RETURNS
    TRUE/FALSE/FAIL
 DESCRIPTION
    Checks to see if the current selection in the dataspace is a single block.
    This is primarily used for reading the entire selection in one swoop.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
H5S__all_is_single(const H5S_t H5_ATTR_UNUSED *space)
{
    FUNC_ENTER_STATIC_NOERR

    HDassert(space);

    FUNC_LEAVE_NOAPI(TRUE)
}   /* H5S__all_is_single() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_is_regular
 PURPOSE
    Check if a "all" selection is "regular"
 USAGE
    htri_t H5S__all_is_regular(space)
        const H5S_t *space;     IN: Dataspace pointer to check
 RETURNS
    TRUE/FALSE/FAIL
 DESCRIPTION
    Checks to see if the current selection in a dataspace is the a regular
    pattern.
    This is primarily used for reading the entire selection in one swoop.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static htri_t
H5S__all_is_regular(const H5S_t H5_ATTR_UNUSED *space)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space);

    FUNC_LEAVE_NOAPI(TRUE)
}   /* H5S__all_is_regular() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_adjust_u
 PURPOSE
    Adjust an "all" selection by subtracting an offset
 USAGE
    void H5S__all_adjust_u(space, offset)
        H5S_t *space;           IN/OUT: Pointer to dataspace to adjust
        const hsize_t *offset; IN: Offset to subtract
 RETURNS
    None
 DESCRIPTION
    Moves selection by subtracting an offset from it.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static void
H5S__all_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *offset)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space);
    HDassert(offset);

    FUNC_LEAVE_NOAPI_VOID
}   /* H5S__all_adjust_u() */

/*-------------------------------------------------------------------------
 * Function:	H5S__all_project_scalar
 *
 * Purpose:	Projects a single element 'all' selection into a scalar
 *              dataspace
 *
 * Return:	non-negative on success, negative on failure.
 *
 * Programmer:	Quincey Koziol
 *              Sunday, July 18, 2010
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5S__all_project_scalar(const H5S_t H5_ATTR_UNUSED *space, hsize_t *offset)
{
    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space && H5S_SEL_ALL == H5S_GET_SELECT_TYPE(space));
    HDassert(offset);

    /* Set offset of selection in projected buffer */
    *offset = 0;

    FUNC_LEAVE_NOAPI(SUCCEED)
}   /* H5S__all_project_scalar() */

/*-------------------------------------------------------------------------
 * Function:	H5S__all_project_simple
 *
 * Purpose:	Projects an 'all' selection onto/into a simple dataspace
 *              of a different rank
 *
 * Return:	non-negative on success, negative on failure.
 *
 * Programmer:	Quincey Koziol
 *              Sunday, July 18, 2010
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5S__all_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *offset)
{
    herr_t ret_value = SUCCEED;         /* Return value */

    FUNC_ENTER_STATIC

    /* Check args */
    HDassert(base_space && H5S_SEL_ALL == H5S_GET_SELECT_TYPE(base_space));
    HDassert(new_space);
    HDassert(offset);

    /* Select the entire new space */
    if(H5S_select_all(new_space, TRUE) < 0)
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "unable to set all selection")

done:
    FUNC_LEAVE_NOAPI(ret_value)
}   /* H5S__all_project_simple() */

/*--------------------------------------------------------------------------
 NAME
    H5S_select_all
 PURPOSE
    Specify the the entire extent is selected
 USAGE
    herr_t H5S_select_all(dsid)
        hid_t dsid;             IN: Dataspace ID of selection to modify
        hbool_t rel_prev;      IN: Flag whether to release previous selection or not
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    This function selects the entire extent for a dataspace.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5S_select_all(H5S_t *space, hbool_t rel_prev)
{
    herr_t ret_value = SUCCEED;  /* return value */

    FUNC_ENTER_NOAPI(FAIL)

    /* Check args */
    HDassert(space);

    /* Remove current selection first */
    if(rel_prev)
        if(H5S_SELECT_RELEASE(space) < 0)
            HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection")

    /* Set number of elements in selection */
    space->select.num_elem = (hsize_t)H5S_GET_EXTENT_NPOINTS(space);

    /* Set selection type */
    space->select.type = H5S_sel_all;

done:
    FUNC_LEAVE_NOAPI(ret_value)
}   /* H5S_select_all() */

/*--------------------------------------------------------------------------
 NAME
    H5Sselect_all
 PURPOSE
    Specify the the entire extent is selected
 USAGE
    herr_t H5Sselect_all(dsid)
        hid_t dsid;             IN: Dataspace ID of selection to modify
 RETURNS
    Non-negative on success/Negative on failure
 DESCRIPTION
    This function selects the entire extent for a dataspace.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
herr_t
H5Sselect_all(hid_t spaceid)
{
    H5S_t *space;               /* Dataspace to modify selection of */
    herr_t ret_value = SUCCEED; /* return value */

    FUNC_ENTER_API(FAIL)
    H5TRACE1("e", "i", spaceid);

    /* Check args */
    if(NULL == (space = (H5S_t *)H5I_object_verify(spaceid, H5I_DATASPACE)))
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")

    /* Call internal routine to do the work */
    if(H5S_select_all(space, TRUE) < 0)
        HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection")

done:
    FUNC_LEAVE_API(ret_value)
}   /* H5Sselect_all() */

/*--------------------------------------------------------------------------
 NAME
    H5S__all_get_seq_list
 PURPOSE
    Create a list of offsets & lengths for a selection
 USAGE
    herr_t H5S__all_get_seq_list(space,flags,iter,maxseq,maxelem,nseq,nelem,off,len)
        H5S_t *space;           IN: Dataspace containing selection to use.
        unsigned flags;         IN: Flags for extra information about operation
        H5S_sel_iter_t *iter;   IN/OUT: Selection iterator describing last
                                    position of interest in selection.
        size_t maxseq;          IN: Maximum number of sequences to generate
        size_t maxelem;         IN: Maximum number of elements to include in the
                                    generated sequences
        size_t *nseq;           OUT: Actual number of sequences generated
        size_t *nelem;          OUT: Actual number of elements in sequences generated
        hsize_t *off;           OUT: Array of offsets
        size_t *len;            OUT: Array of lengths
 RETURNS
    Non-negative on success/Negative on failure.
 DESCRIPTION
    Use the selection in the dataspace to generate a list of byte offsets and
    lengths for the region(s) selected.  Start/Restart from the position in the
    ITER parameter.  The number of sequences generated is limited by the MAXSEQ
    parameter and the number of sequences actually generated is stored in the
    NSEQ parameter.
 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
static herr_t
H5S__all_get_seq_list(const H5S_t H5_ATTR_UNUSED *space, unsigned H5_ATTR_UNUSED flags, H5S_sel_iter_t *iter,
    size_t H5_ATTR_UNUSED maxseq, size_t maxelem, size_t *nseq, size_t *nelem,
    hsize_t *off, size_t *len)
{
    size_t elem_used;           /* The number of elements used */

    FUNC_ENTER_STATIC_NOERR

    /* Check args */
    HDassert(space);
    HDassert(iter);
    HDassert(maxseq > 0);
    HDassert(maxelem > 0);
    HDassert(nseq);
    HDassert(nelem);
    HDassert(off);
    HDassert(len);

    /* Determine the actual number of elements to use */
    H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t);
    elem_used = MIN(maxelem, (size_t)iter->elmt_left);
    HDassert(elem_used > 0);

    /* Compute the offset in the dataset */
    off[0] = iter->u.all.byte_offset;
    len[0] = elem_used * iter->elmt_size;

    /* Should only need one sequence for 'all' selections */
    *nseq = 1;

    /* Set the number of elements used */
    *nelem = elem_used;

    /* Update the iterator */
    iter->elmt_left -= elem_used;
    iter->u.all.elmt_offset += elem_used;
    iter->u.all.byte_offset += len[0];

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5S__all_get_seq_list() */


text:
from __future__ import unicode_literals

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('users', '0006_auto_20170202_0133'),
    ]

    operations = [
        migrations.AddField(
            model_name='userprofile',
            name='google_talk',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='hike',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='line',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='office_number',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='primary_number',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='qq',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='secondary_number',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='tango',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='twitter',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='viber',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='wechat',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AddField(
            model_name='userprofile',
            name='whatsapp',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AlterField(
            model_name='userprofile',
            name='address',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AlterField(
            model_name='userprofile',
            name='phone',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
        migrations.AlterField(
            model_name='userprofile',
            name='skype',
            field=models.CharField(max_length=140, null=True, blank=True),
        ),
    ]

redpajama_set_name: RedPajamaGithub


text:
package com.facebook.flipper.android.utils;

import android.app.ActivityManager;
import android.content.Context;
import com.facebook.flipper.BuildConfig;
import java.util.List;

public final class FlipperUtils {

  private FlipperUtils() {}

  public static boolean shouldEnableFlipper(final Context context) {
    return (BuildConfig.IS_INTERNAL_BUILD || BuildConfig.LOAD_FLIPPER_EXPLICIT)
        && !isEndToEndTest()
        && isMainProcess(context)
        // Flipper has issue with ASAN build. They cannot be concurrently enabled.
        && !BuildConfig.IS_ASAN_BUILD;
  }

  private static boolean isEndToEndTest() {
    final String value = System.getenv("BUDDY_SONAR_DISABLED");
    if (value == null || value.length() == 0) {
      return false;
    }

    try {
      return Boolean.parseBoolean(value);
    } catch (NumberFormatException e) {
      return false;
    }
  }

  private static boolean isMainProcess(final Context context) {
    final int pid = android.os.Process.myPid();
    final ActivityManager manager =
        (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final List<ActivityManager.RunningAppProcessInfo> infoList = manager.getRunningAppProcesses();

    String processName = null;
    if (infoList != null) {
      for (ActivityManager.RunningAppProcessInfo info : infoList) {
        if (info.pid == pid) {
          processName = info.processName;
          break;
        }
      }
    }

    return context.getPackageName().equals(processName);
  }
}


text:
import sys
import traceback
from org.apache.nifi.processor import Processor
from org.apache.nifi.processor import Relationship
from org.apache.nifi.components import PropertyDescriptor
from org.apache.nifi.processor.util import StandardValidators

class UpdateAttributes(Processor) :
    __rel_success = Relationship.Builder().description("Success").name("success").build()

    def __init__(self) :
        pass

    def initialize(self, context) :
        pass

    def getRelationships(self) :
        return set([self.__rel_success])

    def validate(self, context) :
        pass

    def getPropertyDescriptors(self) :
        descriptor = PropertyDescriptor.Builder().name("for-attributes").addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build()
        return [descriptor]

    def onPropertyModified(self, descriptor, newValue, oldValue) :
        pass

    def onTrigger(self, context, sessionFactory) :
        session = sessionFactory.createSession()
        try :
            # ensure there is work to do
            flowfile = session.get()
            if flowfile is None :
                return

            # extract some attribute values
            fromPropertyValue = context.getProperty("for-attributes").getValue()
            fromAttributeValue = flowfile.getAttribute("for-attributes")

            # set an attribute
            flowfile = session.putAttribute(flowfile, "from-property", fromPropertyValue)
            flowfile = session.putAttribute(flowfile, "from-attribute", fromAttributeValue)

            # transfer
            session.transfer(flowfile, self.__rel_success)
            session.commit()
        except :
            print sys.exc_info()[0]
            print "Exception in TestReader:"
            print '-' * 60
            traceback.print_exc(file=sys.stdout)
            print '-' * 60

            session.rollback(true)
            raise

processor = UpdateAttributes()


text:
'use strict'

const IndexFile = require('../lib/natural/wordnet/index_file')

describe('indexFile', function () {
  describe('getFileSize', function () {
    it('should look up a word if the file exists', function () {
      const indexFile = new IndexFile('spec/test_data/', 'document1.txt')
      indexFile.lookupFromFile('node', function (indexRecord) {
      })
    })

    it('should fail to lookup a word if the file does not exist', function () {
      const indexFile = new IndexFile('spec/test_data/', 'nonexistent.txt')
      indexFile.lookupFromFile('node', function (err) {
        err.code.should.equal('ENOENT')
      })
    })
  })
})


text:
package com.hazelcast.query.impl.predicates;

import com.hazelcast.test.HazelcastSerialClassRunner;
import com.hazelcast.test.annotation.QuickTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

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

@RunWith(HazelcastSerialClassRunner.class)
@Category(QuickTest.class)
public class SqlParserTest {

    private final SqlParser parser = new SqlParser();

    @Test
    public void parseEmpty() {
        List<String> list = parser.toPrefix("");
        assertTrue(list.isEmpty());
    }

    @Test
    public void parseAEqB() {
        String query = "a = b";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("a", "b", "="), list);
    }

    @Test
    public void parseAeqBandXgrtY() {
        assertTrue(parser.hasHigherPrecedence("=", "AND"));
        assertFalse(parser.hasHigherPrecedence("=", ">"));
        List<String> list = parser.toPrefix("a = b AND x > y");
        assertEquals(Arrays.asList("a", "b", "=", "x", "y", ">", "AND"), list);
    }

    @Test
    public void parseAeqBandOpenBsmlCorDgtEclose() {
        String query = "A = B AND ( B < C OR D > E )";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("A", "B", "=", "B", "C", "<", "D", "E", ">", "OR", "AND"), list);
    }

    @Test
    public void testComplexStatement() {
        String query = "age > 5 AND ( ( ( active = true ) AND ( age = 23 ) ) OR age > 40 ) AND ( salary > 10 ) OR age = 10";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("age", "5", ">", "active", "true", "=", "age", "23", "=", "AND", "age", "40", ">", "OR",
                "AND", "salary", "10", ">", "AND", "age", "10", "=", "OR"), list);
    }

    @Test
    public void testTwoInnerParenthesis() {
        String query = "a and b AND ( ( ( a > c AND b > d ) OR ( x = y ) ) ) OR t > u";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("a", "b", "and", "a", "c", ">", "b", "d", ">", "AND", "x", "y", "=", "OR", "AND", "t", "u",
                ">", "OR"), list);
    }

    @Test
    public void testBetweenAnd() {
        String query = "a and b between 10 and 15";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("a", "b", "10", "15", "between", "and"), list);
    }

    @Test
    public void testBetween() {
        String query = "b between 10 and 15";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("b", "10", "15", "between"), list);
    }

    @Test
    public void testBetweenSimple() {
        String s = "b between 'ali' and 'veli''s'";
        List<String> list = parser.toPrefix(s);
        assertEquals(Arrays.asList("b", "'ali'", "'veli''s'", "between"), list);
    }

    @Test
    public void testIn() {
        String query = "a and b OR c in ( 4, 5, 6 )";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("a", "b", "and", "c", "4,5,6", "in", "OR"), list);
    }

    @Test
    public void testNot() {
        String query = "a and not(b) OR c not in ( 4, 5, 6 )";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("a", "b", "not", "and", "c", "4,5,6", "in", "not", "OR"), list);
    }

    @Test
    public void testNotEqual1() {
        String query = "b != 30";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("b", "30", "!="), list);
    }

    @Test
    public void testNotEqual2() {
        String query = "b <> 30";
        List<String> list = parser.toPrefix(query);
        assertEquals(Arrays.asList("b", "30", "<>"), list);
    }

    @Test
    public void split1() {
        List<String> tokens = parser.split("a and b");
        assertEquals(Arrays.asList("a", "and", "b"), tokens);
    }

    @Test
    public void split2() {
        List<String> tokens = parser.split("(a and b)");
        assertEquals(Arrays.asList("(", "a", "and", "b", ")"), tokens);
    }

    @Test
    public void split3() {
        List<String> tokens = parser.split("((a and b))");
        assertEquals(Arrays.asList("(", "(", "a", "and", "b", ")", ")"), tokens);
    }

    @Test
    public void split4() {
        List<String> tokens = parser.split("a and b AND(((a>c AND b> d) OR (x = y )) ) OR t>u");
        assertEquals(Arrays.asList("a", "and", "b", "AND", "(", "(", "(", "a", ">", "c", "AND", "b", ">", "d", ")", "OR", "(",
                "x", "=", "y", ")", ")", ")", "OR", "t", ">", "u"), tokens);
    }

    @Test
    public void split5() {
        List<String> tokens = parser.split("a and b AND(((a>=c AND b> d) OR (x <> y )) ) OR t>u");
        assertEquals(Arrays.asList("a", "and", "b", "AND", "(", "(", "(", "a", ">=", "c", "AND", "b", ">", "d", ")", "OR", "(",
                "x", "<>", "y", ")", ")", ")", "OR", "t", ">", "u"), tokens);
    }

    @Test
    public void testComplexStatementWithGreaterAndEqueals() {
        String s = "age>=5 AND ((( active = true ) AND (age = 23 )) OR age > 40) AND( salary>10 ) OR age=10";
        List<String> list = parser.toPrefix(s);
        assertEquals(Arrays.asList("age", "5", ">=", "active", "true", "=", "age", "23", "=", "AND", "age", "40", ">", "OR",
                "AND", "salary", "10", ">", "AND", "age", "10", "=", "OR"), list);
    }

    @Test(expected = NullPointerException.class)
    public void parserShouldNotAcceptNull() {
        parser.toPrefix(null);
        fail();
    }

    @Test
    public void parserShouldThrowOnInvalidInput() {
        parser.toPrefix(")");
    }

    @Test
    public void shouldNotThrowOnRandomInput() {
        Random random = new SecureRandom();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < 1000; i++) {
            stringBuilder.setLength(0);
            for (int n = 0; n < 1000; n++) {
                stringBuilder.append((char) (random.nextInt() & 0xFFFF));
            }
            parser.toPrefix(stringBuilder.toString());
        }
    }
}


text:
<?php
require_once dirname(__FILE__) . '/accesscheck.php';

class phplistPlugin {
  ############################################################
  # Registration & Config

  public $name= "Default Plugin";
  public $version= "unknown";
  public $authors= "";
  public $description = 'No description';
  public $enabled = 1; // use directly, can be privitsed later and calculated with __get and __set
  public $system_root = ''; ## root dir of the phpList admin directory
  #@@Some ideas to implement this:
  # * Start each method with if (!$this->enabled) return parent :: parentMethod($args);
  # * Don't add to manage Global plugins if disabled
  public $coderoot = "./PLUGIN_ROOTDIR/defaultplugin/"; # coderoot relative to the phplist admin directory
  # optional configuration variables
  public $configvars = array ();
  # config var    array( type, name [array values]));
  public $DBstruct= array ();
  # These files can be called from the commandline
  # This should hold an array per file: filename (without .php) => path relative to admin/
  public $commandlinePluginPages = array();

  # An array of page names that can be called as public pages, e.g. www.mysite.com/lists/?pi=myplugin&p=mypage
  # The page name is the file name without .php. The files must be in the $coderoot directory
  public $publicPages = array();

  public $configArray = array();

  public $importTabTitle = ''; ## title of the tab for the import page

  public $needI18N = 0;

  ## set to true, if this plugin provides the WYSIWYG editor for the send page
  /* the plugin will then need to implement:
   *
   * function editor($fieldname,$fieldvalue)
   *
   * which returns the HTML for the editor.
   */
  public $editorProvider = false;

  public $tables = array(); // will hold tablename -> real table mapping

  /* array of pages in this plugin to add to the main menu
   *
   * example format:
   *      array(
   *          'page' => array('category' => 'subscribers'),
   *      )
   *
   * valid categories are:
   *
   * subscribers
   * campaigns
   * statistics
   * system
   * config
   * develop (will only show up in "dev" mode)
   * info
   *
   */
  public $topMenuLinks = array();

  /* titles of pages in the plugin, this is used in the listing of the pages in the menu
   *
   * example:
   *    array(
   *      'page' => 'Title of page'
   *    )
   */

  public $pageTitles = array();

  function name() {
    return $this->name;
  }

  /*
   * constructor
   * plugins should not run SQL queries as construction time
   * use the "activate" function instead
   * that way you can use processDBerror to handle DB errors
   */
  function __construct() {
    $this->phplistplugin();
  }

  function phplistplugin() {
    # constructor
    # Startup code, other objects might not be constructed yet
    #print ("
Construct " . $this->name);
    ## try to prepend PLUGIN ROOTDIR, if necessary
    if (!is_dir($this->coderoot)) {
      $this->coderoot = PLUGIN_ROOTDIR . '/' . $this->coderoot;
    }
    ## always enable in dev mode
    if (!empty($GLOBALS['developer_email'])) {
      $this->enabled = 1;
    }
    $this->importTabTitle = $this->name;
    $this->system_root = dirname(__FILE__);
    if (isset($this->settings)) {
      foreach ($this->settings as $item => $itemDetails) {
        $GLOBALS['default_config'][$item] = $itemDetails;
        $GLOBALS['default_config'][$item]['hidden'] = false;
      }
    }
    $this->version = $this->getVersion();
    ## map table names
    $me = new ReflectionObject($this);
    foreach ($this->DBstruct as $table => $structure) {
      $this->tables[$table] = $GLOBALS['table_prefix'].$me->getName().'_'.$table;
    }
  }

  function getVersion() {
    $version = array();
    $me = new ReflectionObject($this);

    ## interesting trick from Dokuwiki inc/infoutils.php
    if(is_dir(dirname($me->getFileName()).'/../.git')) {
        $version['type'] = 'Git';
        $version['date'] = 'unknown';

        $inventory = dirname($me->getFileName()).'/../.git/logs/HEAD';
        if(is_file($inventory)){
            $sz   = filesize($inventory);
            $seek = max(0,$sz-2000); // read from back of the file
            $fh   = fopen($inventory,'rb');
            fseek($fh,$seek);
            $chunk = fread($fh,2000);
            fclose($fh);
            $chunk = trim($chunk);
            $chunk = @array_pop(explode("\n",$chunk));   //last log line
            $chunk = @array_shift(explode("\t",$chunk)); //strip commit msg
            $chunk = explode(" ",$chunk);
            array_pop($chunk); //strip timezone
            $date = date('Y-m-d',array_pop($chunk));
            if($date) $version['date'] = $date;
        }
        return $version['type']. ' - ' .$version['date'];
    }
    return $this->version;
  }

  function initialise() {
    global $table_prefix;
    $me = new ReflectionObject($this);
    $plugin_initialised = getConfig(md5('plugin-'.$me->getName().'-initialised'));
    if (empty($plugin_initialised)) {
      foreach ($this->DBstruct as $table => $structure) {
        if (!Sql_Table_exists( $table_prefix.$me->getName().'_'.$table) ) {
       #  print s('Creating table').' '.$table . '
';
          Sql_Create_Table($table_prefix.$me->getName().'_'.$table, $structure);
        }
      }
      saveConfig(md5('plugin-'.$me->getName().'-initialised'),time(),0);
    }
  }

  function upgrade($previous) {
    return true;
  }

  function activate() {
    # Startup code, all other objects are constructed
    # returns success or failure, false means we cannot start
  }

  function displayAbout() {
    # Return html snippet to tell about coopyrights of used third party code.
    # author is already displayed
    return null;
  }

  function i18nLanguageDir() {
    # Return i18n Language Dir so that main page content can be extended
    return null;
  }

  function pageTitle($page) {
    if (isset($this->pageTitles[$page])) return s($this->pageTitles[$page]);
    return $this->name.' : '.$page;
  }

  function pageTitleHover($page) {
    if (isset($this->pageTitleHover[$page])) return s($this->pageTitleHover[$page]);
    return $this->name.' : '.$page;
  }

  /** deleteSent - wipe DB entries marking a campaign sent for subscribers
   *
   * this is used in DEV mode only
   */

  function deleteSent() {
  }

  function writeConfig($name, $value) {
    #  write a value to the general config to be retrieved at a later stage
    # parameters: name -> name of the variable
    #             value -> value of the variablesiable, can be a scalar, array or object
    # returns success or failure    $store = '';
    if (is_object($value) || is_array($value)) {
      $store= 'SER:' . serialize($value);
    } else {
      $store= $value;
    }
    Sql_Query(sprintf('replace into %s set item = "%s-%s",value="%s",editable=0', $GLOBALS['tables']['config'], $this->name, addslashes($name), addslashes($store)));
    ## force refresh of config in session
    unset($_SESSION['config']);
    return 1;
  }

  function getConfig($name) {
    # read a value from the general config to be retrieved at a later stage
    # parameters: name -> name of the variable
    # returns value

    if (isset($_SESSION['config'][$this->name.'-'.addslashes($name)])) {
      return $_SESSION['config'][$this->name.'-'.addslashes($name)];
    }

    $req= Sql_Fetch_Array_Query(sprintf('select value from  %s where item = "%s-%s"', $GLOBALS['tables']['config'], $this->name, addslashes($name)));
    $result= stripslashes($req[0]);
    if (!empty ($result) && strpos('SER:', $result) == 1) {
      $result= substr($result, 4);
      $value= unserialize($result);
    } else {
      $value = $result;
    }
    $_SESSION['config'][$this->name.'-'.addslashes($name)] = $value;
    return $result;
  }

  function displayConfig($name) {
    ## displayConfig
    # purpose: display input for a config variable in the backend
    # parameters:
    # name -> name of the config variable, as found in $this->configvars
    # return, HTML snippet of input to slot into a form
    $name= trim(strtolower($name));
    $name= preg_replace('/\W/', '', $name);
    $type= $this->configvars[$name][0];
    $label= $this->configvars[$name][1];
    $currentvalue= $this->getConfig($name);
    $html= '';
    switch ($type) {
      case 'attributeselect' :
        $html= sprintf('<select name="%s"><option value=""> --%s</option>', $name, $GLOBALS['I18N']->get('choose'));
        $req= Sql_Query(sprintf('select * from %s', $GLOBALS['tables']['attribute']));
        while ($row= Sql_Fetch_Array($req)) {
          $html .= sprintf('<option value="%d" %s>%s</option>', $row['id'], $row['id'] == $currentvalue ? 'selected="selected"' : '', substr(htmlspecialchars($row['name']),0,25));
        }
        $html .= '</select>';
        return $html;
      case 'radio' :
        $values= $this->configvars[$name][2];
        foreach ($values as $key => $label) {
          $html .= sprintf('<input type="radio" name="%s" value="%s" %s> %s', $name, $key, $currentvalue == $key ? 'checked="checked"' : '', $label);
        }
        return $html;
      case 'textarea' :
        $html= sprintf('<textarea name="%s" rows="10" cols="40" wrap="virtual">%s </textarea>', $name, htmlspecialchars($currentvalue));
        return $html;
      case 'text' :
      default :
        $html= sprintf('<input type="text" name="%s" value="%s" size="45">', $name, htmlspecialchars($currentvalue));
        return $html;
    }
  }

  ############################################################
  # Main interface hooks

  function adminmenu() {
    return array (
      # page, description
      "main" => "Main Page",
      "helloworld" => "Hello World page"
    );
  }

  ############################################################
  # Frontend

  function displaySubscriptionChoice($pageData, $userID= 0) {
    # return snippet for the Subscribe page
    return '';
  }

  function validateSubscriptionPage($pageData) {
    return;
  }

  function parseThankyou($pageid= 0, $userid= 0, $text= "") {
    # parse the text of the thankyou page
    # parameters:
    #  pageid -> id of the subscribe page
    #  userid -> id of the user
    #  text -> current text of the page
    # returns parsed text
    return $text;
  }

  function subscriberConfirmation($subscribepageID,$userdata = array()) {

  }

  ############################################################
  # Messages

  /* displayMessages
   *  obsolete
   * @return string
   */

  function displayMessages($msg, &$status) {
    return "";
  }

  ############################################################
  # Message

  function sendMessageTab($messageid= 0, $messagedata= array ()) {
    ## add a tab to the "Send a Message page" for options to be set in the plugin
    # parameters:
    #    messageid = ID of the message being displayed (should always be > 0)
    #    messagedata = associative array of all data from the db for this message
    # returns: HTML code to slot into the form to submit to the database
    return '';
  }

  function sendMessageTabTitle($messageid= 0) {
    ## If adding a TAB to the Send a Message page, what is the TAB's name
    # parameters: none
    # returns: short title (less than about 10 characters)
    return '';
  }

  function sendMessageTabSave($messageid= 0, $data= array ()){
    ## add a tab to the "Send a Message page" for options to be set in the plugin
    # parameters:
    #    messageid = ID of the message being saved (should always be > 0)
    #    messagedata = associative array of all data from the db for this message
    # returns: HTML code to communicate the result to the user
    return '';
  }

  function sendFormats() {
    ## sendFormats();
    # parameters: none
    # returns array of "shorttag" => "description" of possible formats this plugin can provide
    # this will be listed in the "Send As" list of radio buttons, so that an editor can choose the format
    # prefix the shorttag with _ to suppress it from the send page (for internal use)
    return array ();
  }

  /*
   * HelloWorld
   * just a simple check
   */
  function HelloWorld($params) {
    print "Hello to you from ".$this->name;
  }

  ############################################################
  # Processqueue

  /* canSend
   *
   * can this message be sent to this subscriber
   * if false is returned, the message will be identified as sent to the subscriber
   * and never tried again
   *
   * @param $messagedata array of all message data
   * @param $userdata array of all user data
   * returns bool: true, send it, false don't send it
 */

  function canSend ($messagedata, $subscriberdata) {
    return true; //@@@
  }

  /* throttleSend
   *
   * can this message be sent to this subscriber
   * if false is returned, the message will be identified as failed
   * and re-tried in the next queue run
   *
   * @param $messagedata array of all message data
   * @param $userdata array of all user data
   * returns bool: true, do not send it, false send it
 */

  function throttleSend($messagedata, $subscriberdata) {
    return false;
  }

  /**
   * messageStatusLimitReached
   *
   * @param $recentlySent integer
   * @return text to display in the status panel of the active message
   */
  function messageStatusLimitReached($recentlySent) {
    return '';
  }

  /** messageStatus
   *
   * @param integer $id messageid
   * @param string $status message status
   * @return possible additional text to display
   */
  function messageStatus($id,$status) {
    return '';
  }

  /*
   * parseOutgoingTextMessage
   * @param integer messageid: ID of the message
   * @param string  content: entire text content of a message going out
   * @param string  destination: destination email
   * @param array   userdata: associative array with data about user
   * @return string parsed content
   */
  function parseOutgoingTextMessage($messageid, $content, $destination, $userdata = null) {
    return $content;
  }

  /*
   * parseOutgoingHTMLMessage
   * @param integer messageid: ID of the message
   * @param string  content: entire text content of a message going out
   * @param string  destination: destination email
   * @param array   userdata: associative array with data about user
   * @return string parsed content
   */
  function parseOutgoingHTMLMessage($messageid, $content, $destination, $userdata = null) {
    return $content;
  }

  function getMessageAttachment($messageid, $content) {
    ###getMessageAttachment($messageid,$mail->Body);
    # parameters: $messageid,$messagecontent
    # returns array (
    #  'content' => Content of the attachment
    #  'filename' => name of the attached file
    #  'mimetype' => mimetype of the attachment
    # );
    return array ();
  }

  function mimeWrap($messageid, $body, $header, $contenttype, $destination) {
    ### mimeWrap
    # purpose: wrap the actual contents of the message in another MIME layer
    # Designed to ENCRYPT the fully expanded message just before sending
    # Designed to be called by phplistmailer
    # parameters:
    #   messageid: message being sent
    #   body: current body of message
    #   header: current header of message, except for the Content-Type
    #   contenttype: Content-Type of message
    #   destination: email that this message is going out to
    # returns array(newheader,newbody,newcontenttype)
    return array (
      $header,
      $body,
      $contenttype
    );
  }

  function setFinalDestinationEmail($messageid, $uservalues, $email) {
    ### setFinalDestinationEmail
    # purpose: change the actual recipient based on user Attribute values:
    # parameters:
    #   messageid: message being sent
    #   uservalues: array of "attributename" => "attributevalue" of all user attributes
    #   email: email that this message is current set to go out to
    # returns: email that it should go out to
    return $email;
  }

  /**
   * messageHeaders
   *
   * return headers for the message to be added, as "key => val"
   *
   * @param object $mail
   * @return array (headeritem => headervalue)
   */
  function messageHeaders($mail) {
    return array();
  }

  /** parseFinalMessage
    * purpose: create the actual message, based on the text and html content as prepared by phplist
    * parameters:
    * sendformat: the send format chosen by the admin
    *    if this is not one of the sendFormats() set up for this plugin, return 0
    * htmlmessage: contents of HTML version of message
    * textmessage: contents of Text version of message
    * mail:  mail object that is going to be send
    *
    ### you can alter the outgoing mail by calling the required methods of the mail object
    * returns 1 if the message has been dealt with successfully and 0 if not
    */

  function parseFinalMessage($sendformat, $htmlmessage, $textmessage, & $mail,$messageid) {
    return 0;
  }

  function processSuccesFailure($messageid, $sendformat, $userdata, $success= true) {
    # purpose: process the success or failure of sending an email in $sendformat
    #   if function returns false, caller will know the whole email should be marked as failed
    # Currently used in sendemaillib.php
    # 200710 Bas
    return true;
  }

  /**
   * processSendSuccess
   *
   * called when sending of this messageid to this subscriber was successful
   *
   * @param messageid integer
   * @param userdata array
   * @param isTest boolean, true when testmessage
   * @return null
   */

  function processSendSuccess($messageid, $userdata, $isTest = false) {
  }

  /**
   * processSendFailed
   *
   * called when sending of this messageid to this subscriber failed
   *
   * @param messageid integer
   * @param userdata array
   * @param isTest boolean, true when testmessage
   * @return null
   */
  function processSendFailed($messageid, $userdata, $isTest = false) {
  }

  /*
   * processSendStats
   * called when sending a campaign has finished
   * @param integer $sent - amount sent
   * @param integer $invalid - amount invalid
   * @param integer $failed_sent - amount failed
   * @param integer $unconfirmed - amount unconfirmed
   *
   * receive stats from phpList for further handling
   * @return null
   */

  function processSendStats($sent = 0,$invalid = 0,$failed_sent = 0,$unconfirmed = 0,$counters = array()) {
    return;
  }

  /* sendReport
   * @param string $subject
   * @param string $message
   * @return null
   */
  function sendReport ($subject,$message) {
  }

  /* sendError
   * @param string $subject
   * @param string $to
   * @param string $message
   * @return null
   */
  function sendError ($subject,$to = '',$message = '') {
  }

  /* processDBerror
   * @param integer $error number
   * @return null
   */
  function processDBerror($errorid) {

  }

  /* importReport
   * called when a subscriber import has finished
   * @param string $report
   * @return null
   */
  function importReport($report) {
  }

  /* processError
   * @param string msg
   */
  function processError($msg) {
  }

  /* processQueueStart
   * called at the beginning of processQueue, after the process was locked
   * @param none
   * @return null
   */
  function processQueueStart() {
  }

  /* allowProcessQueue
   * called at the beginning of processQueue
   * if this returns anything but "true" processing will be cancelled
   * @param none
   * @return bool
   */
  function allowProcessQueue() {
    return true;
  }

  /* sendtestAllowed
   * called when trying to send a test email
   * return false is sending a test email is not allowed
   * @param array messagedata
   * @return bool;
   */
  function sendTestAllowed($messagedata) {
    return true;
  }

  /*
   * campaignStarted
   * called when sending of a campaign starts
   * @param array messagedata - associative array with all data for campaign
   * @return null
   */

  function campaignStarted($messagedata = array()) {
  }

  /* allowMessageToBeQueued
   * called to verify that the message can be added to the queue
   * @param array messagedata - associative array with all data for campaign
   * @return empty string if allowed, or error string containing reason for not allowing
   */
  function allowMessageToBeQueued($messagedata = array()) {
    return '';
  }

  /* messageQueued
   * called when a message is placed in the queue
   * @param integer id message id
   * @return null
   */

  function messageQueued($id) {
  }

  /* messageReQueued
   * called when a message is placed back in the queue
   * @param integer id message id
   * @return null
   */

  function messageReQueued($id) {
  }
  /* messageQueueFinished
   * called when a sending of the queue has finished
   * @return null
   */
  function messageQueueFinished() {
  }

  /* logEvent
   * @param string msg message to log
   * @return true when dealt with or false to pass on
   */
  function logEvent($msg = '') {
    return false;
  }

  /* logout
   * called on logout
   * @param none
   * @return null
   */

  function logout() {
    return '';
  }

  ############################################################
  # User

  function displayUsers( $user, $rowid, $list ) {
    # purpose: add columns for this plugin to WebblerListing
    # Currently used in users.php and members.php
    # 200710 Bas
    # (array) user, should have an id to connect to the database
    # (mixed) rowid, used to place data in the right row  of the WebblerListing
    # (WebblerListing) list, will hold the result

    return null; #@@idea: return false could mean don't display this user at all
  }

  function deleteUser($id) {
    # purpose: allow plugins to delete their data when deleting a user
    # 200711 Bas
    return true;
  }

  ############################################################
  # List

  function displayLists($list) {
    # purpose: return html snippet with plugin info for this list
    # Currently used in lists.php
    # 200711 Bas
    return null;
  }

  function displayEditList($list) {
    # purpose: return tablerows with list attributes for this list
    # Currently used in list.php
    # 200710 Bas
    return null;
  }

  function processEditList($id) {
    # purpose: process edit list page (usually save fields)
    # return false if failed
    # 200710 Bas
    return true;
  }

  function processSpamComplaint($email,$date) {
  }

  ############################################################
  # Subscribe page

  function displaySubscribePageEdit($subscribePageData) {
    # purpose: return tablerows with subscribepage options for this list
    # Currently used in spageedit.php
    # 200710 Bas
    return null;
  }

  /*
   * unsubscribePage
   * @param email string - email to unsubscribe
   * @return true when processed, which will then override the standard subscribe page
   */

  function unsubscribePage($email) {
    return false;
  }

  function processSubscribePageEdit($subscribePageID) {
    # purpose: process selected subscribepage options for this list
    # return false if failed
    # Currently used in spageedit.php
    # 200710 Bas
    return true;
  }

  function importContent() {
    # purpose: show content for this plugin on the import page
    return '';
  }

  ######################################
  # Static functions to manage the collection of plugins

  static function isEnabled($pluginName) {
    # see if a plugin is enabled, static method so it can be called even if existance of plugin is unknown.
    return array_key_exists($pluginName, $GLOBALS['plugins']) && $GLOBALS['plugins'][$pluginName]->enabled;
  }

};
?>


text:
The goal of this project is to build a compiler for the Pig Latin dataflow language on modern data analytics
platforms such as Apache Spark and Apache Flink. The project is not intented as a replacement or competitor of
the official Pig compiler for Hadoop or its extensions such as PigSpork. Instead we have the following goals:

 * We want to build a compiler from scratch that compiles natively to the Scala-based Spark/Flink API and avoids all the
   stuff needed for MapReduce/Hadoop.
 * Though, we are aiming at being compatible to the original Pig compiler we plan to integrate extensiblity features
   allowing to define and use user-defined operators (not only UDFs) and in this way being able to integrate extensions
   for graph processing or machine learning.
 * Finally, it is also a nice exercise in Scala programming resulting in a more compact code simplifying maintenance
   and extensibility.

### Installation ###

#### Clone & Update ####
Simply clone the git project.

#### Build ####
To build the project, in the project directory invoke
```
sbt package
```

This will build the (main) Pig compiler project as well as the shipped backends.
(i.e. `sparklib` and `flinklib`)

There are several test cases included which should be passed: unit
tests can be executed by `sbt test`, integration tests which compile
and execute Pig scripts on Spark or Flink are executed by `sbt it:test`.

Note that building the compiler requires the most recent Spark and Flink jars, but they will be downloaded by sbt automatically.

If you want to use the compiler with the frontend scripts (see below),
you have to build an assembly:

```
sbt assembly
```

### Usage ###

We provide a simple wrapper script for processing Pig scripts. Just call it with

```
piglet --master local[4] --backend spark your_script.pig
```
To run this script you have to specify the full path to the platform distribution jar in the environment
variable `SPARK_JAR` for Spark (e.g. `spark-assembly-1.5.2-hadoop2.6.0.jar`) and in `FLINK_JAR` (e.g. `flink-dist_2.11-1.0.0.jar`) for Flink.
For Flink you also have to provide the path to the `conf` directory in `FLINK_CONF_DIR`.

An example for Spark could look like the following:
```
export SPARK_JAR=/opt/spark-1.6.0/assembly/target/scala-2.11/spark-assembly-1.6.0-hadoop2.6.0.jar
piglet --master local[4] --backend spark your_script.pig
```
The equivalent for Flink would be:
```
export FLINK_JAR=/opt/flink-1.0.0/build-target/lib/flink-dist_2.11-1.0.0.jar
export FLINK_CONF_DIR=/opt/flink-1.0.0/build-target/conf
piglet --master local[4] --backend flink your_script.pig
```

Note, that both for Spark and Flink you need a version built for Scala 2.11 (see e.g.
[Spark doc](http://spark.apache.org/docs/latest/building-spark.html#building-for-scala-211) and [Flink doc](https://ci.apache.org/projects/flink/flink-docs-release-1.0/setup/building.html ))
and the same version used for building must also be used for execution. For Flink you have to run the start script found in the bin directory (e.g. `/opt/flink-1.0.0/build-target/bin/start-local.sh`) before executing scripts.

The following options are supported:
 * `--master m` specifies the master (local, yarn-client, yarn)
 * `--compile` compile and build jar, but do not execute
 * `--profiling`
 * `--outdir dir` specifies the output directory for the generated code
 * `--backend b` specifies the backend to execute the script. Currently, we support
    * `spark` (Apache Spark in batch mode)
    * `sparks`: Apache Spark Streaming
    * `flink`: Apache Flink in batch mode
    * `flinks`: Apache Flink Streaming
    * `mapreduce`: Apache Hadoop (by simply passing the script to the original Pig compiler)
 * `--backend_dir dir`
 * `--languages l` specifies the language dialects accepted by the parser: pig (standard Pig), sparql (pig + SPARQL extensions),
                  streaming (Pig + data stream extensions), cep (Pig + complex event processing extensions), all (all extensions)
 * `--params key=value, ...`
 * `--update-config`
 * `--show-plan` Print the resulting dataflow plan
 * `--show-stats` Show execution runtimes for (some) Piglet methods
 * `--keep` Keep generated files
 * `--sequential` If more than one input script is provided, do not merge them but execute them sequentially
 * `--log-level l`
 * `--backend-args key=value, ...`

In addition, you can start an interactive Pig shell similar to Grunt:

```
piglet --interactive --backend spark
```

where Pig statements can be entered at the prompt and are executed as soon as
a `DUMP` or `STORE` statement is entered. Furthermore, the schema can be printed using `DESCRIBE`.

#### Docker ####

Piglet can also be run as a [Docker](https://www.docker.com/) container. However, the image is not
yet on DockerHub, so it has to be built manually:
```
sbt clean package assembly
docker build -t dbis/piglet .
```

Currently, the Docker image supports the Spark backend only.

To start the container, run:
```
docker run -it --rm --name piglet dbis/piglet
```

This uses the container's entrypoint which runs piglet. The above command will print the help message.

You can start the interactive mode, using `-i` option and enter your script.

```
docker run -it --rm --name piglet dbis/piglet -b spark -i
```

Alternatively, you can add your existing files into the container by [mounting volumes](https://docs.docker.com/engine/userguide/dockervolumes/#mount-a-host-file-as-a-data-volume) and run the script in batch mode:
```
docker run -it --rm --name piglet -v /tmp/test.pig:/test.pig dbis/piglet -b spark /test.pig
```

As mentioned before, the container provides an entrypoint that executes piglet. In case you need a bash for that container,
you need to overwrite the entrypoint:
```
docker run -it --rm --name piglet --entrypoint /bin/bash dbis/piglet
```

### Configuration ###

To configure the program, we ship a configuration file. When starting the program for the first time, we will create our program home directory in your home directory and also copy the configuration file into this directory.
More specifically, we will create a folder `~/.piglet` (on *nix like systems) and copy the configuration file `application.conf` to this location.

If you update Piglet to a new version and the configuration file still exists from a previous version, a configuration exception might occur because we cannot find new configuration keys introduced by the new Piglet version in the existing config file. In such cases, you can start piglet with the `-u` (`--update-config`) option. This will force the override of your old configuration (make sure you have a backup if needed). Alternatively, you can simply remove the existing `~/.piglet/application.conf`. This will also trigger the copy routine.

We use the [Typesafe Config](https://github.com/typesafehub/config/) library.

### Backends ###

As stated before, we support various backends that are used to execute the scripts. You can add your own backend by creating a jar file that contains the necessary configuration information and
classes and adding it to the classpath (e.g. using the `BACKEND_DIR` variable).

More detailed information on how to create backends can be found in [backends.md](backends.md)

### Further Information ###

 * Details on the supported language features (statements, functions, etc.) are described [here](Language.md).
 * Documentation on [how to setup](Zeppelin.md) integration with [Zeppelin](https://zeppelin.incubator.apache.org/).
 * We use the [Scala testing framework](http://www.scalatest.org/) as well as the [scoverage tool](http://scoverage.org/)
   for test coverage. You can produce a coverage report by running `sbt clean coverage test`. The results can be found in
   `target/scala-2.11/scoverage-report/index.html`.


text:
title: AngularJS
---


text:
package com.komis_spring_hiber.dao;

import java.util.List;

import com.komis_spring_hiber.model.Sprzedawca;

public interface SprzedawcaDao {
	public void add(Sprzedawca sprzedawca);
	public void edit(Sprzedawca sprzedawca);
	public void delete(int idSprzedawca);
	public Sprzedawca getSprzedawca(int idSprzedawca);
	public List getAllSprzedawca();
}


text:
#if !GOOGLE_CUDA
#error This file must only be included when building with Cuda support
#endif

#ifndef TENSORFLOW_COMMON_RUNTIME_GPU_GPU_DEVICE_H_
#define TENSORFLOW_COMMON_RUNTIME_GPU_GPU_DEVICE_H_

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h"
#include "tensorflow/core/common_runtime/gpu_device_context.h"
#include "tensorflow/core/common_runtime/local_device.h"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/device_base.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow/core/platform/stream_executor.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/public/session_options.h"

namespace tensorflow {

class BaseGPUDevice : public LocalDevice {
 public:
  BaseGPUDevice(const SessionOptions& options, const string& name,
                Bytes memory_limit, const DeviceLocality& locality, int gpu_id,
                const string& physical_device_desc, Allocator* gpu_allocator,
                Allocator* cpu_allocator, bool sync_every_op,
                int32 max_streams);

  ~BaseGPUDevice() override;

  // Initialize the device and return the status of initialization.
  Status Init(const SessionOptions& options);

  // GPU devices require the Op Compute method to save a reference to
  // any temporary tensors that are allocated until the Op execution
  // completes.
  bool RequiresRecordingAccessedTensors() const override;

  void ConsumeListOfAccessedTensors(
      DeviceContext* device_context,
      const TensorReferenceVector& tensor_refs) override;

  Status FillContextMap(const Graph* graph,
                        DeviceContextMap* device_context_map);

  void Compute(OpKernel* op_kernel, OpKernelContext* context) override;

  Status Sync() override;

  void ComputeAsync(AsyncOpKernel* op_kernel, OpKernelContext* context,
                    AsyncOpKernel::DoneCallback done) override;

  Status MakeTensorFromProto(const TensorProto& tensor_proto,
                             const AllocatorAttributes alloc_attrs,
                             Tensor* tensor) override;

  // The caller owns the returned device.
  PerOpGpuDevice* MakeGpuDevice() override;

  void ReinitializeGpuDevice(OpKernelContext* context, PerOpGpuDevice* device,
                             DeviceContext* dc, Allocator* allocator) override;

  // Returns the id of this device within the native driver system; e.g., for
  // CUDA this is the ordinal of the GPU within the system.
  int gpu_id() const { return gpu_id_; }

  // The executor that provides control for the device; e.g., for CUDA this
  // corresponds to the cuda context.
  gpu::StreamExecutor* executor() const { return executor_; }

 protected:
  Allocator* gpu_allocator_;  // not owned
  Allocator* cpu_allocator_;  // not owned

  gpu::StreamExecutor* executor_;  // not owned

 private:
  struct StreamGroup {
    gpu::Stream* compute = nullptr;
    gpu::Stream* host_to_device = nullptr;
    gpu::Stream* device_to_host = nullptr;
    gpu::Stream* device_to_device = nullptr;
  };
  class StreamGroupFactory;

  gtl::InlinedVector<StreamGroup*, 4> streams_;
  gtl::InlinedVector<char*, 4> scratch_;
  std::vector<GPUDeviceContext*> device_contexts_;
  GpuDeviceInfo* gpu_device_info_ = nullptr;
  mutex trace_mu_;
  int gpu_id_ = -1;
  const bool sync_every_op_ = false;
  const int32 max_streams_;
  std::unique_ptr<EventMgr> em_;

  void ReinitializeDevice(OpKernelContext* context, PerOpGpuDevice* device,
                          int stream_id, Allocator* allocator);

  void ComputeHelper(OpKernel* op_kernel, OpKernelContext* context);
};

class BaseGPUDeviceFactory : public DeviceFactory {
 public:
  Status CreateDevices(const SessionOptions& options, const string& name_prefix,
                       std::vector<Device*>* devices) override;

 private:
  Status CreateGPUDevice(const SessionOptions& options, const string& name,
                         int gpu_id, BaseGPUDevice** out_device);

  virtual BaseGPUDevice* CreateGPUDevice(const SessionOptions& options,
                                         const string& name, Bytes memory_limit,
                                         const DeviceLocality& locality,
                                         int gpu_id,
                                         const string& physical_device_desc,
                                         Allocator* gpu_allocator,
                                         Allocator* cpu_allocator) = 0;

  // Returns into 'ids' the list of valid GPU ids, in the order that
  // they should map to logical gpu ids "/gpu:0", "/gpu:1", etc, based
  // upon 'visible_device_list', a comma-separated list of 'visible
  // gpu ids'.
  Status GetValidDeviceIds(const string& visible_device_list,
                           std::vector<int>* ids);

  // visible_gpu_initialized_[gpu_id] is true if visible GPU gpu_id
  // has been initialized by the process.
  std::unordered_map<int, bool> visible_gpu_initialized_;
};

}  // namespace tensorflow

#endif  // TENSORFLOW_COMMON_RUNTIME_GPU_GPU_DEVICE_H_


text:
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

namespace IronFoundry.Models
{
    public interface IMergeable<T>
    {
        void Merge(T obj);
    }
}


text:
package boundary;

import controller.PlayerRemoveCtrl;
import controller.PlayerRestartLevelCtrl;
import controller.PlayerScrambleCtrl;
import controller.PlayerSwapCtrl;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.PlayerModel;

/**
 * The view when a player loads up a level.
 *
 * @author Bailey Sheridan, Eli Skeggs, and Maurizio Vitale
 */
public class PlayerLevelView extends JPanel {
  PlayerApplication app;
  PlayerModel model;
  public PlayerBoardView boardView;

  JLabel lblScoreNum;
  JLabel lblCounterNum;
  JLabel lblStar[] = new JLabel[3];

  public JButton btnRemove;
  public JButton btnSwap;
  public JButton btnScramble;

  public JButton btnRestart;
  public JButton btnMainMenu;

  /**
   * Create a level view for the player application.
   *
   * The quit listener is invoked when the quit button is clicked, indicating
   * either that the player is done playing the level, or the builder is done
   * previewing the level.
   *
   * The PlayerApplication and PlayerModel are used to create the constituent
   * views and controllers.
   *
   * @param onQuit
   * @param app
   * @param model
   */
  public PlayerLevelView(ActionListener onQuit, PlayerApplication app,
      PlayerModel model) {
    this.app = app;
    this.model = model;

    setMinimumSize(new Dimension(600, 480));
    setPreferredSize(new Dimension(600, 480));
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    //Panel Left (Game Board)

    JPanel panelLeft = new JPanel();
    panelLeft.setAlignmentY(0);
    add(panelLeft);
    panelLeft.setLayout(new BoxLayout(panelLeft, BoxLayout.X_AXIS));
    boardView = new PlayerBoardView(app, model);
    boardView.setAlignmentY(0);
    panelLeft.add(boardView);

    //Panel Controls

    JPanel panelControls = new JPanel();
    panelControls.setAlignmentY(0);
    panelLeft.add(panelControls);
    panelControls.setLayout(new BoxLayout(panelControls, BoxLayout.Y_AXIS));

    btnSwap = new JButton(new ImageIcon(app.loader.getResource("swap.png").getScaledInstance(64, 64, 0)));
    btnSwap.addActionListener(new PlayerSwapCtrl(app, model));
    panelControls.add(btnSwap);

    btnRemove = new JButton(new ImageIcon(app.loader.getResource("remove.png").getScaledInstance(64, 64, 0)));
    btnRemove.addActionListener(new PlayerRemoveCtrl(app, model));
    panelControls.add(btnRemove);

    btnScramble = new JButton(new ImageIcon(app.loader.getResource("scramble.png").getScaledInstance(64, 64, 0)));
    btnScramble.addActionListener(new PlayerScrambleCtrl(app, model));
    panelControls.add(btnScramble);

    //Panel Right

    JPanel panelRight = new JPanel();
    panelRight.setAlignmentY(0);
    add(panelRight);
    panelRight.setLayout(new BoxLayout(panelRight, BoxLayout.Y_AXIS));

    //Panel Navigation

    JPanel panelNavigation = new JPanel();
    panelNavigation.setAlignmentX(0);
    panelRight.add(panelNavigation);
    panelNavigation.setLayout(new BoxLayout(panelNavigation, BoxLayout.X_AXIS));

    btnRestart = new JButton("Restart");
    btnRestart.addActionListener(new PlayerRestartLevelCtrl(app, model));
    panelNavigation.add(btnRestart);

    btnMainMenu = new JButton("Quit");
    btnMainMenu.addActionListener(onQuit);
    panelNavigation.add(btnMainMenu);

    //Panel Info

    JPanel panelInfo = new JPanel();
    panelInfo.setAlignmentX(0);

    panelRight.add(panelInfo);
    panelInfo.setLayout(new BoxLayout(panelInfo,BoxLayout.Y_AXIS));

    JLabel lblScore = new JLabel("Score");
    panelInfo.add(lblScore);

    lblScoreNum = new JLabel("12345");
    panelInfo.add(lblScoreNum);

    JLabel lblCounter = new JLabel("Moves Left");
    panelInfo.add(lblCounter);

    lblCounterNum = new JLabel("20");
    panelInfo.add(lblCounterNum);

    JPanel panelStars = new JPanel();

    panelStars.setLayout(new GridLayout(0,3,0,0));

    for (int i = 0; i < 3; i++) {
  	  lblStar[i] = new JLabel(new ImageIcon(app.loader.getResource("stargameempty.png")));
  	  panelStars.add(lblStar[i]);
    }

    panelStars.setMaximumSize(new Dimension(100,32));
    panelStars.setAlignmentX(0);
    panelInfo.add(panelStars);

    update();
    repaint();
  }

  public void update() {
    lblScoreNum.setText(Integer.toString(model.score));
    lblCounterNum.setText(Integer.toString(model.counter));
    for (int i = 0; i < 3; i++) {
    	if (model.score >= model.level.rules.scoreThresholds[i]) {
    	  lblStar[i].setIcon(new ImageIcon(app.loader.getResource("stargame.png")));;
    	}
      }
    this.validate();
    this.repaint();
  }
}


text:
define("dijit/form/Slider", ["dojo", "dijit", "dijit/form/HorizontalSlider", "dijit/form/VerticalSlider", "dijit/form/HorizontalRule", "dijit/form/VerticalRule", "dijit/form/HorizontalRuleLabels", "dijit/form/VerticalRuleLabels"], function(dojo, dijit) {

dojo.deprecated("Call require() for HorizontalSlider / VerticalRule, explicitly rather than 'dijit.form.Slider' itself", "", "2.0");

// For back-compat, remove for 2.0

return dijit.form.Slider;
});


text:
require 'rubygems' # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
workspace_sid = 'WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
task_sid = 'WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

client = Twilio::REST::TaskRouterClient.new account_sid,
                                            auth_token,
                                            workspace_sid

task = client.workspace.tasks.get(task_sid)
task.delete


text:
#import "NSObject.h"

@class NSMutableData, NSString;

@interface MFDbJournal : NSObject
{
    NSString *_path;
    struct _opaque_pthread_mutex_t {
        long long __sig;
        char __opaque[56];
    } _lock;
    int _fd;
    NSMutableData *_buffer;
}

- (_Bool)mergeWithDatabase:(struct sqlite3 *)arg1;
- (_Bool)_processJournalFile:(id)arg1 db:(struct sqlite3 *)arg2;
- (void)clear;
- (_Bool)flush;
- (_Bool)append:(const char *)arg1;
- (void)_resetBuffer;
- (void)dealloc;
- (id)initWithPath:(id)arg1;

@end


text:
package org.wso2.carbon.bpmn.rest.model.runtime;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;

@XmlRootElement(name = "TaskRequest")
@XmlAccessorType(XmlAccessType.FIELD)
public class TaskRequest {

    private String owner;
    private String assignee;
    private String delegationState;
    private String name;
    private String description;
    private Date dueDate;
    private int priority;
    private String parentTaskId;
    private String category;
    private String tenantId;
    private String formKey;

    private boolean ownerSet = false;
    private boolean assigneeSet = false;
    private boolean delegationStateSet = false;
    private boolean nameSet = false;
    private boolean descriptionSet = false;
    private boolean duedateSet = false;
    private boolean prioritySet = false;
    private boolean parentTaskIdSet = false;
    private boolean categorySet = false;
    private boolean tenantIdSet = false;
    private boolean formKeySet = false;

    public String getOwner() {
        return owner;
    }
    public void setOwner(String owner) {
        this.owner = owner;
        ownerSet = true;
    }
    public String getAssignee() {
        return assignee;
    }
    public void setAssignee(String assignee) {
        this.assignee = assignee;
        assigneeSet = true;
    }
    public String getDelegationState() {
        return delegationState;
    }
    public void setDelegationState(String delegationState) {
        this.delegationState = delegationState;
        delegationStateSet = true;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
        nameSet = true;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
        descriptionSet = true;
    }
    public Date getDueDate() {
        return dueDate;
    }
    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
        duedateSet = true;
    }
    public int getPriority() {
        return priority;
    }
    public void setPriority(int priority) {
        this.priority = priority;
        prioritySet = true;
    }
    public String getParentTaskId() {
        return parentTaskId;
    }
    public void setParentTaskId(String parentTaskId) {
        this.parentTaskId = parentTaskId;
        parentTaskIdSet = true;
    }
    public void setCategory(String category) {
        this.category = category;
        categorySet = true;
    }
    public String getCategory() {
        return category;
    }
    public String getTenantId() {
        return tenantId;
    }
    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
        tenantIdSet = true;
    }
    public String getFormKey() {
        return formKey;
    }
    public void setFormKey(String formKey) {
        this.formKey = formKey;
        formKeySet = true;
    }

    public boolean isOwnerSet() {
        return ownerSet;
    }
    public boolean isAssigneeSet() {
        return assigneeSet;
    }
    public boolean isDelegationStateSet() {
        return delegationStateSet;
    }
    public boolean isNameSet() {
        return nameSet;
    }
    public boolean isDescriptionSet() {
        return descriptionSet;
    }
    public boolean isDuedateSet() {
        return duedateSet;
    }
    public boolean isPrioritySet() {
        return prioritySet;
    }
    public boolean isParentTaskIdSet() {
        return parentTaskIdSet;
    }
    public boolean isCategorySet() {
        return categorySet;
    }
    public boolean isTenantIdSet() {
        return tenantIdSet;
    }
    public boolean isFormKeySet() {
        return formKeySet;
    }
}


text:
namespace Content.Server.NPC.Components;

/// <summary>
/// Added to NPCs whenever they're in melee combat so they can be handled by the dedicated system.
/// </summary>
[RegisterComponent]
public sealed class NPCMeleeCombatComponent : Component
{
    /// <summary>
    /// Weapon we're using to attack the target. Can also be ourselves.
    /// </summary>
    [ViewVariables] public EntityUid Weapon;

    [ViewVariables]
    public EntityUid Target;

    [ViewVariables]
    public CombatStatus Status = CombatStatus.Normal;
}

public enum CombatStatus : byte
{
    /// <summary>
    /// The target isn't in LOS anymore.
    /// </summary>
    NotInSight,

    /// <summary>
    /// Due to some generic reason we are unable to attack the target.
    /// </summary>
    Unspecified,

    /// <summary>
    /// Set if we can't reach the target for whatever reason.
    /// </summary>
    TargetUnreachable,

    /// <summary>
    /// If the target is outside of our melee range.
    /// </summary>
    TargetOutOfRange,

    /// <summary>
    /// Set if the weapon we were assigned is no longer valid.
    /// </summary>
    NoWeapon,

    /// <summary>
    /// No dramas.
    /// </summary>
    Normal,
}


text:
package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.Objects;
import javax.swing.*;

public final class MainPanel extends JPanel {
    private final JDialog dialog = new JDialog();
    private final PopupMenu popup = new PopupMenu();
    private final Timer animator;
    private final transient Image[] imglist = new Image[4];
    private final transient SystemTray tray;
    private final transient TrayIcon icon;

    public MainPanel() {
        super();
        if (!SystemTray.isSupported()) {
            throw new UnsupportedOperationException("SystemTray is not supported");
        }

        setPreferredSize(new Dimension(320, 240));

        imglist[0] = new ImageIcon(getClass().getResource("16x16.png")).getImage();
        imglist[2] = imglist[0];
        imglist[1] = new ImageIcon(getClass().getResource("16x16l.png")).getImage();
        imglist[3] = new ImageIcon(getClass().getResource("16x16r.png")).getImage();

        dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        dialog.setSize(new Dimension(100, 100));
        dialog.setLocationRelativeTo(null);
        dialog.setTitle("xxxxxxxxx");

        tray = SystemTray.getSystemTray();
        //TEST: icon   = new TrayIcon(new ImageIcon(getClass().getResource("anime.gif")).getImage(), "TRAY", popup);
        icon = new TrayIcon(imglist[0], "TRAY", popup);
        animator = new Timer(100, new ActionListener() {
            private int idx;
            @Override public void actionPerformed(ActionEvent e) {
                icon.setImage(imglist[idx]);
                idx = (idx + 1) % imglist.length;
            }
        });
        initTrayPopupMenu(popup);
        try {
            tray.add(icon);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
    private void initTrayPopupMenu(PopupMenu popup) {
        MenuItem item1 = new MenuItem("Open:Frame");
        item1.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                Window w = SwingUtilities.getWindowAncestor(getRootPane());
                if (Objects.nonNull(w)) {
                    w.setVisible(true);
                }
            }
        });
        MenuItem item2 = new MenuItem("Open:Dialog");
        item2.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                dialog.setVisible(true);
            }
        });

        MenuItem item3 = new MenuItem("Animation:Start");
        item3.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                animator.start();
            }
        });
        MenuItem item4 = new MenuItem("Animation:Stop");
        item4.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                animator.stop();
                icon.setImage(imglist[0]);
            }
        });

        MenuItem item5 = new MenuItem("Exit");
        item5.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                tray.remove(icon);
                animator.stop();
                dialog.dispose();
                Window w = SwingUtilities.getWindowAncestor(getRootPane());
                if (w instanceof JFrame) {
                    JFrame frame = (JFrame) w;
                    //frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                    frame.dispose();
                }
            }
        });
        popup.add(item1);
        popup.add(item2);
        popup.addSeparator();
        popup.add(item3);
        popup.add(item4);
        popup.addSeparator();
        popup.add(item5);

    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        //frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}


text:
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "String#sum" do
  it "returns a basic n-bit checksum of the characters in self" do
    "ruby".sum.should == 450
    "ruby".sum(8).should == 194
    "rubinius".sum(23).should == 881
  end

  it "tries to convert n to an integer using to_int" do
    obj = mock('8')
    obj.should_receive(:to_int).and_return(8)

    "hello".sum(obj).should == "hello".sum(8)
  end

  it "returns sum of the bytes in self if n less or equal to zero" do
    "xyz".sum(0).should == 363
    "xyz".sum(-10).should == 363
  end
end