text:
#include <QtCore/QBuffer>
#include <QtCore/QStringList>
#include <QtXmlPatterns/QXmlFormatter>

#include "qacceltreeresourceloader_p.h"
#include "qcommonvalues_p.h"
#include "qxmlresultitems.h"
#include "qxmlresultitems_p.h"
#include "qxmlserializer.h"
#include "qxpathhelper_p.h"

#include "qxmlquery.h"
#include "qxmlquery_p.h"

QT_BEGIN_NAMESPACE

/*!
  \class QXmlQuery

  \brief The QXmlQuery class performs XQueries on XML data, or on non-XML data modeled to look like XML.

  \reentrant
  \since 4.4
  \ingroup xml-tools

  The QXmlQuery class compiles and executes queries written in the
  \l {http://www.w3.org/TR/xquery/}{XQuery language}. QXmlQuery is
  typically used to query XML data, but it can also query non-XML
  data that has been modeled to look like XML.

  Using QXmlQuery to query XML data, as in the snippet below, is
  simple because it can use the built-in \l {QAbstractXmlNodeModel}
  {XML data model} as its delegate to the underlying query engine for
  traversing the data. The built-in data model is specified in \l
  {http://www.w3.org/TR/xpath-datamodel/} {XQuery 1.0 and XPath 2.0
  Data Model}.

  \snippet doc/src/snippets/code/src_xmlpatterns_api_qabstractxmlreceiver.cpp 0

  The example uses QXmlQuery to match the first paragraph of an XML
  document and then \l {QXmlSerializer} {output the result} to a
  device as XML.

  Using QXmlQuery to query \e {non-XML} data requires writing a
  subclass of QAbstractXmlNodeModel to use as a replacement for the
  built-in XML data model. The custom data model will be able to
  traverse the non-XML data as required by the QAbstractXmlNodeModel
  interface. An instance of this custom data model then becomes the
  delegate used by the query engine to traverse the non-XML data. For
  an example of how to use QXmlQuery to query non-XML data, see the
  documentation for QAbstractXmlNodeModel.

  \section1 Running XQueries

  To run a query set up with QXmlQuery, call one of the evaluation
  functions.

  \list

  \o evaluateTo(QAbstractXmlReceiver *) is called with a pointer to an
  XML \l {QAbstractXmlReceiver} {receiver}, which receives the query
  results as a sequence of callbacks. The receiver callback class is
  like the callback class used for translating the output of a SAX
  parser. QXmlSerializer, for example, is a receiver callback class
  for translating the sequence of callbacks for output as unformatted
  XML text.

  \endlist

  \list

  \o evaluateTo(QXmlResultItems *) is called with a pointer to an
  iterator for an empty sequence of query \l {QXmlResultItems} {result
  items}.  The Java-like iterator allows the query results to be
  accessed sequentially.

  \endlist

  \list

  \o evaluateTo(QStringList *) is like evaluateTo(QXmlResultItems *),
  but the query must evaluate to a sequence of strings.

  \endlist

  \section1 Running XPath Expressions

  The XPath language is a subset of the XQuery language, so
  running an XPath expression is the same as running an XQuery
  query. Pass the XPath expression to QXmlQuery using setQuery().

  \section1 Running XSLT stylesheets

  Running an XSLT stylesheet is like running an XQuery, except that
  when you construct your QXmlQuery, you must pass QXmlQuery::XSLT20
  to tell QXmlQuery to interpret whatever it gets from setQuery() as
  an XSLT stylesheet instead of as an XQuery. You must also set the
  input document by calling setFocus().

  \snippet doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp 7

  \note Currently, setFocus() must be called \e before setQuery() when
  using XSLT.

  Another way to run an XSLT stylesheet is to use the \c xmlpatterns
  command line utility.

  \code
  xmlpatterns myStylesheet.xsl myInput.xml
  \endcode

  \note For the current release, XSLT support should be considered
  experimental. See section \l{XQuery#XSLT 2.0} {XSLT conformance} for
  details.

  Stylesheet parameters are bound using bindVariable().

  \section1 Binding A Query To A Starting Node

  When a query is run on XML data, as in the snippet above, the
  \c{doc()} function returns the node in the built-in data model where
  the query evaluation will begin. But when a query is run on a custom
  node model containing non-XML data, one of the bindVariable()
  functions must be called to bind a variable name to a starting node
  in the custom model.  A $variable reference is used in the XQuery
  text to access the starting node in the custom model. It is not
  necessary to declare the variable name external in the query. See
  the example in the documentation for QAbstractXmlNodeModel.

  \section1 Reentrancy and Thread-Safety

  QXmlQuery is reentrant but not thread-safe. It is safe to use the
  QxmlQuery copy constructor to create a copy of a query and run the
  same query multiple times. Behind the scenes, QXmlQuery will reuse
  resources such as opened files and compiled queries to the extent
  possible. But it is not safe to use the same instance of QXmlQuery
  in multiple threads.

  \section1 Error Handling

  Errors can occur during query evaluation. Examples include type
  errors and file loading errors. When an error occurs:

  \list

  \o The error message is sent to the messageHandler().

  \o QXmlResultItems::hasError() will return \c{true}, or
  evaluateTo() will return \c{false};

  \o The results of the evaluation are undefined.

  \endlist

  \section1 Resource Management

  When a query runs, it parses documents, allocating internal data
  structures to hold them, and it may load other resources over the
  network. It reuses these allocated resources when possible, to
  avoid having to reload and reparse them.

  When setQuery() is called, the query text is compiled into an
  internal data structure and optimized. The optimized form can
  then be reused for multiple evaluations of the query. Since the
  compile-and-optimize process can be expensive, repeating it for
  the same query should be avoided by using a separate instance of
  QXmlQuery for each query text.

  Once a document has been parsed, its internal representation is
  maintained in the QXmlQuery instance and shared among multiple
  QXmlQuery instances.

  An instance of QCoreApplication must exist before QXmlQuery can be
  used.

  \section1 Event Handling

  When QXmlQuery accesses resources (e.g., calling \c fn:doc() to load a file,
  or accessing a device via a bound variable), the event loop is used, which
  means events will be processed. To avoid processing events when QXmlQuery
  accesses resources, create your QXmlQuery instance in a separate thread.
 */

/*!
 \enum QXmlQuery::QueryLanguage
 \since 4.5

 Specifies whether you want QXmlQuery to interpret the input to
 setQuery() as an XQuery or as an XSLT stylesheet.

 \value XQuery10 XQuery 1.0.
 \value XSLT20 XSLT 2.0
 \omitvalue XmlSchema11IdentityConstraintSelector The selector, the restricted
            XPath pattern found in W3C XML Schema 1.1 for uniqueness
            contraints. Apart from restricting the syntax, the type check stage
            for the expression assumes a sequence of nodes to be the focus.
 \omitvalue XmlSchema11IdentityConstraintField The field, the restricted
            XPath pattern found in W3C XML Schema 1.1 for uniqueness
            contraints. Apart from restricting the syntax, the type check stage
            for the expression assumes a sequence of nodes to be the focus.
 \omitvalue XPath20 Signifies XPath 2.0. Has no effect in the public API, it's
            used internally. As With XmlSchema11IdentityConstraintSelector and
            XmlSchema11IdentityConstraintField, the type check stage
            for the expression assumes a sequence of nodes to be the focus.

 \sa setQuery()
 */

// ### Qt5: Merge constructor overloads
/*!
  Constructs an invalid, empty query that cannot be used until
  setQuery() is called.

  \note This constructor must not be used if you intend to use
  this QXmlQuery to process XSL-T stylesheets. The other constructor
  must be used in that case.
 */
QXmlQuery::QXmlQuery() : d(new QXmlQueryPrivate())
{
}

/*!
  Constructs a QXmlQuery that is a copy of \a other. The new
  instance will share resources with the existing query
  to the extent possible.
 */
QXmlQuery::QXmlQuery(const QXmlQuery &other) : d(new QXmlQueryPrivate(*other.d))
{
    /* First we have invoked QXmlQueryPrivate's synthesized copy constructor.
     * Keep this section in sync with QXmlQuery::operator=(). */
    d->detach();
}

/*!
  Constructs a query that will use \a np as its name pool. The query
  cannot be evaluated until setQuery() has been called.
 */
QXmlQuery::QXmlQuery(const QXmlNamePool &np) : d(new QXmlQueryPrivate(np))
{
}

/*!

  Constructs a query that will be used to run Xqueries or XSL-T
  stylesheets, depending on the value of \a queryLanguage. It will use
  \a np as its name pool.

  \note If your QXmlQuery will process XSL-T stylesheets, this
  constructor must be used. The default constructor can only
  create instances of QXmlQuery for running XQueries.

  \note The XSL-T support in this release is considered experimental.
  See the \l{XQuery#XSLT 2.0} {XSLT conformance} for details.

 \since 4.5
 \sa queryLanguage()
 */
QXmlQuery::QXmlQuery(QueryLanguage queryLanguage,
                     const QXmlNamePool &np) : d(new QXmlQueryPrivate(np))
{
    d->queryLanguage = queryLanguage;
}

/*!
  Destroys this QXmlQuery.
 */
QXmlQuery::~QXmlQuery()
{
    delete d;
}

/*!
  Assigns \a other to this QXmlQuery instance.
 */
QXmlQuery &QXmlQuery::operator=(const QXmlQuery &other)
{
    /* Keep this section in sync with QXmlQuery::QXmlQuery(const QXmlQuery &).
     */
    if(d != other.d)
    {
        *d = *other.d;
        d->detach();
    }

    return *this;
}

/*!
  Changes the \l {QAbstractMessageHandler}{message handler} for this
  QXmlQuery to \a aMessageHandler. The query sends all compile and
  runtime messages to this message handler. QXmlQuery does not take
  ownership of \a aMessageHandler.

  Normally, the default message handler is sufficient. It writes
  compile and runtime messages to \e stderr. The default message
  handler includes color codes if \e stderr can render colors.

  Note that changing the message handler after the query has been
  compiled has no effect, i.e. the query uses the same message handler
  at runtime that it uses at compile time.

  When QXmlQuery calls QAbstractMessageHandler::message(),
  the arguments are as follows:

  \table
  \header
    \o message() argument
    \o Semantics
  \row
    \o QtMsgType type
    \o Only QtWarningMsg and QtFatalMsg are used. The former
       identifies a compile or runtime warning, while the
       latter identifies a dynamic or static error.
  \row
    \o const QString & description
    \o An XHTML document which is the actual message. It is translated
       into the current language.
  \row
    \o const QUrl &identifier
    \o Identifies the error with a URI, where the fragment is
       the error code, and the rest of the URI is the error namespace.
  \row
    \o const QSourceLocation & sourceLocation
    \o Identifies where the error occurred.
  \endtable

 */
void QXmlQuery::setMessageHandler(QAbstractMessageHandler *aMessageHandler)
{
    d->messageHandler = aMessageHandler;
}

/*!
    Returns the message handler that handles compile and runtime
    messages for this QXmlQuery.
 */
QAbstractMessageHandler *QXmlQuery::messageHandler() const
{
    return d->messageHandler;
}

/*!
  Sets this QXmlQuery to an XQuery read from the \a sourceCode
  device.  The device must have been opened with at least
  QIODevice::ReadOnly.

  \a documentURI represents the query obtained from the \a sourceCode
  device. It is the base URI of the static context, as defined in the
  \l {http://www.w3.org/TR/xquery/}{XQuery language}. It is used
  internally to resolve relative URIs that appear in the query, and
  for message reporting. \a documentURI can be empty. If it is empty,
  the \l{QCoreApplication::applicationFilePath()} {application file
  path} is used. If it is not empty, it may be either relative or
  absolute. If it is relative, it is resolved itself against the
  \l {QCoreApplication::applicationFilePath()} {application file
  path} before it is used. If \a documentURI is neither a valid URI
  nor empty, the result is undefined.

  If the query contains a static error (e.g. syntax error), an error
  message is sent to the messageHandler(), and isValid() will return
  \e false.

  Variables must be bound before setQuery() is called.

  The encoding of the XQuery in \a sourceCode is detected internally
  using the rules for setting and detecting encoding of XQuery files,
  which are explained in the \l {http://www.w3.org/TR/xquery/}
  {XQuery language}.

  If \a sourceCode is \c null or not readable, or if \a documentURI is not
  a valid URI, behavior is undefined.
  \sa isValid()
 */
void QXmlQuery::setQuery(QIODevice *sourceCode, const QUrl &documentURI)
{
    if(!sourceCode)
    {
        qWarning("A null QIODevice pointer cannot be passed.");
        return;
    }

    if(!sourceCode->isReadable())
    {
        qWarning("The device must be readable.");
        return;
    }

    d->queryURI = QPatternist::XPathHelper::normalizeQueryURI(documentURI);
    d->expression(sourceCode);
}

/*!
  \overload
  The behavior and requirements of this function are the same as for
  setQuery(QIODevice*, const QUrl&), after the XQuery has been read
  from the IO device into a string. Because \a sourceCode is already
  a Unicode string, detection of its encoding is unnecessary.
*/
void QXmlQuery::setQuery(const QString &sourceCode, const QUrl &documentURI)
{
    Q_ASSERT_X(documentURI.isEmpty() || documentURI.isValid(), Q_FUNC_INFO,
               "The document URI must be valid.");

    QByteArray query(sourceCode.toUtf8());
    QBuffer buffer(&query);
    buffer.open(QIODevice::ReadOnly);

    setQuery(&buffer, documentURI);
}

/*!
  Sets this QXmlQuery to the XQuery read from the \a queryURI.  Use
  isValid() after calling this function. If an error occurred reading
  \a queryURI, e.g., the query does not exist, cannot be read, or is
  invalid, isValid() will return \e false.

  The supported URI schemes are the same as those in the XQuery
  function \c{fn:doc}, except that queryURI can be the object of
  a variable binding.

  \a baseURI is the Base URI of the static context, as defined in the
  \l {http://www.w3.org/TR/xquery/}{XQuery language}. It is used
  internally to resolve relative URIs that appear in the query, and
  for message reporting. If \a baseURI is empty, \a queryURI is used.
  Otherwise, \a baseURI is used, and it is resolved against the \l
  {QCoreApplication::applicationFilePath()} {application file path} if
  it is relative.

  If \a queryURI is empty or invalid, or if \a baseURI is invalid,
  the behavior of this function is undefined.
 */
void QXmlQuery::setQuery(const QUrl &queryURI, const QUrl &baseURI)
{
    Q_ASSERT_X(queryURI.isValid(), Q_FUNC_INFO, "The passed URI must be valid.");

    const QUrl canonicalURI(QPatternist::XPathHelper::normalizeQueryURI(queryURI));
    Q_ASSERT(canonicalURI.isValid());
    Q_ASSERT(!canonicalURI.isRelative());
    Q_ASSERT(baseURI.isValid() || baseURI.isEmpty());

    d->queryURI = QPatternist::XPathHelper::normalizeQueryURI(baseURI.isEmpty() ? queryURI : baseURI);

    QPatternist::AutoPtr<QIODevice> result;

    try
    {
        result.reset(QPatternist::AccelTreeResourceLoader::load(canonicalURI, d->m_networkAccessDelegator,
                                                                d->staticContext()));
    }
    catch(const QPatternist::Exception)
    {
        /* We do nothing, result will be 0. */
    }

    if(result)
    {
        setQuery(result.data(), d->queryURI);
        result->close();
    }
    else
        d->recompileRequired();
}

/*!
  Binds the variable \a name to the \a value so that $\a name can be
  used from within the query to refer to the \a value.

  \a name must not be \e null. \a {name}.isNull() must return false.
  If \a name has already been bound by a previous bindVariable() call,
  its previous binding will be overridden.

  If \a {value} is null so that \a {value}.isNull() returns true, and
  \a {name} already has a binding, the effect is to remove the
  existing binding for \a {name}.

  To bind a value of type QString or QUrl, wrap the value in a
  QVariant such that QXmlItem's QVariant constructor is called.

  All strings processed by the query must be valid XQuery strings,
  which means they must contain only XML 1.0 characters. However,
  this requirement is not checked. If the query processes an invalid
  string, the behavior is undefined.

  \sa QVariant::isValid(), {QtXDM}{How QVariant maps to XQuery's Data Model},
   QXmlItem::isNull()
 */
void QXmlQuery::bindVariable(const QXmlName &name, const QXmlItem &value)
{
    if(name.isNull())
    {
        qWarning("The variable name cannot be null.");
        return;
    }

    const QPatternist::VariableLoader::Ptr vl(d->variableLoader());
    const QVariant variant(QVariant::fromValue(value));

    /* If the type of the variable changed(as opposed to only the value),
     * we will have to recompile. */
    if(vl->invalidationRequired(name, variant) || value.isNull())
        d->recompileRequired();

    vl->addBinding(name, variant);
}

/*!
  \overload

  This function constructs a QXmlName from \a localName using the
  query's \l {QXmlNamePool} {namespace}. The function then behaves as
  the overloaded function. It is equivalent to the following snippet.

  \snippet doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp 0
 */
void QXmlQuery::bindVariable(const QString &localName, const QXmlItem &value)
{
    bindVariable(QXmlName(d->namePool, localName), value);
}

/*!
  Binds the variable \a name to the \a device so that $\a name can be
  used from within the query to refer to the \a device. The QIODevice
  \a device is exposed to the query as a URI of type \c{xs:anyURI},
  which can be passed to the \c{fn:doc()} function to be read. E.g.,
  this function can be used to pass an XML document in memory to
  \c{fn:doc}.

  \snippet doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp 1

  The caller must ensure that \a device has been opened with at least
  QIODevice::ReadOnly prior to this binding. Otherwise, behavior is
  undefined.

  If the query will access an XML document contained in a QString, use
  a QBuffer as shown in the following snippet. Suppose \e myQString
  contains \c{<document>content</document>}

  \snippet doc/src/snippets/qxmlquery/bindingExample.cpp 0

  \a name must not be \e null. \a {name}.isNull() must return false.
  If \a name has already been bound, its previous binding will be
  overridden. The URI that \a name evaluates to is arbitrary and may
  change.

  If the type of the variable binding changes (e.g., if a previous
  binding by the same name was a QVariant, or if there was no previous
  binding), isValid() will return \c{false}, and recompilation of the
  query text is required. To recompile the query, call setQuery(). For
  this reason, bindVariable() should be called before setQuery(), if
  possible.

  \note \a device must not be deleted while this QXmlQuery exists.
*/
void QXmlQuery::bindVariable(const QXmlName &name, QIODevice *device)
{
    if(device && !device->isReadable())
    {
        qWarning("A null, or readable QIODevice must be passed.");
        return;
    }

    if(name.isNull())
    {
        qWarning("The variable name cannot be null.");
        return;
    }

    const QPatternist::VariableLoader::Ptr vl(d->variableLoader());

    if(device)
    {
        const QVariant variant(QVariant::fromValue(device));

        if(vl->invalidationRequired(name, variant))
            d->recompileRequired();

        vl->addBinding(name, variant);

        /* We need to tell the resource loader to discard its document, because
         * the underlying QIODevice has changed, but the variable name is the
         * same which means that the URI is the same, and hence the resource
         * loader will return the document for the old QIODevice.
         */
        d->resourceLoader()->clear(QUrl(QLatin1String("tag:trolltech.com,2007:QtXmlPatterns:QIODeviceVariable:") + d->namePool.d->stringForLocalName(name.localName())));
    }
    else
    {
        vl->removeBinding(name);
        d->recompileRequired();
    }
}

/*!
  \overload

  If \a localName is a valid \l {QXmlName::isNCName()} {NCName}, this
  function is equivalent to the following snippet.

  \snippet doc/src/snippets/code/src_xmlpatterns_api_qxmlquery.cpp 2

  A QXmlName is constructed from \a localName, and is passed
  to the appropriate overload along with \a device.

  \sa QXmlName::isNCName()
 */
void QXmlQuery::bindVariable(const QString &localName, QIODevice *device)
{
    bindVariable(QXmlName(d->namePool, localName), device);
}

/*!
  Evaluates this query and sends the result as a sequence of callbacks
  to the \l {QAbstractXmlReceiver} {receiver} \a callback. QXmlQuery
  does not take ownership of \a callback.

  If an error occurs during the evaluation, error messages are sent to
  messageHandler() and \c false is returned.

  If this query \l {isValid()} {is invalid}, \c{false} is returned
  and the behavior is undefined. If \a callback is null,
  behavior is undefined.

  \sa QAbstractXmlReceiver, isValid()
 */
bool QXmlQuery::evaluateTo(QAbstractXmlReceiver *callback) const
{
    if(!callback)
    {
        qWarning("A non-null callback must be passed.");
        return false;
    }

    if(isValid())
    {
        try
        {
            /*
             * This order is significant. expression() might cause
             * query recompilation, and as part of that it recreates
             * the static context. However, if we create the dynamic
             * context before the query recompilation has been
             * triggered, it will use the old static context, and
             * hence old source locations.
             */
            const QPatternist::Expression::Ptr expr(d->expression());
            const QPatternist::DynamicContext::Ptr dynContext(d->dynamicContext(callback));
            callback->startOfSequence();
            expr->evaluateToSequenceReceiver(dynContext);
            callback->endOfSequence();
            return true;
        }
        catch(const QPatternist::Exception)
        {
            return false;
        }
    }
    else
        return false;
}

/*!
  Attempts to evaluate the query and returns the results in the
  \a target \l {QStringList} {string list}.

  If the query \l {isValid()} {is valid} and the evaluation succeeds,
  true is returned. Otherwise, false is returned and the contents of
  \a target are undefined.

  The query must evaluate to a sequence of \c{xs:string} values. If
  the query does not evaluate to a sequence of strings, the values can
  often be converted by adding a call to \c{string()} at the end of
  the XQuery.

  If \a target is null, the behavior is undefined.
 */
bool QXmlQuery::evaluateTo(QStringList *target) const
{
    if(!target)
    {
        qWarning("A non-null callback must be passed.");
        return false;
    }

    if(isValid())
    {
        try
        {
            /*
             * This order is significant. expression() might cause
             * query recompilation, and as part of that it recreates
             * the static context. However, if we create the dynamic
             * context before the query recompilation has been
             * triggered, it will use the old static context, and
             * hence old source locations.
             */
            const QPatternist::Expression::Ptr expr(d->expression());
            if(!expr)
                return false;

            QPatternist::DynamicContext::Ptr dynContext(d->dynamicContext());

            if(!QPatternist::BuiltinTypes::xsString->xdtTypeMatches(expr->staticType()->itemType()))
                return false;

            const QPatternist::Item::Iterator::Ptr it(expr->evaluateSequence(dynContext));
            QPatternist::Item next(it->next());

            while(!next.isNull())
            {
                target->append(next.stringValue());
                next = it->next();
            }

            return true;
        }
        catch(const QPatternist::Exception)
        {
            return false;
        }
    }
    else
        return false;
}

/*!
  Evaluates the query or stylesheet, and writes the output to \a target.

  QXmlSerializer is used to write the output to \a target. In a future
  release, it is expected that this function will be changed to
  respect serialization options set in the stylesheet.

  If an error occurs during the evaluation, error messages are sent to
  messageHandler() and \c false is returned.

  If \a target is \c null, or is not opened in at least
  QIODevice::WriteOnly mode, the behavior is undefined.  QXmlQuery
  does not take ownership of \a target.

  \since 4.5
  \overload
 */
bool QXmlQuery::evaluateTo(QIODevice *target) const
{
    if(!target)
    {
        qWarning("The pointer to the device cannot be null.");
        return false;
    }

    if(!target->isWritable())
    {
        qWarning("The device must be writable.");
        return false;
    }

    QXmlSerializer serializer(*this, target);
    return evaluateTo(&serializer);
}

/*!
  Starts the evaluation and makes it available in \a result.  If \a
  result is null, the behavior is undefined. The evaluation takes
  place incrementally (lazy evaluation), as the caller uses
  QXmlResultItems::next() to get the next result.

  \sa QXmlResultItems::next()
*/
void QXmlQuery::evaluateTo(QXmlResultItems *result) const
{
    if(!result)
    {
        qWarning("A null pointer cannot be passed.");
        return;
    }

    if(isValid())
    {
        try
        {
            /*
             * We don't have the d->expression() calls and
             * d->dynamicContext() calls in the same order as seen in
             * QXmlQuery::evaluateTo(), and the reason to why
             * that isn't a problem, is that we call isValid().
             */
            const QPatternist::DynamicContext::Ptr dynContext(d->dynamicContext());
            result->d_ptr->setDynamicContext(dynContext);
            result->d_ptr->iterator = d->expression()->evaluateSequence(dynContext);
        }
        catch(const QPatternist::Exception)
        {
            result->d_ptr->iterator = QPatternist::CommonValues::emptyIterator;
            result->d_ptr->hasError = true;
        }
    }
    else
    {
        result->d_ptr->iterator= QPatternist::CommonValues::emptyIterator;
        result->d_ptr->hasError = true;
    }
}

/*!
  Evaluates the query, and serializes the output as XML to \a output.

  If an error occurs during the evaluation, error messages are sent to
  messageHandler(), the content of \a output is undefined and \c false is
  returned, otherwise \c true is returned.

  If \a output is \c null behavior is undefined. QXmlQuery
  does not take ownership of \a output.

  Internally, the class QXmlFormatter is used for this.
 \since 4.5
 */
bool QXmlQuery::evaluateTo(QString *output) const
{
    Q_ASSERT_X(output, Q_FUNC_INFO,
               "The input cannot be null");

    QBuffer outputDevice;
    outputDevice.open(QIODevice::ReadWrite);

    QXmlFormatter formatter(*this, &outputDevice);
    const bool success = evaluateTo(&formatter);

    outputDevice.close();
    *output = QString::fromUtf8(outputDevice.data().constData());

    return success;
}

/*!
  Returns true if this query is valid. Examples of invalid queries
  are ones that contain syntax errors or that have not had setQuery()
  called for them yet.
 */
bool QXmlQuery::isValid() const
{
    return d->isValid();
}

/*!
  Sets the URI resolver to \a resolver. QXmlQuery does not take
  ownership of \a resolver.

  \sa uriResolver()
 */
void QXmlQuery::setUriResolver(const QAbstractUriResolver *resolver)
{
    d->uriResolver = resolver;
}

/*!
  Returns the query's URI resolver. If no URI resolver has been set,
  QtXmlPatterns will use the URIs in queries as they are.

  The URI resolver provides a level of abstraction, or \e{polymorphic
  URIs}. A resolver can rewrite \e{logical} URIs to physical ones, or
  it can translate obsolete or invalid URIs to valid ones.

  QtXmlPatterns calls the URI resolver for all URIs it encounters,
  except for namespaces. Specifically, all builtin functions that deal
  with URIs (\c{fn:doc()}, and \c{fn:doc-available()}).

  In the case of \c{fn:doc()}, the absolute URI is the base URI in the
  static context (which most likely is the location of the query).
  Rather than use the URI the user specified, the return value of
  QAbstractUriResolver::resolve() will be used.

  When QtXmlPatterns calls QAbstractUriResolver::resolve() the
  absolute URI is the URI mandated by the XQuery language, and the
  relative URI is the URI specified by the user.

  \sa setUriResolver()
 */
const QAbstractUriResolver *QXmlQuery::uriResolver() const
{
    return d->uriResolver;
}

/*!
  Returns the name pool used by this QXmlQuery for constructing \l
  {QXmlName} {names}. There is no setter for the name pool, because
  mixing name pools causes errors due to name confusion.
 */
QXmlNamePool QXmlQuery::namePool() const
{
    return d->namePool;
}

/*!
  Sets the focus to \a item. The focus is the set of items that the
  context item expression and path expressions navigate from. For
  example, in the expression \e p/span, the element that \e p
  evaluates to is the focus for the following expression, \e span.

  The focus can be accessed using the context item expression, i.e.,
  dot (".").

  By default, the focus is not set and is undefined. It will
  therefore result in a dynamic error, \c XPDY0002, if the focus
  is attempted to be accessed. The focus must be set before the
  query is set with setQuery().

  There is no behavior defined for setting an item which is null.

 */
void QXmlQuery::setFocus(const QXmlItem &item)
{
    d->contextItem = item;
}

/**
 * This function should be a private member function of QXmlQuery,
 * but we don't dare that due to our weird compilers.
 * @internal
 * @relates QXmlQuery
 */
template<typename TInputType>
bool setFocusHelper(QXmlQuery *const queryInstance,
                    const TInputType &focusValue)
{
    /* We call resourceLoader(), so we have ensured that we have a resourceLoader
     * that we will share in our copy. */
    queryInstance->d->resourceLoader();

    QXmlQuery focusQuery(*queryInstance);

    /* Now we use the same, so we own the loaded document. */
    focusQuery.d->m_resourceLoader = queryInstance->d->m_resourceLoader;

    /* The copy constructor doesn't allow us to copy an existing QXmlQuery and
     * changing the language at the same time so we need to use private API. */
    focusQuery.d->queryLanguage = QXmlQuery::XQuery10;

    Q_ASSERT(focusQuery.queryLanguage() == QXmlQuery::XQuery10);
    focusQuery.bindVariable(QChar::fromLatin1('u'), focusValue);
    focusQuery.setQuery(QLatin1String("doc($u)"));
    Q_ASSERT(focusQuery.isValid());

    QXmlResultItems focusResult;

    queryInstance->d->m_resourceLoader = focusQuery.d->m_resourceLoader;

    focusQuery.evaluateTo(&focusResult);
    const QXmlItem focusItem(focusResult.next());

    if(focusItem.isNull() || focusResult.hasError())
    {
        /* The previous focus must be cleared in error situations.
         * Otherwise the query may be left in an inconsistent state. */
        queryInstance->setFocus(QXmlItem());
        return false;
    }
    else
    {
        queryInstance->setFocus(focusItem);
        return true;
    }
}

/*!
  \since 4.5
  \overload

  Sets the focus to be the document located at \a documentURI and
  returns true. If \a documentURI cannot be loaded, false is returned.
  It is undefined at what time the document may be loaded. When
  loading the document, the message handler and URI resolver set on
  this QXmlQuery are used.

  If \a documentURI is empty or is not a valid URI, the behavior of
  this function is undefined.
 */
bool QXmlQuery::setFocus(const QUrl &documentURI)
{
    Q_ASSERT_X(documentURI.isValid() && !documentURI.isEmpty(),
               Q_FUNC_INFO,
               "The URI passed must be valid.");

    return setFocusHelper(this, QVariant(documentURI));
}

/*!

  Sets the focus to be the \a document read from the QIODevice and
  returns true. If \a document cannot be loaded, false is returned.

  QXmlQuery does not take ownership of \a document. The user
  guarantees that a document is available from the \a document device
  and that the document is not empty. The device must be opened in at
  least read-only mode. \a document must stay in scope as long as the
  current query is active.

 \since 4.5
 \overload
 */
bool QXmlQuery::setFocus(QIODevice *document)
{
    if(!document)
    {
        qWarning("A null QIODevice pointer cannot be passed.");
        return false;
    }

    if(!document->isReadable())
    {
        qWarning("The device must be readable.");
        return false;
    }

    return setFocusHelper(this, document);
}

/*!
  This function behaves identically to calling the setFocus() overload with a
  QIODevice whose content is \a focus encoded as UTF-8. That is, \a focus is
  treated as if it contained an XML document.

  Returns the same result as the overload.

  \overload
  \since 4.6
 */
bool QXmlQuery::setFocus(const QString &focus)
{
    QBuffer device;
    device.setData(focus.toUtf8());
    device.open(QIODevice::ReadOnly);

    return setFocusHelper(this, &device);
}

/*!
  Returns a value indicating what this QXmlQuery is being used for.
  The default is QXmlQuery::XQuery10, which means the QXmlQuery is
  being used for running XQuery and XPath queries. QXmlQuery::XSLT20
  can also be returned, which indicates the QXmlQuery is for running
  XSL-T spreadsheets.

 \since 4.5
 */
QXmlQuery::QueryLanguage QXmlQuery::queryLanguage() const
{
    return d->queryLanguage;
}

/*!
  Sets the \a name of the initial template. The initial template is
  the one the processor calls first, instead of attempting to match a
  template to the context node (if any). If an initial template is not
  set, the standard order of template invocation will be used.

  This function only applies when using QXmlQuery to process XSL-T
  stylesheets. The name becomes part of the compiled stylesheet.
  Therefore, this function must be called before calling setQuery().

  If the stylesheet has no template named \a name, the processor will
  use the standard order of template invocation.

  \since 4.5
  \sa initialTemplateName()
 */
void QXmlQuery::setInitialTemplateName(const QXmlName &name)
{
    d->initialTemplateName = name;
}

/*!
  \overload

  Sets the name of the initial template to \a localName, which must be
  a valid \l{QXmlName::localName()} {local name}. The initial template
  is the one the processor calls first, instead of attempting to match
  a template to the context node (if any). If an initial template is
  not set, the standard order of template invocation will be used.

  This function only applies when using QXmlQuery to process XSL-T
  stylesheets. The name becomes part of the compiled stylesheet.
  Therefore, this function must be called before calling setQuery().

  If \a localName is not a valid \l{QXmlName::localName()} {local
  name}, the effect is undefined. If the stylesheet has no template
  named \a localName, the processor will use the standard order of
  template invocation.

  \since 4.5
  \sa initialTemplateName()
 */
void QXmlQuery::setInitialTemplateName(const QString &localName)
{
    Q_ASSERT_X(QXmlName::isNCName(localName),
               Q_FUNC_INFO,
               "The name passed must be a valid NCName.");
    setInitialTemplateName(QXmlName(d->namePool, localName));
}

/*!
  Returns the name of the XSL-T stylesheet template that the processor
  will call first when running an XSL-T stylesheet. This function only
  applies when using QXmlQuery to process XSL-T stylesheets. By
  default, no initial template is set. In that case, a default
  constructed QXmlName is returned.

  \since 4.5
 */
QXmlName QXmlQuery::initialTemplateName() const
{
    return d->initialTemplateName;
}

/*!
  Sets the network manager to \a newManager.
  QXmlQuery does not take ownership of \a newManager.

  \sa networkAccessManager()
  \since 4.5
 */
void QXmlQuery::setNetworkAccessManager(QNetworkAccessManager *newManager)
{
    d->m_networkAccessDelegator->m_genericManager = newManager;
}

/*!
  Returns the network manager, or 0 if it has not been set.

  \sa setNetworkAccessManager()
  \since 4.5
 */
QNetworkAccessManager *QXmlQuery::networkAccessManager() const
{
    return d->m_networkAccessDelegator->m_genericManager;
}

/*!
  Binds the result of the query \a query, to a variable by name \a name.

  Evaluation of \a query will be commenced when this function is called.

  If \a query is invalid, behavior is undefined. \a query will be copied.

  \since 4.5
  \sa isValid()
 */
void QXmlQuery::bindVariable(const QXmlName &name, const QXmlQuery &query)
{
    Q_ASSERT_X(query.isValid(), Q_FUNC_INFO, "The query being bound must be valid.");

    const QPatternist::VariableLoader::Ptr vl(d->variableLoader());
    const QVariant variant(QVariant::fromValue(query));

    if(vl->invalidationRequired(name, variant))
        d->recompileRequired();

    vl->addBinding(name, variant);
}

/*!
 \overload

 Has the same behavior and effects as the function being overloaded, but takes
 the variable name \a localName as a QString. \a query is used as in the
 overloaded function.

  \since 4.5
 */
void QXmlQuery::bindVariable(const QString &localName, const QXmlQuery &query)
{
    return bindVariable(QXmlName(d->namePool, localName), query);
}

QT_END_NAMESPACE


text:
package com.robin.core.base.util;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Comparator;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @desc Sorting - Generic Comparator
 *
 * @filename GenericComparator.java
 * @author Jeevanandam Madanagopal
 * @copyright © 2010-2012 www.myjeeva.com
 */
public final class GenericComparator implements Comparator, Serializable {
	private static final long serialVersionUID = -2293914106471884607L;
	// Logger
	private static final Log LOG = LogFactory.getLog(GenericComparator.class);

	private static final int LESSER = -1;
	private static final int EQUAL = 0;
	private static final int GREATER = 1;
	private static final String METHOD_GET_PREFIX = "get";
	private static final String DATATYPE_STRING = "java.lang.String";
	private static final String DATATYPE_DATE = "java.util.Date";
	private static final String DATATYPE_INTEGER = "java.lang.Integer";
	private static final String DATATYPE_LONG = "java.lang.Long";
	private static final String DATATYPE_FLOAT = "java.lang.Float";
	private static final String DATATYPE_DOUBLE = "java.lang.Double";
	private enum CompareMode { EQUAL, LESS_THAN, GREATER_THAN, DEFAULT }

	// generic comparator attributes
	private String targetMethod;
	private boolean sortAscending;

	/**
	 *
default constructor - assumes comparator for Type List

	 *
	 *
For Example-

	 * List<Integer> aa = new ArrayList<Integer>();

	 * List<String> bb = new ArrayList<String>();

	 * List<Date> cc = new ArrayList<Date>();

	 *
and so on..

	 *
Invoking sort method with passing {@link com.myjeeva.comparator.GenericComparator} for

	 * Collections.sort(aa, new GenericComparator(false));

	 *
	 * @param sortAscending - a {@link boolean} - true ascending order or false descending order
	 */
	public GenericComparator(boolean sortAscending) {
		super();
		this.targetMethod = null;
		this.sortAscending = sortAscending;
	}

	/**
	 *
constructor with sortField parameter for Derived type of Class default sorting is ascending order

	 *
	 *
For Example-

	 *
PersonVO person = new PersonVO();

	 * person.setId(10001);

	 * person.setName("Jacob");

	 * person.setHeight(5.2F);

	 * person.setEmailId("jacob@example.example");

	 * person.setSalary(10500L);

	 * person.setDob(new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse("Jan 1, 1970"));

	 *
and person2, person3, so on.. And Defining & adding all the created objects in to below list

	 *
List<PersonVO> persons = new ArrayList<PersonVO>();

	 * persons.add(person1);

	 * persons.add(person2);

	 * persons.add(person3); and so on

	 *
Invoking sort method with passing {@link com.myjeeva.comparator.GenericComparator} for

	 * Collections.sort(persons, new GenericComparator("name"));

	 *
	 * @param sortField - a {@link java.lang.String} - which field requires sorting; as per above example "sorting required for name field"
	 */
	public GenericComparator(String sortField) {
		super();
		this.targetMethod = prepareTargetMethod(sortField);
		this.sortAscending = true;
	}

	/**
	 *
constructor with sortField, sortAscending parameter for Derived type of Class

	 *
	 *
For Example-

	 *
PersonVO person = new PersonVO();

	 * person.setId(10001);

	 * person.setName("Jacob");

	 * person.setHeight(5.2F);

	 * person.setEmailId("jacob@example.example");

	 * person.setSalary(10500L);

	 * person.setDob(new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse("Jan 1, 1970"));

	 *
and person2, person3, so on.. And Defining & adding all the created objects in to below list

	 *
List<PersonVO> persons = new ArrayList<PersonVO>();

	 * persons.add(person1);

	 * persons.add(person2);

	 * persons.add(person3); and so on

	 *
Invoking sort method with passing {@link com.myjeeva.comparator.GenericComparator} for

	 * Collections.sort(persons, new GenericComparator("name"), false);

	 * @param sortField - a {@link java.lang.String} - which field requires sorting; as per above example "sorting required for name field"
	 * @param sortAscending - a {@link boolean} - true ascending order or false descending order
	 */
	public GenericComparator(String sortField, boolean sortAscending) {
		super();
		this.targetMethod = prepareTargetMethod(sortField);
		this.sortAscending = sortAscending;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int compare(Object o1, Object o2) {
		int response = LESSER;
		try {
			Object v1 = (null == this.targetMethod) ? o1 : getValue(o1);
			Object v2 = (null == this.targetMethod) ? o2 : getValue(o2);
			CompareMode cm = findCompareMode(v1, v2);

			if (!cm.equals(CompareMode.DEFAULT)) {
				return compareAlternate(cm);
			}

			final String returnType = (null == this.targetMethod)
											? o1.getClass().getName() : getMethod(o1).getReturnType().getName();
			response = compareActual(v1, v2, returnType);
		} catch (NoSuchMethodException nsme) {
			LOG.error("NoSuchMethodException occurred while comparing", nsme);
		} catch (IllegalAccessException iae) {
			LOG.error("IllegalAccessException occurred while comparing", iae);
		} catch (InvocationTargetException ite) {
			LOG.error("InvocationTargetException occurred while comparing", ite);
		}
		return response;
	}

	//---------------------------------------------------------------------------------//
	// Private methods used by {@link com.myjeeva.comparator.GenericComparator} //
	//---------------------------------------------------------------------------------//

	/**
	 * alternate to actual value comparison i.e., either (lsh & rhs) one the value could be null
	 *
	 * @param cm - a enum used to idetify the position for sorting
	 */
	private int compareAlternate(CompareMode cm) {
		int compareState = LESSER;
		switch(cm) {
			case LESS_THAN:
				compareState = LESSER * determinePosition();
				break;
			case GREATER_THAN:
				compareState = GREATER * determinePosition();
				break;
			case EQUAL:
				compareState = EQUAL * determinePosition();
				break;
			case DEFAULT:
				compareState = EQUAL * determinePosition();
				break;
			default:
				break;
		}
		return compareState;
	}

	/**
	 * actual value comparison for sorting; both lsh & rhs value available
	 *
	 * @param v1 - value of lhs
	 * @param v2 - value of rhs
	 * @param returnType - datatype of given values
	 * @return int - compare return value
	 */
	private int compareActual(Object v1, Object v2, String returnType) {
		int acutal = LESSER;
		if (returnType.equals(DATATYPE_INTEGER)) {
			acutal = (((Integer) v1).compareTo((Integer) v2) * determinePosition());
		} else if (returnType.equals(DATATYPE_LONG)) {
			acutal = (((Long) v1).compareTo((Long) v2) * determinePosition());
		} else if (returnType.equals(DATATYPE_STRING)) {
			acutal = (((String) v1).compareTo((String) v2) * determinePosition());
		} else if (returnType.equals(DATATYPE_DATE)) {
			acutal = (((Date) v1).compareTo((Date) v2) * determinePosition());
		} else if (returnType.equals(DATATYPE_FLOAT)) {
			acutal = (((Float) v1).compareTo((Float) v2) * determinePosition());
		} else if (returnType.equals(DATATYPE_DOUBLE)) {
			acutal = (((Double) v1).compareTo((Double) v2) * determinePosition());
		}
		return acutal;
	}

	/**
	 * preparing target name of getter method for given sort field
	 *
	 * @param name a {@link java.lang.String}
	 * @return methodName a {@link java.lang.String}
	 */
	private static String prepareTargetMethod(String name) {
		StringBuffer fieldName =  new StringBuffer(METHOD_GET_PREFIX);
		fieldName.append(name.substring(0, 1).toUpperCase());
		fieldName.append(name.substring(1));
		return fieldName.toString();
	}

	/**
	 * fetching method from Class object through reflect
	 *
	 * @param obj - a {@link java.lang.Object} - input object
	 * @return method - a {@link java.lang.reflect.Method}
	 * @throws NoSuchMethodException
	 */
	private Method getMethod(Object obj) throws NoSuchMethodException {
		return obj.getClass().getMethod(targetMethod, null);
	}

	/**
	 * dynamically invoking given method with given object through reflect
	 *
	 * @param method - a {@link java.lang.reflect.Method}
	 * @param obj - a {@link java.lang.Object}
	 * @return object - a {@link java.lang.Object} - return of given method
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	private static Object invoke(Method method, Object obj) throws InvocationTargetException, IllegalAccessException {
		return method.invoke(obj, null);
	}

	/**
	 * fetching a value from given object
	 *
	 * @param obj - a {@link java.lang.Object}
	 * @return object - a {@link java.lang.Object} - return of given method
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @throws NoSuchMethodException
	 */
	private Object getValue(Object obj) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
		return invoke(getMethod(obj), obj);
	}

	/**
	 * identifying the comparison mode for given value
	 *
	 * @param o1 - a {@link java.lang.Object}
	 * @param o2 - a {@link java.lang.Object}
	 * @return compareMode - a {@link com.myjeeva.comparator.GenericComparator.CompareMode}
	 */
	private CompareMode findCompareMode(Object o1, Object o2) {
		CompareMode cm = CompareMode.LESS_THAN;

		if(null != o1 & null != o2) {
			cm = CompareMode.DEFAULT;
		} else if (null == o1 & null != o2) {
			cm = CompareMode.LESS_THAN;
		} else if (null != o1 & null == o2) {
			cm = CompareMode.GREATER_THAN;
		} else if (null == o1 & null == o2) {
			cm = CompareMode.EQUAL;
		}

		return cm;
	}

	/**
	 * Determining positing for sorting
	 *
	 * @return -1 to change the sort order if appropriate.
	 */
	private int determinePosition() {
		return sortAscending ? GREATER : LESSER;
	}
}

redpajama_set_name: RedPajamaGithub


text:
package com.github.philippheuer.chatbot4twitch.commands.general;

import me.philippheuer.twitch4j.events.event.irc.ChannelMessageEvent;
import me.philippheuer.twitch4j.message.commands.Command;
import me.philippheuer.twitch4j.message.commands.CommandPermission;

import java.util.Set;

public class Commands extends Command {
    /**
     * Initialize Command
     */
    public Commands() {
        super();

        // Command Configuration
        setCommand("команды");
        setCommandAliases(new String[]{});
        setCategory("general");
        setDescription("Показывает все команды.");
        getRequiredPermissions().add(CommandPermission.EVERYONE);
        setUsageExample("");
    }

    /**
     * executeCommand Logic
     */
    @Override
    public void executeCommand(ChannelMessageEvent messageEvent) {
        super.executeCommand(messageEvent);
        Set<String> commandSet = getTwitchClient().getCommandHandler().getCommandMap().keySet();
        //int numberOfCommands = getTwitchClient().getCommandHandler().getCommandMap().size();
        StringBuilder builderMod = new StringBuilder("Для модераторов: ");
        StringBuilder builderSub = new StringBuilder("Для подписчиков: ");
        StringBuilder builderAll = new StringBuilder("Для всех: ");

        for (String command : commandSet
                ) {
            if (isForAll(command)) {
                builderAll.append("!").append(command).append(" ");
            }

            if (isForSubs(command)) {
                builderSub.append("!").append(command).append(" ");
            }

            if (isForMods(command)) {
                builderMod.append("!").append(command).append(" ");
            }
        }
        sendMessageToChannel(messageEvent.getChannel().getName(), builderMod.toString().trim() + ". " + builderSub.toString().trim() + ". " + builderAll.toString().trim() + ".");
    }

    private boolean isForAll(String command) {
        return (getTwitchClient().getCommandHandler().getCommand(command).isPresent())
                && (getTwitchClient().getCommandHandler().getCommand(command).get().getRequiredPermissions().contains(CommandPermission.EVERYONE));
    }

    private boolean isForSubs(String command) {
        return (getTwitchClient().getCommandHandler().getCommand(command).isPresent())
                && (getTwitchClient().getCommandHandler().getCommand(command).get().getRequiredPermissions().contains(CommandPermission.SUBSCRIBER));
    }

    private boolean isForMods(String command) {
        return (getTwitchClient().getCommandHandler().getCommand(command).isPresent())
                && (getTwitchClient().getCommandHandler().getCommand(command).get().getRequiredPermissions().contains(CommandPermission.MODERATOR))
                && !(getTwitchClient().getCommandHandler().getCommand(command).get().getRequiredPermissions().contains(CommandPermission.SUBSCRIBER));
    }

}


text:
/**
 * More details
 * http://illya-keeplearning.blogspot.com/search/label/suffix%20tree
 */
package com.blogspot.illyakeeplearning.suffixtree.gui;

import com.blogspot.illyakeeplearning.suffixtree.GeneralizedSuffixTree;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GSTApplet extends JApplet {
    private static final Dimension HGAP5 = new Dimension(5, 1);

    private STDrawPanel drawPanel;
    private STControlPanel controlPanel;

    private GeneralizedSuffixTree gst;

    @Override
    public void init() {
        String laf = UIManager.getCrossPlatformLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(laf);
        } catch (UnsupportedLookAndFeelException exc) {
            System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
        } catch (Exception exc) {
            System.err.println("Error loading " + laf + ": " + exc);
        }

        controlPanel = new STControlPanel();
        drawPanel = new STDrawPanel();

        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(BorderLayout.NORTH, controlPanel);
        getContentPane().add(BorderLayout.CENTER, drawPanel);
    }

    private class STControlPanel extends JPanel implements ActionListener {
        private JButton buildButton;
        private JLabel textLabel1;
        private JTextField textField1;
        private JLabel textLabel2;
        private JTextField textField2;

        public STControlPanel() {
            buildButton = new JButton("Build GST");
            buildButton.addActionListener(this);

            textLabel1 = new JLabel("String 1: ");
            textField1 = new JTextField();

            textLabel2 = new JLabel("String 2: ");
            textField2 = new JTextField();

            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

            add(Box.createRigidArea(HGAP5));
            add(textLabel1, BorderLayout.WEST);
            add(Box.createRigidArea(HGAP5));
            add(textField1, BorderLayout.WEST);
            add(Box.createRigidArea(HGAP5));
            add(Box.createRigidArea(HGAP5));

            add(textLabel2, BorderLayout.WEST);
            add(Box.createRigidArea(HGAP5));
            add(textField2, BorderLayout.WEST);
            add(Box.createRigidArea(HGAP5));
            add(Box.createRigidArea(HGAP5));

            add(buildButton, BorderLayout.EAST);
        }

        public void actionPerformed(ActionEvent e) {
            String arg = e.getActionCommand();
            if (arg.equals("Build GST")) {
                gst = new GeneralizedSuffixTree(textField1.getText(), textField2.getText(), '#', '$');
                drawPanel.setSuffixTree(gst.getSuffixTree());
            }
        }
    }
}


text:
package com.miscitems.MiscItemsAndBlocks.Network.Client;

import MiscUtils.Network.AbstractPacket;
import MiscUtils.Handlers.ChatMessageHandler;
import com.miscitems.MiscItemsAndBlocks.Main.Main;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;

public class ClientGamePacketInviteRecived  extends AbstractPacket {

	String Player;

	public ClientGamePacketInviteRecived(){}
	public ClientGamePacketInviteRecived(String Pl){
		Player = Pl;
	}

	@Override

    public void fromBytes(ByteBuf buf, Side side) {
		Player = ByteBufUtils.readUTF8String(buf);
	}

	@Override
	public void toBytes(ByteBuf buf, Side side) {
		ByteBufUtils.writeUTF8String(buf,Player);
	}

	@Override
    public void onMessage(Side side, EntityPlayer player) {

        if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
            Main.proxy.tickHandlerClient.tradeReq = Player;
             FMLClientHandler.instance().getClient().theWorld.playSoundEffect((float) FMLClientHandler.instance().getClient().thePlayer.posX, (float) FMLClientHandler.instance().getClient().thePlayer.posY, (float) FMLClientHandler.instance().getClient().thePlayer.posZ, "random.successful_hit", 1.0F, 1.0F);
            ChatMessageHandler.sendChatToPlayer(FMLClientHandler.instance().getClient().thePlayer, EnumChatFormatting.GOLD + "You have recived a game invite to play tic tac toe!");

        }

	}

}


text:
package org.editorconfig.configmanagement.generate;

import com.intellij.application.options.CodeStyle;
import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.codeInsight.actions.CodeInsightAction;
import com.intellij.ide.DataManager;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.project.LightEditActionFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
import org.editorconfig.configmanagement.export.EditorConfigSettingsWriter;
import org.editorconfig.configmanagement.extended.EditorConfigPropertyKind;
import org.editorconfig.core.EditorConfig;
import org.editorconfig.language.messages.EditorConfigBundle;
import org.editorconfig.language.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class EditorConfigGenerateLanguagePropertiesAction extends CodeInsightAction {

  private final static CodeInsightActionHandler HANDLER = new LanguagePropertiesGenerator();
  private final static Logger LOG = Logger.getInstance(EditorConfigGenerateLanguagePropertiesAction.class);

  @Override
  protected @NotNull CodeInsightActionHandler getHandler() {
    return HANDLER;
  }

  @Override
  protected boolean isValidForFile(@NotNull Project project,
                                   @NotNull Editor editor,
                                   @NotNull PsiFile file) {
    if (file instanceof EditorConfigPsiFile) {
      int currOffset = editor.getCaretModel().getOffset();
      if (currOffset == file.getTextLength() && currOffset > 0) currOffset --;
      PsiElement contextElement = file.findElementAt(currOffset);
      if (contextElement != null) {
        if (contextElement instanceof PsiWhiteSpace) {
          PsiElement prev = contextElement.getPrevSibling();
          return prev != null &&
                 (prev.getNode().getElementType() == EditorConfigElementTypes.SECTION ||
                  prev.getNode().getElementType() == EditorConfigElementTypes.HEADER ||
                  prev instanceof EditorConfigOption);
        }
        else if (contextElement.getNode().getElementType() == EditorConfigElementTypes.IDENTIFIER) {
          return contextElement.getTextRange().getStartOffset() == currOffset;
        }
      }
    }
    return false;
  }

  @TestOnly
  public static void generateProperties(@NotNull Project project, @NotNull Editor editor, @NotNull Language language) {
    LanguagePropertiesGenerator.generateProperties(project, editor, language);
  }

  private static class LanguagePropertiesGenerator implements CodeInsightActionHandler {
    @Override
    public boolean startInWriteAction() {
      return false;
    }

    @Override
    public void invoke(@NotNull Project project,
                       @NotNull Editor editor, @NotNull PsiFile file) {
      ListPopup languagePopup = createLanguagePopup(project, file, editor);
      languagePopup.showInBestPositionFor(editor);
    }

    private static void generateProperties(@NotNull Project project, @NotNull Editor editor, @NotNull Language language) {
      LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(language);
      if (provider != null) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try (
          EditorConfigSettingsWriter writer =
            new EditorConfigSettingsWriter(project, output, CodeStyle.getSettings(project), false, false)
              .forLanguages(language)
              .forPropertyKinds(EditorConfigPropertyKind.LANGUAGE)
              .withoutHeaders()) {
          writer.writeSettings();
          writer.flush();
          String text = new String(output.toByteArray(), StandardCharsets.UTF_8);
          CommandProcessor.getInstance().runUndoTransparentAction(
            () -> ApplicationManager.getApplication().runWriteAction(
              () -> {
                editor.getDocument().insertString(editor.getCaretModel().getOffset(), text);
              }
            )
          );
        }
        catch (IOException e) {
          LOG.error(e);
        }
      }
    }

    private static ListPopup createLanguagePopup(@NotNull Project project, @NotNull PsiFile file, @NotNull Editor editor) {
      DefaultActionGroup languageGroup = new DefaultActionGroup();
      Set<Language> preferredLanguages = getPreferredLanguages(file, editor.getCaretModel().getOffset());
      getSupportedLanguages().stream()
                             .sorted((l1, l2) -> {
                               if (preferredLanguages == null) return 0;
                               return (preferredLanguages.contains(l2) ? 1 : 0) - (preferredLanguages.contains(l1) ? 1 : 0);
                             })
                             .forEach(
                               language -> {
                                 languageGroup.add(
                                   LightEditActionFactory
                                     .create(language.getDisplayName(), event -> generateProperties(project, editor, language)));
                               }
                             );
      return JBPopupFactory.getInstance().createActionGroupPopup(
        EditorConfigBundle.message("popup.title.choose.language"),
        languageGroup,
        DataManager.getInstance().getDataContext(editor.getComponent()),
        JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
        false);
    }

    private static List<Language> getSupportedLanguages() {
      return
        LanguageCodeStyleSettingsProvider.getAllProviders()
                                                 .stream()
                                                 .filter(provider -> provider.supportsExternalFormats())
                                                 .map(provider -> provider.getLanguage())
                                                 .sorted((l1, l2) -> l1.getDisplayName().compareToIgnoreCase(l2.getDisplayName()))
                                                 .collect(Collectors.toList());
    }

    @Nullable
    private static Set<Language> getPreferredLanguages(@NotNull PsiFile file, int offset) {
      Set<Language> languages = new HashSet<>();
      int currOffset = offset == file.getTextLength() && offset > 0 ? offset - 1 : offset;
      PsiElement contextElement = file.findElementAt(currOffset);
      if (contextElement != null) {
        EditorConfigHeader header = findHeader(contextElement);
        if (header != null) {
          String pattern = header.getText();
          pattern = StringUtil.trimEnd(StringUtil.trimStart(pattern, "["), "]").trim();
          if ("*".equals(pattern)) return null;
          for (FileType fileType : FileTypeManager.getInstance().getRegisteredFileTypes()) {
            if (fileType instanceof LanguageFileType) {
              String testName = "/a." + fileType.getDefaultExtension();
              if (EditorConfig.filenameMatches("", pattern, testName)) {
                languages.add(((LanguageFileType)fileType).getLanguage());
              }
            }
          }
        }
      }
      return languages;
    }

    @Nullable
    private static EditorConfigHeader findHeader(@NotNull PsiElement contextElement) {
      if (contextElement instanceof PsiWhiteSpace) {
        PsiElement prev = contextElement.getPrevSibling();
        if (prev instanceof EditorConfigSection) {
          return ((EditorConfigSection)prev).getHeader();
        }
      }
      PsiElement parent = contextElement.getParent();
      while (parent != null && !(parent instanceof PsiFile)) {
        if (parent instanceof EditorConfigSection) {
          return ((EditorConfigSection)parent).getHeader();
        }
        parent = parent.getParent();
      }
      return null;
    }
  }
}


text:
package net.peterkuterna.android.apps.devoxxsched.service;

import java.util.ArrayList;
import java.util.List;

import net.peterkuterna.android.apps.devoxxsched.c2dm.Util;
import net.peterkuterna.android.apps.devoxxsched.provider.CfpContract;
import net.peterkuterna.android.apps.devoxxsched.provider.CfpContract.Sessions;
import net.peterkuterna.android.apps.devoxxsched.util.Lists;
import net.peterkuterna.android.apps.devoxxsched.util.Prefs;
import net.peterkuterna.android.apps.devoxxsched.util.Prefs.DevoxxPrefs;
import net.peterkuterna.appengine.apps.devoxxsched.shared.DevoxxRequest;
import net.peterkuterna.appengine.apps.devoxxsched.shared.DevoxxRequestFactory;
import net.peterkuterna.appengine.apps.devoxxsched.shared.SessionProxy;
import android.app.IntentService;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
import android.provider.BaseColumns;
import android.util.Log;

import com.google.web.bindery.requestfactory.shared.Receiver;

/**
 * {@link IntentService} that performs the sync operation with the AppEngine
 * part. It will send pending starring/unstarring operations and retrieve the
 * starred session id's back from AppEngine.
 */
public class AppEngineSyncService extends AbstractSyncService {

	protected static final String TAG = "AppEngineSyncService";

	public static final String EXTRA_INITIAL_SYNC = "net.peterkuterna.android.apps.devoxxsched.extra.INITIAL_SYNC";

	private ContentResolver mResolver;

	public AppEngineSyncService() {
		super(TAG);
	}

	@Override
	public void onCreate() {
		super.onCreate();

		mResolver = getContentResolver();
	}

	@Override
	protected void doSync(Intent intent) throws Exception {
		Log.d(TAG, "Start session sync");

		final Context context = this;
		final SharedPreferences prefs = Prefs.get(context);
		String deviceRegistrationID = prefs.getString(
				DevoxxPrefs.DEVICE_REGISTRATION_ID, null);
		if (deviceRegistrationID != null) {
			Cursor c = null;
			if (intent.hasExtra(EXTRA_INITIAL_SYNC)) {
				c = mResolver.query(Sessions.CONTENT_STARRED_URI,
						SessionsQuery.PROJECTION, null, null, null);
			} else {
				c = mResolver.query(Sessions.CONTENT_URI,
						SessionsQuery.PROJECTION,
						Sessions.SESSION_OPERATION_PENDING + "=1", null, null);
			}

			DevoxxRequestFactory factory = (DevoxxRequestFactory) Util
					.getRequestFactory(context, DevoxxRequestFactory.class);
			DevoxxRequest request = factory.devoxxRequest();

			final ArrayList<SessionProxy> toStar = Lists.newArrayList();
			final ArrayList<SessionProxy> toUnstar = Lists.newArrayList();

			try {
				while (c.moveToNext()) {
					final String sessionId = c
							.getString(SessionsQuery.SESSION_ID);
					final int isStarred = c
							.getInt(SessionsQuery.SESSION_STARRED);
					final SessionProxy session = request
							.create(SessionProxy.class);
					session.setSessionId(sessionId);
					if (isStarred == 1) {
						toStar.add(session);
					} else {
						toUnstar.add(session);
					}
				}
			} finally {
				c.close();
			}

			Log.d(TAG, "Going to star " + toStar.size()
					+ " sessions and unstar " + toUnstar.size() + " sessions.");
			request.sync(toStar, toUnstar).fire(
					new Receiver<List<SessionProxy>>() {
						@Override
						public void onSuccess(List<SessionProxy> sessions) {
							if (sessions != null) {
								Log.d(TAG, "Received " + sessions.size()
										+ " starred sessions in response");
								ArrayList<ContentProviderOperation> batch = Lists
										.newArrayList();
								batch.add(ContentProviderOperation
										.newUpdate(Sessions.CONTENT_STARRED_URI)
										.withValue(Sessions.SESSION_STARRED, 0)
										.build());
								for (SessionProxy session : sessions) {
									final Uri sessionUri = Sessions
											.buildSessionUri(session
													.getSessionId());
									batch.add(ContentProviderOperation
											.newUpdate(sessionUri)
											.withValue(
													Sessions.SESSION_STARRED, 1)
											.build());
								}
								batch.add(ContentProviderOperation
										.newUpdate(Sessions.CONTENT_URI)
										.withValue(
												Sessions.SESSION_OPERATION_PENDING,
												0).build());
								try {
									mResolver.applyBatch(
											CfpContract.CONTENT_AUTHORITY,
											batch);
								} catch (RemoteException e) {
									Log.w(TAG, e.getMessage());
								} catch (OperationApplicationException e) {
									Log.w(TAG, e.getMessage());
								}
							}
						}
					});
		}

		Log.d(TAG, "Session sync finished");
	}

	/**
	 * {@link Sessions} query parameters.
	 */
	private interface SessionsQuery {

		String PROJECTION[] = { BaseColumns._ID,
				CfpContract.Sessions.SESSION_ID,
				CfpContract.Sessions.SESSION_STARRED };

		int _ID = 0;
		int SESSION_ID = 1;
		int SESSION_STARRED = 2;

	}

}


text:
int main()
{
    std::clock_t c = 0;
    ((void)c); // avoid unused warning
    std::size_t s = 0;
    std::time_t t = 0;
    std::tm tm = {0};
    char str[3];
    static_assert((std::is_same<decltype(std::clock()), std::clock_t>::value), "");
    static_assert((std::is_same<decltype(std::difftime(t,t)), double>::value), "");
    static_assert((std::is_same<decltype(std::mktime(&tm)), std::time_t>::value), "");
    static_assert((std::is_same<decltype(std::time(&t)), std::time_t>::value), "");
    static_assert((std::is_same<decltype(std::asctime(&tm)), char*>::value), "");
    static_assert((std::is_same<decltype(std::ctime(&t)), char*>::value), "");
    static_assert((std::is_same<decltype(std::gmtime(&t)), std::tm*>::value), "");
    static_assert((std::is_same<decltype(std::localtime(&t)), std::tm*>::value), "");
    static_assert((std::is_same<decltype(std::strftime(str,s,"",&tm)), std::size_t>::value), "");
}


text:
'''
Created by auto_sdk on 2014.11.04
'''
from top.api.base import RestApi
class WlbOrderConsignRequest(RestApi):
	def __init__(self,domain='gw.api.taobao.com',port=80):
		RestApi.__init__(self,domain, port)
		self.wlb_order_code = None

	def getapiname(self):
		return 'taobao.wlb.order.consign'


text:
package org.corundummc.entities.nonliving.hanging;

import net.minecraft.entity.item.EntityPainting;
import org.corundummc.entities.nonliving.hanging.HangingEntity.HangingEntityType;

public class Painting extends HangingEntity<Painting, EntityPainting, Painting.PaintingType> {
    public Painting() {
        super(new EntityPainting(null));
    }

    protected Painting(EntityPainting entityMC) {
        super(entityMC);
    }

    protected static class PaintingType extends HangingEntityType<PaintingType, EntityPainting, Painting> {
        public static final PaintingType TYPE = new PaintingType();

        private PaintingType() {
            super(9);
        }

        // overridden utilities
        @Override
        public Painting create() {
            return new Painting();
        }

        /** This method is used to create a new instance of {@link Entity Corundum Entity} to wrap around the given {@link Minecraft net.minecraft.entity.Entity}.
         *
         * @param entityMC
         *            is the Minecraft Entity that will wrapped with a new {@link Entity Corundum Entity} <tt>Object</tt>.
         * @return a new Entity created using the given {@link net.minecraft.entity.Entity Minecraft Entity}. */
        @Override
        public Painting fromMC(EntityPainting entityMC) {
            return new Painting(entityMC);
        }
    }

    // instance utilities

    // overridden utilities
    @Override
    public PaintingType getType() {
        return PaintingType.TYPE;
    }
}


text:
package backend

import (
	"owl/common/types"

	"gopkg.in/Shopify/sarama.v1"
)

type KafkaBackend struct {
	Producer sarama.SyncProducer
	Topic    string
}

func NewKafkaBackend(brokers []string, topic string) (*KafkaBackend, error) {
	producer, err := sarama.NewSyncProducer(brokers, nil)
	if err != nil {
		return nil, err
	}
	backend := &KafkaBackend{
		Producer: producer,
		Topic:    topic,
	}
	return backend, nil
}

func (backend *KafkaBackend) Write(data *types.TimeSeriesData) error {
	message := &sarama.ProducerMessage{
		Topic: backend.Topic,
		Value: sarama.StringEncoder(string(data.Encode())),
	}
	_, _, err := backend.Producer.SendMessage(message)
	return err
}


text:
$cmdletsToBeExported = @("Get-GcLogEntry", "New-GcLogEntry", "New-GcLogMonitoredResource",
                         "Get-GcLog", "Remove-GcLog", "New-GcLogSink", "Get-GcLogSink",
                         "Update-GcLogSink", "Remove-GcLogSink", "Get-GcpsTopic",
                         "New-GcpsTopic", "Remove-GcpsTopic", "New-GcpsSubscription",
                         "Get-GcpsSubscription", "Set-GcpsSubscriptionConfig",
                         "Remove-GcpsSubscription", "New-GcpsMessage", "Publish-GcpsMessage",
                         "Get-GcpsMessage", "Set-GcpsAckDeadline", "Send-GcpsAck"
                         "Get-GcIamPolicyBinding", "Add-GcIamPolicyBinding",
                         "Get-BqDataset", "Set-BqDataset", "New-BqDataset", "Remove-BqDataset",
                         "Get-BqTable", "Set-BqTable", "New-BqTable", "Remove-BqTable",
                         "New-BqSchema", "Set-BqSchema", "Add-BqTableRows", "Get-BqTableRows",
                         "Get-BqJob", "Start-BqJob", "Receive-BqJob", "Stop-BqJob",
                         "Get-GkeCluster", "New-GkeNodeConfig", "Add-GkeCluster",
                         "Set-GkeCluster", "Remove-GkeCluster", "Add-GkeNodePool",
                         "Get-GkeNodePool", "New-GkeNodePool")
$cmdletsToBeExported


text:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
        <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
            <SignedInfo>
                <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
                <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                <Reference URI="">
                    <Transforms>
                        <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                    </Transforms>
                    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                    <DigestValue>lKKQ147Vik+XPEtEmSG7oD/iF6I=</DigestValue>
                </Reference>
            </SignedInfo>
            <SignatureValue>nujc8vcEdwNdFcMV+afElicLWWByJTVWJvwtTDe+yZA9zX10CT8dO38mvVWlq3wZ5L1Z5ffBwDcX
      QflIWVqJ2Nbg3SlFPck9zXPJQRjmDOFN26jRrmdlJnQY08DXoVyi3w7dhntrXr6fLO88+Z9Q+M/Y
    dieKcRKKu1D9RWNVhF4=
            </SignatureValue>
        </Signature>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12" SOAP-SEC:id="Body">
        <tran:getTransaction xmlns:tran="http://www.allpay.kz/mfs/soap/TransactionManagement">
            <GetTransactionRequest>
                <transactionNumber>1</transactionNumber>
            </GetTransactionRequest>
        </tran:getTransaction>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


text:
'''
Created on Aug 27, 2014

Declare PDC constant string here
'''

# Contact Types
QE_GROUP_CONTACT = 'QE_Group'
QE_LEADER_CONTACT = 'QE_Leader'
QE_ACK_CONTACT = 'QE_ACK'
BUILD_CONTACT = 'Build_Owner'
DEVEL_CONTACT = 'Devel_Owner'

# Arch type
ARCH_SRC = 'src'

# PDC warning field in response header
PDC_WARNING_HEADER_NAME = 'pdc-warning'

# Warning when using put method on optional parameter
PUT_OPTIONAL_PARAM_WARNING = {
    'PUT_OPTIONAL_PARAM_WARNING': 'When using the `PUT` method, if an optional field is not specified' +
                                  ' in the input, it will be erased.',
}


text:
class Release004 < ActiveRecord::Migration[4.2]
  def up
    add_index :players_results, :player_id
    add_index :players_results, :result_id

    add_index :rating_history_events, :rating_id

    add_index :ratings, :player_id
    add_index :ratings, :game_id

    add_index :results, :game_id
    add_index :results, :loser_id
    add_index :results, :winner_id
  end

  def down
  end
end