text:
/**
 \file    LuaScripting.h
 \author  James Hughes
          SCI Institute
          University of Utah
 \date    Mar 21, 2012
 \brief   Interface to the Lua scripting system built for Tuvok.

          To see examples of how to use the system, consult the unit tests at
          the bottom of LuaMemberReg.cpp and LuaScripting.cpp.
 */

#ifndef TUVOK_LUASCRIPTING_H_
#define TUVOK_LUASCRIPTING_H_

#include <functional>
#include <memory>

#ifndef LUASCRIPTING_NO_TUVOK

#include "3rdParty/LUA/lua.hpp"

#else

#include "Lua/lua.hpp"
#include "NoTuvok/LuaTuvokException.h"

#ifdef __clang__
// Place shared_ptr and function in the tr1 namespace.
namespace std {
  namespace tr1 {
    using std::shared_ptr;
    using std::function;
  }
}
#endif

#endif

#include "LuaCommon.h"
#include "LuaError.h"
#include "LuaFunBinding.h"
#include "LuaStackRAII.h"
#include "LuaScriptingExecHeader.h"

namespace tuvok
{

class LuaProvenance;
class LuaMemberRegUnsafe;
class LuaClassConstructor;
template <class T> class LuaClassRegistration;

/// Usage Note: If you construct any Lua Class instances that retain a
/// shared_ptr reference to this LuaScripting class, be sure to call
/// removeAllRegistrations before deleting LuaScripting.
/// Consider using weak_ptr instead.
class LuaScripting
{
  // TODO: Expose getLuaState function and most of these can go away.
  friend class LuaMemberRegUnsafe;  // For getNewMemberHookID.
  friend class LuaProvenance;       // For obtaining function tables.
  friend class LuaStackRAII;        // For unwinding lua stack during exception
  friend class LuaClassInstanceHook;// For getNewMemberHookID.
  friend class LuaClassConstructor; // For createCallableFuncTable.
  template<class T> friend class LuaClassRegistration;// For notifyOfDeletion.
  friend class LuaClassInstance;    // For obtaining Lua instance.
public:

  LuaScripting();
  virtual ~LuaScripting();

  /// It is highly recommended to call this function as your program is about
  /// to terminate. All it does is clear the provenance history and perform
  /// a complete Lua garbage collection cycle. This is necessary to get rid
  /// of any shared_ptr objects that may be in the provenance system.
  /// If you pass any shared_ptr's that reference LuaScripting, you must call
  /// this function. Otherwise, you will have memory leaks.
  void clean();

  /// Removes all class definitions and function registrations from the system.
  /// This will clean up any lingering classes that may have lingering
  /// shared pointer references.
  void removeAllRegistrations();

  /// Registers a static C++ function with Lua.
  /// Since Lua is compiled as CPP, it is safe to throw exceptions from the
  /// function pointed to by f (since Lua detects that it is being compiled in
  /// cpp, and uses exceptions instead of long jumping).
  /// \param  f         Any function pointer.
  ///                   f's parameters and return value will be handled
  ///                   automatically.
  ///                   The number of parameters allowed in f is limited by
  ///                   the templates in LuaFunBinding.h.
  /// \param  name      Period delimited fully qualified name of f inside of Lua
  ///                   No characters other than those regularly allowed inside
  ///                   C++ functions are allowed, with the exception of periods
  ///                   Example: "renderer.eye"
  /// \param  desc      Description of f.
  /// \param  undoRedo  If true, this function will add itself to the
  ///                   provenance tracking system and undo/redo will be handled
  ///                   automatically. If false, the function will not use
  ///                   undo/redo functionality in the provenance system.
  ///                   You will not want undo/redo on functions that do not
  ///                   modify state (such as getters).
  ///
  /// \return The name parameter. You can use this as an id.
  ///
  /// NOTES: The system is re-entrant, so you may call lua from within
  /// registered functions, or even call other registered functions.
  ///
  /// Automatic Undo/Redo: In order for automatic undo/redo to function
  /// properly with registered functions, the following property needs to be
  /// satisfied: your functions must be idempotent, or a composition
  /// of idempotent functions such that all of the side-effects of the function
  /// are known to the provenance system. This is further explained in the
  /// Lua Scripting paper.
  ///
  /// TO REGISTER MEMBER FUNCTIONS:
  /// Use the LuaMemberReg mediator class. It will clean up for you.
  template <typename FunPtr>
  std::string registerFunction(FunPtr f,
                               const std::string& name,
                               const std::string& desc,
                               bool undoRedo);

  /// Hooks a fully qualified function name with the given function.
  /// All hooks are called directly after the bound Lua function is called,
  /// but before the return values (if any) are sent back to Lua.
  /// \param  f         Function pointer.
  /// \param  name      Fully qualified name to hook.
  //
  /// TO HOOK USING MEMBER FUNCTIONS:
  /// Use the LuaMemberReg mediator class. It will clean up for you.
  template <typename FunPtr>
  void strictHook(FunPtr f, const std::string& name);

  /// Sets the undo function for the registered function specified by 'name'.
  /// The default undo function is to re-execute the last command executed.
  /// E.G. If you execute "fun(1.5)", then "fun(5.5)", then execute an undo,
  ///      the undo will execute fun(1.5) to undo fun(5.5).
  /// If there is no prior command, then the command is called with 'default'
  /// values. Default values are determined by the LuaStrictStack class, or
  /// by the user specifying them using setDefault.
  /// E.G. If an undo is executed again on the example given above, fun(0.0)
  ///      will be executed to undo fun(1.5). 0.0 is the default for a float.
  ///      To reset defaults on a per function basis, use the setDefaults
  ///      family of functions.
  /// \param  f       Function to call. If the function does not have the
  ///                 same signature of the function registered at 'name',
  ///                 a runtime exception will be thrown if RTTI is enabled.
  /// \param  name    The fully qualified name of the function that you wish to
  ///                 reset the undo function for.
  template <typename FunPtr>
  void setUndoFun(FunPtr f, const std::string& name);

  /// Use this function to ensure that no functions are called on undo.
  /// The last executed parameters table is still updated upon undo.
  /// Use this function if you don't know what arguments
  /// the function takes and you would like to nullify its undo/redo
  /// operations. It is used to nullify undo on constructors / destructors
  /// of lua instance classes.
  /// All composited functions are called.
  /// XXX: Could be replaced with a function hook that ignores the function's
  ///      arguments (does not enforce strict argument compliance).
  void setNullUndoFun(const std::string& name);

  /// Sets the redo function for the registered function specified by name.
  /// The default redo is just to re-execute the function with the same args.
  /// The f and name parameters are the exact same as setUndoFun.
  template <typename FunPtr>
  void setRedoFun(FunPtr f, const std::string& name);

  /// Use this function to ensure that no functions are called on redo.
  /// The last executed parameters table is still updated upon redo.
  void setNullRedoFun(const std::string& name);

  /// Registers a Lua class. This method was ultimately chosen due to 3 reasons:
  /// 1) Depending on what registration functions we use, we can potentially
  ///    determine what functions are associated with a particular class
  ///    without having to create an instance of the class.
  /// 2) Gets rid of the pointer stack / id stacks that we setup to support
  ///    function registration in the second method.
  /// 3) Can register classes that know nothing about LuaScripting.
  ///    Particularly useful for not breaking encapsulation. A practical
  ///    example of this is to register the Dataset IO class without IO
  ///    knowing about Tuvok.
  /// \param fp         Pointer to a function that will construct the class and
  ///                   return a pointer to it.
  /// \param className  Fully qualified class name.
  /// \param desc       Class description.
  /// \param callback   Callback issued directly after the constructor is called
  ///                   This callback is tightly bound to the return type of
  ///                   FunPtr. If FunPtr has the return type of T*, then the
  ///                   function signature the callback is:
  ///                   callback(LuaClassRegistration<T>& reg, T* cls);
  /// @{
  template <typename CLS, typename T, typename FunPtr>
  void registerClass(T* t, FunPtr fp, const std::string& className,
                     const std::string& desc,
                     typename LuaClassRegCallback<CLS>::Type callback);

  template <typename CLS, typename FunPtr>
  void registerClassStatic(FunPtr fp, const std::string& className,
                           const std::string& desc,
                           typename LuaClassRegCallback<CLS>::Type callback);
  /// @}

  /// Retrieves the LuaClassInstance given the object pointer.
  /// Only use the pointer that was returned from the class constructor.
  LuaClassInstance getLuaClassInstance(void* p);

  /// Executes a command.
  ///
  /// Example: exec("provenance.undo()")
  ///   or     exec("myFunc(34, "string", ...)")
  void exec(const std::string& cmd);

  /// Executes a command and returns 1 value.
  ///
  /// Example: T a = executeRet<T>("myFunc()")
  template <typename T>
  T execRet(const std::string& cmd);

  /// The following functions allow you to call a function using C++ types.
  /// These function are more efficient than the exec functions given above.
  /// The general form of these functions is given in the below example
  ///
  /// Example: cexec("myFunc", a, b, c, d, ...)
  ///@{
  void cexec(const std::string& cmd);

  // Include the cexec function prototypes.
  TUVOK_LUA_CEXEC_FUNCTIONS
  ///@}

  /// The following functions allow you to call a function using C++ types.
  /// Unlike the functions above, these functions also return the execution
  /// result of the function.
  ///
  /// NOTE: You must match the return type of the function exactly, otherwise
  ///       a runtime exception will be thrown.
  ///
  /// Example: T a = cexecRet<T>("myFunc", p1, p2, ...)
  ///@{
  template <typename T>
  T cexecRet(const std::string& cmd);

  // Include the cexecRet function prototypes.
  TUVOK_LUA_CEXEC_RET_FUNCTIONS
  ///@}

  /// The following functions allow you to specify default parameters to use
  /// for registered functions.
  /// This is so you can specify different undo/redo defaults (such as turning
  /// lighting ON by default).
  /// NOTE: You should call this directly after registering the function (name).
  ///       Waiting to set defaults until after the function has been called
  ///       results in undefined behavior on the undo/redo stack.
  /// \param  name        Fully qualified name of the function whose defaults
  ///                     you would like to set.
  /// \param  callFunc    If true, the function will be called for you with the
  ///                     given parameters.
  /// \param  call        If true, the function indicated by (name) will be
  ///                     called with the given parameters. This call will
  ///                     not be logged with the provenance system.
  ///
  /// Example: setDefaults("myFunc", p1, p2, ... , false)
  ///@{

  // Here is an example function prototype for setDefaults.
  //  template <typename P1>
  //  void setDefaults(const std::string& name,
  //                   P1 p1, bool call);

  // Include setDefaults function prototypes.
  TUVOK_LUA_SETDEFAULTS_FUNCTIONS
  ///@}

  /// TODO: Build the set optional parameters functions.
  ///       Possible signature:
  /// void setOptional(std::string id, int arg, T paramValue);
  /// Lets you specify optional parameters for registered functions.
  /// All optional parameters must be grouped at the end of the parameter list.
  /// Optional parameters are different from defaults in that defaults deal
  /// with undoing the very first call. Whereas, optional parameters
  /// indicate that if certain parameters aren't specified, the parameters
  /// should be filled with the given optional values.

  /// Sets additional parameter information (such as name and description).
  /// \param fqname   Fully qualified name of the function.
  /// \param paramID  Zero based. 0 represents the first parameter, n represents
  ///                 the (n-1)'th parameter.
  /// \param name     The name of the parameter.
  /// \param desc     The description.
  void addParamInfo(const std::string& fqname, int paramID,
                    const std::string& name, const std::string& desc);

  /// Sets additional return value information.
  void addReturnInfo(const std::string& fqname, const std::string& desc);

  /// Default: Provenance is enabled. Disabling provenance will disable undo/
  /// redo.
  bool isProvenanceEnabled() const;
  void enableProvenance(bool enable);

  LuaClassInstance::IDType getCurGlobalInstID() const{return mGlobalInstanceID;}
  void incrementGlobalInstID()    {mGlobalInstanceID++;}

  /// Function description returned from getFuncDescs().
  struct FunctionDesc
  {
    std::string funcName;   ///< Name of the function.
    std::string funcDesc;   ///< Description of the function provided by the
                            ///< registrar.
    std::string paramSig;   ///< Function parameter signature, only parameters.
    std::string funcSig;    ///< Full function signature.
    std::string funcFQName; ///< Fully qualified function name.
  };

  /// Return all function descriptions.
  std::vector<FunctionDesc> getAllFuncDescs() const;

  // Names for data stored in a function's encapsulating table.
  // Exposed for unit testing purposes.
  static const char* TBL_MD_DESC;         ///< Description
  static const char* TBL_MD_SIG;          ///< Signature
  static const char* TBL_MD_SIG_NO_RET;   ///< No name signature without return
  static const char* TBL_MD_SIG_NAME;     ///< Signature with name
  static const char* TBL_MD_NUM_EXEC;     ///< Number of executions
  static const char* TBL_MD_QNAME;        ///< Fully qualified function name
  static const char* TBL_MD_FUN_PDEFS;    ///< Function parameter defaults
  static const char* TBL_MD_FUN_LAST_EXEC;///< Parameters from last execution
  static const char* TBL_MD_HOOKS;        ///< Static function hooks table
  static const char* TBL_MD_HOOK_INDEX;   ///< Static function hook index
  static const char* TBL_MD_MEMBER_HOOKS; ///< Class member function hook table
  static const char* TBL_MD_CPP_CLASS;    ///< Light user data to LuaScripting
  static const char* TBL_MD_STACK_EXEMPT; ///< True if undo/redo stack exempt
  static const char* TBL_MD_PROV_EXEMPT;  ///< True if provenance exempt.
  static const char* TBL_MD_NUM_PARAMS;   ///< Number of parameters accepted.
  static const char* TBL_MD_UNDO_FUNC;    ///< Non-nil if undo hook present.
  static const char* TBL_MD_REDO_FUNC;    ///< Non-nil if redo hook present.
  static const char* TBL_MD_NULL_UNDO;    ///< If true, no undo function
                                          ///< is called.
  static const char* TBL_MD_NULL_REDO;    ///< If true, no redo function
                                          ///< is called.
  static const char* TBL_MD_PARAM_DESC;   ///< Additional parameter descriptions
                                          ///< table.

#ifdef TUVOK_DEBUG_LUA_USE_RTTI_CHECKS
  static const char* TBL_MD_TYPES_TABLE;  ///< type_info userdata table.
#endif

  static const char* PARAM_DESC_NAME_SUFFIX;
  static const char* PARAM_DESC_INFO_SUFFIX;

  static const char* SYSTEM_NOP_COMMAND;  ///< The no-op command.

  /// Sets a flag in the Lua registry indicating that an exception is expected
  /// that will cause the lua stack to be unbalanced in internal functions.
  /// This is to avoid debug log output, more than anything else.
  void setExpectedExceptionFlag(bool expected);

  /// Please do not use this function in production code. It is used for
  /// testing purposes.
  LuaProvenance* getProvenanceSys() const {return mProvenance.get();}

  /// Used for testing purposes only.
  LuaClassInstance::IDType getCurrentClassInstID() {return mGlobalInstanceID;}

  /// Retrieves the last created instance ID
  LuaClassInstance::IDType getLastCreatedInstID(){return mGlobalInstanceID - 1;}

  /// Used by friend class LuaProvenance.
  /// Any public use of this function should be for testing purposes only.
  lua_State* getLuaState() const {return mL;}

  /// Notifies the scripting system of an object's deletion.
  /// Use this function in the object's destructor if you believe deleteClass
  /// was not called on the object (E.G. the object is GUI window, and the user
  /// clicked the close button, and you have no control over the deletion of
  /// the object).
  /// It is safe to call this function repeatedly. You may also call the
  /// function even though deleteClass was called. deleteClass is reentrant for
  /// the same class.
  void notifyOfDeletion(LuaClassInstance inst);

  /// Allows you to temporarily disable the provenance system. This will not
  /// wipe any provenance records, but will allow you to make lua calls without
  /// having them logged by the system.
  /// This function routes to mProvenance->setDisableProvTemporarily(...)
  void setTempProvDisable(bool disable);

  /// This function should be used sparingly, and only for those functions that
  /// do not modify state nor return internal state in some way.
  /// Turns out that we want functions that get called every frame to be
  /// provenance exempt as well. Otherwise the provenance record is useless
  /// and grows too fast (which is a performance concern).
  /// E.G. Debug logging functions should be provenance exempt.
  void setProvenanceExempt(const std::string& fqName);

  /// Returns true if we are running in verbose mode.
  bool isVerbose()    {return mVerboseMode;}

  /// Returns a list of possible completions to the given command.
  std::vector<std::string> completeCommand(const std::string& fqName);

  /// Retrieves the commands 'path'.
  /// E.G. getCmdPath("iv3d.ren.two.get") = "iv3d.ren.two"
  std::string getCmdPath(std::string fqName);

  /// All commands between these two function calls will be grouped together
  /// so that one provenance.undo() command will undo/redo all of them.
  /// @{
  void beginCommandGroup();
  void endCommandGroup();
  /// @}

  /// Verbose print. Prints a message using log.info only if verbose is enabled.
  void vPrint(const char* fmt, ...);

private: // Used by LuaMemberRegUnsafe

  /// Just calls provenance begin/end command.
  void beginCommand();
  void endCommand();

  /// Exec failure.
  void logExecFailure(const std::string& failure);

  /// Stack expectations: the function table at tableIndex, and the parameters
  /// required to call the function directly after the table on the stack.
  /// There must be no other values on the stack above tableIndex other than the
  /// table and the parameters to call the function.
  void doHooks(lua_State* L, int tableIndex, bool provExempt);

  /// Returns true if the function is provenance exempt.
  /// Used to tell whether or not we should log hooks later on.
  bool doProvenanceFromExec(lua_State* L,
                            std::shared_ptr<LuaCFunAbstract> funParams,
                            std::shared_ptr<LuaCFunAbstract> emptyParams);

private:

  template <typename FunPtr>
  void strictHookInternal(FunPtr f,
                          const std::string& name,
                          bool registerUndo,
                          bool registerRedo);

  /// Clears out all function's last exec tables. This is done when the
  /// provenance system is cleared. This even clears every class function's
  /// last exec table -- all tables must be cleared in order to get rid of
  /// dangling shared_ptrs.
  void clearAllLastExecTables();
  void clearLastExecFromTable();  ///< Expects recurse table to be on stack top.

  /// Pushes the table associated with the LuaClassInstance to the top of the
  /// stack. Returns false if it could not find the class instance table.
  bool getClassTable(LuaClassInstance inst);

  /// Ensures the function is not added to the undo/redo stack. Examples include
  /// the undo and redo functions themselves.
  void setUndoRedoStackExempt(const std::string& funcName);

  /// Prepare function for execution (places function on the top of the stack).
  void prepForExecution(const std::string& fqName);

  /// Execute the function on the top of the stack. Works excatly like lua_call.
  void executeFunctionOnStack(int nparams, int nret);

  /// Unregisters the function associated with the fully qualified name.
  void unregisterFunction(const std::string& fqName);

  /// Resets default for function. Value to set as default is assumed to be on
  /// the top of the stack. It is popped off the stack.
  /// \param  argumentPos     Function argument position (e.g. f(1,2,3), 1 is at
  ///                         argument pos 0, 2 at pos 1, and 3 at pos 2).
  /// \param  ftableStackPos  Stack position of the function table.
  void resetFunDefault(int argumentPos, int ftableStackPos);

  /// Unregisters all functions registered using this LuaScripting instance.
  /// Should NEVER be called outside LuaScripting's destructor.
  void unregisterAllFunctions();

  /// Returns a new member hook ID.
  std::string getNewMemberHookID();

  /// Recursive helper function for unregisterAllFunctions().
  /// Expects that the table from which to remove functions is on the top of the
  /// stack.
  /// \param  parentTable If 0, the table is remove from globals if it is a
  ///                     function.
  /// \param  tableName   Name of the table on the top of the stack.
  void removeFunctionsFromTable(int parentTable, const char* tableName);

  /// Returns true if the table at stackIndex is a registered function.
  /// Makes no guarantees that it is a function registered by this class.
  bool isRegisteredFunction(int stackIndex) const;

  /// Returns true if the function table at stackIndex was create by this
  /// LuaScripting class. For now, we create our own unique Lua instance, so
  /// we are guaranteed this, but this is forward thinking for the future
  /// when we need to share the Lua state.
  bool isOurRegisteredFunction(int stackIndex) const;

  /// Returns true if the given fully qualified function name would be stored
  /// in lua globlas.
  bool isGlobalFunction(std::string fqName);

  /// Retrieves the function table given the fully qualified function name.
  /// Places the function table at the top of the stack. If the function fails
  /// to find the function table, false is returned and nothing is pushed
  /// onto the stack.
  /// Note: You can use this function as a generic way of grabbing tables
  ///       at a particular fully qualified name.
  bool getFunctionTable(const std::string& fqName);

  /// Creates a callable Lua table. classInstance can be NULL.
  /// Leaves the table on the top of the Lua stack.
  void createCallableFuncTable(lua_CFunction proxyFunc, void* realFuncToCall);

  /// Populates the table at the given index with the given function metadata.
  void populateWithMetadata(const std::string& name,
                            const std::string& description,
                            const std::string& signature,
                            const std::string& signatureWithName,
                            const std::string& sigNoReturn,
                            int tableIndex);

  /// Creates the defaults and last exec tables and places them inside the
  /// table given at tableIndex.
  /// Expects that the parameters are at the top of the stack.
  void createDefaultsAndLastExecTables(int tableIndex, int numParams);

  /// Binds the closure given at closureIndex to the fully qualified name (fq).
  /// In reality, you can use this function to bind any lua value to the
  /// indicated function name.
  void bindClosureTableWithFQName(const std::string& fqName, int closureIndex);

  /// Retrieves the unqualified name given the qualified name.
  static std::string getUnqualifiedName(const std::string& fqName);

  /// Recursive function helper for getAllFuncDescs.
  void getTableFuncDefs(std::vector<LuaScripting::FunctionDesc>& descs) const;

  /// Retrieve the function description from the given table.
  FunctionDesc getFunctionDescFromTable(int table) const;

  /// Lua panic function. Lua calls this when an unrecoverable error occurs
  /// in the interpreter.
  static int luaPanic(lua_State* L);

  /// Customized memory allocator called from within Lua.
  static void* luaInternalAlloc(void* ud, void* ptr, size_t osize,
                                size_t nsize);

  /// Expects the function table to be given at funTableIndex
  /// Copies the defaults table to the last exec table (used for undo/redo).
  void copyDefaultsTableToLastExec(int funTableIndex);

  /// Expects parameters to start at paramStartIndex. The table to receive the
  /// parameters should be at tableIndex.
  /// Do NOT use psuedo indices for tableIndex or paramStartIndex.
  void copyParamsToTable(int tableIndex, int paramStartIndex, int numParams);

  /// Registers our functions with the scripting system.
  void registerScriptFunctions();

  /// Logs info.
  void logInfo(std::string log);

  /// Logs a warning.
  void logWarn(std::string log);

  /// Logs a failure.
  void logError(std::string log);

  /// Prints all currently registered functions using log.info.
  void printFunctions();

  /// Prints all currently registered functions using log.info.
  void printHelp();

  /// Prints help for the given class instance table.
  std::string getClassHelp(int tableIndex);

  /// Prints help about a specific function given by func.
  void infoHelp(LuaTable table);

  /// Retrieves info about the given table as a string.
  std::string getInfoHelp(LuaTable table);

  /// Delete's a lua class instance. Does not delete a class definition.
  /// Class definitions are permanent.
  void deleteLuaClassInstance(LuaClassInstance inst);

  /// Retrieves a new class instance ID. This function is modified by
  /// setNextTempClassInstRange.
  int getNewClassInstID();

  /// Removes all class instances from the system table.
  void deleteAllClassInstances();

  /// Cleans up class constructors stored in mRegisteredClasses.
  void cleanupClassConstructors();

  /// Deletes the class instance in the table. The table should be removed
  /// and no longer called after this function is executable.
  void destroyClassInstanceTable(int tableIndex);

  /// Retrieves the class' unique ID.
  int getClassUniqueID(LuaClassInstance inst);

  /// Retrieves the class with the given Unique ID.
  LuaClassInstance getClassWithUniqueID(LuaClassInstance::IDType ID);

  /// Used when redoing class instance creation. Ensures that the same id is
  /// used when creating the classes. Starts getNewClassInstID at low, and
  /// when current > high, we move to where we were when creating instance IDs.
  /// \param  low   The lowest instance ID to return when using
  ///               getNewClassInstID.
  /// \param  high  The highest instance
  void setNextTempClassInstRange(LuaClassInstance::IDType low,
                                 LuaClassInstance::IDType high);

  /// Returns true if the path specified points to a class instance.
  bool isLuaClassInstance(int tableIndex);

  /// Registers Lua utility functions, such as dir and os.capture.
  void registerLuaUtilityFunctions();

  /// Enable / disable verbose mode for the scripting system.
  void enableVerboseMode(bool enable);

  /// Performs a correction search given the table in which to search, and the
  /// name within the table. If the name is unique, it will be the only value
  /// in the returned vector of strings.
  std::vector<std::string> performCorrection(int tbl,
                                             const std::string& name);

  /// Lua Registry Values
  ///@{
  /// Expected exception flag. Affects LuaStackRAII, and the logging of errors.
  static const char* REG_EXPECTED_EXCEPTION_FLAG;
  ///@}

  /// The one true Lua state.
  lua_State*                        mL;

  /// List of registered modules/functions in Lua's global table.
  /// Used to iterate through all registered functions.
  std::vector<std::string>          mRegisteredGlobals;

  /// List of registered classes. Needed for cleanup purposes.
  std::vector<std::string>          mRegisteredClasses;

  /// Index used to assign a unique ID to classes that wish to register
  /// hooks.
  int                               mMemberHookIndex;

  /// Current global instance ID that will be used to create new Lua classes.
  LuaClassInstance::IDType          mGlobalInstanceID;
  bool                              mGlobalTempInstRange;
  LuaClassInstance::IDType          mGlobalTempInstLow;
  LuaClassInstance::IDType          mGlobalTempInstHigh;
  LuaClassInstance::IDType          mGlobalTempCurrent;

  std::unique_ptr<LuaProvenance>      mProvenance;
  std::unique_ptr<LuaMemberRegUnsafe> mMemberReg;
  std::unique_ptr<LuaClassConstructor>mClassCons;

  bool                              mVerboseMode;

  /// These structures were created in order to handle void return types easily
  ///@{
  template <typename FunPtr, typename Ret>
  struct LuaCallback
  {
    static int exec(lua_State* L)
    {
      LuaStackRAII _a = LuaStackRAII(L, 0, 1); // 1 return value.

      FunPtr fp = reinterpret_cast<FunPtr>(
          lua_touserdata(L, lua_upvalueindex(1)));

      typename LuaStrictStack<Ret>::Type r;
      if (lua_toboolean(L, lua_upvalueindex(2)) == 0)
      {
        LuaScripting* ss = static_cast<LuaScripting*>(
                    lua_touserdata(L, lua_upvalueindex(3)));

        std::shared_ptr<LuaCFunAbstract> execParams(
            new LuaCFunExec<FunPtr>());
        std::shared_ptr<LuaCFunAbstract> emptyParams(
            new LuaCFunExec<FunPtr>());
        // Fill execParams. Function parameters start at index 2.
        execParams->pullParamsFromStack(L, 2);

        // Obtain reference to LuaScripting in order to invoke provenance.
        // See createCallableFuncTable for justification on pulling an
        // instance of LuaScripting out of Lua.
        bool provExempt = ss->doProvenanceFromExec(L, execParams, emptyParams);

        // We are NOT a hook. Our parameters start at index 2 (because the
        // callable table is at the first index). We will want to call all
        // hooks associated with our table.
        ss->beginCommand();
        try
        {
          r = LuaCFunExec<FunPtr>::run(L, 2, fp);
        }
        catch (std::exception& e)
        {
          ss->endCommand();
          ss->logExecFailure(e.what());
          throw;
        }
        catch (...)
        {
          ss->endCommand();
          ss->logExecFailure("");
          throw;
        }
        ss->endCommand();

        // Call registered hooks.
        // Note: The first parameter on the stack (not on the top, but
        // on the bottom) is the table associated with the function.
        ss->doHooks(L, 1, provExempt);
      }
      else
      {
        // The catching of hook failures is done in doHooks.
        r = LuaCFunExec<FunPtr>::run(L, 1, fp);
      }

      LuaStrictStack<Ret>().push(L, r);
      return 1;
    }
  };

  template <typename FunPtr>
  struct LuaCallback <FunPtr, void>
  {
    static int exec(lua_State* L)
    {
      LuaStackRAII _a = LuaStackRAII(L, 0, 0);

      FunPtr fp = reinterpret_cast<FunPtr>(
          lua_touserdata(L, lua_upvalueindex(1)));
      if (lua_toboolean(L, lua_upvalueindex(2)) == 0)
      {
        LuaScripting* ss = static_cast<LuaScripting*>(
                    lua_touserdata(L, lua_upvalueindex(3)));

        std::shared_ptr<LuaCFunAbstract> execParams(
            new LuaCFunExec<FunPtr>());
        std::shared_ptr<LuaCFunAbstract> emptyParams(
            new LuaCFunExec<FunPtr>());
        // Fill execParams. Function parameters start at index 2.
        execParams->pullParamsFromStack(L, 2);

        bool provExempt = ss->doProvenanceFromExec(L, execParams, emptyParams);

        ss->beginCommand();
        try
        {
          LuaCFunExec<FunPtr>::run(L, 2, fp);
        }
        catch (std::exception& e)
        {
          ss->logExecFailure(e.what());
          ss->endCommand();
          throw;
        }
        catch (...)
        {
          ss->logExecFailure("");
          ss->endCommand();
          throw;
        }
        ss->endCommand();

        ss->doHooks(L, 1, provExempt);
      }
      else
      {
        // The catching of hook failures is done in doHooks.
        LuaCFunExec<FunPtr>::run(L, 1, fp);
      }

      return 0;
    }
  };
  ///@}

};

} // namespace tuvok

// We need to place this here to resolve a circular reference introduced by the
// functions below.
#include "LuaClassConstructor.h"

namespace tuvok
{

template <typename CLS, typename T, typename FunPtr>
void LuaScripting::registerClass(
    T* t, FunPtr fp, const std::string& className,
    const std::string& desc,
    typename LuaClassRegCallback<CLS>::Type callback)
{
  // Register f as the function _new. This function will be called to construct
  // a pointer to the class we want to create. This function is guaranteed
  // to be a static function.
  // Construct 'constructor' table.
  lua_State* L = getLuaState();
  LuaStackRAII _a(L, 0, 0);

  // Register 'new'. This will automatically create the necessary class table.
  std::string fqFunName = className;
  fqFunName += ".new";
  mClassCons->registerMemberConstructor<CLS>(t, fp, fqFunName, desc, true,
                                             callback);
  setNullUndoFun(fqFunName); // We do not want to exe new when undoing
                             // All child undo items are still executed.

  // Since we did the registerConstructor above we will have our function
  // table present.
  if (getFunctionTable(className) == false)
    throw LuaFunBindError("Unable to find table we just built!");

  // Pop function table off stack.
  lua_pop(L, 1);

  // Populate the 'new' function's table with the class definition function,
  // and the full factory name.
  std::ostringstream retNewFun;
  retNewFun << "return " << className << ".new";
  luaL_dostring(mL, retNewFun.str().c_str());

  lua_pushstring(mL, className.c_str());
  lua_setfield(mL, -2, LuaClassConstructor::CONS_MD_FACTORY_NAME);

  // Pop the new function table.
  lua_pop(mL, 1);

  // Store the class in the 'registered class' stack.
  // This stack lets us get rid of the callback pointers stored inside of the
  // 'new' function in the class constructor.
  mRegisteredClasses.push_back(className);
}

template <typename CLS, typename FunPtr>
void LuaScripting::registerClassStatic(
    FunPtr fp, const std::string& className,
    const std::string& desc,
    typename LuaClassRegCallback<CLS>::Type callback)
{
  // Register f as the function _new. This function will be called to construct
  // a pointer to the class we want to create. This function is guaranteed
  // to be a static function.
  // Construct 'constructor' table.
  lua_State* L = getLuaState();
  LuaStackRAII _a(L, 0, 0);

  // Register 'new'. This will automatically create the necessary class table.
  std::string fqFunName = className;
  fqFunName += ".new";
  mClassCons->registerConstructor<CLS>(fp, fqFunName, desc, true, callback);
  setNullUndoFun(fqFunName); // We do not want to exe new when undoing
                             // All child undo items are still executed.

  // Since we did the registerConstructor above we will have our function
  // table present.
  if (getFunctionTable(className) == false)
    throw LuaFunBindError("Unable to find table we just built!");

  // Pop function table off stack.
  lua_pop(L, 1);

  // Populate the 'new' function's table with the class definition function,
  // and the full factory name.
  std::ostringstream retNewFun;
  retNewFun << "return " << className << ".new";
  luaL_dostring(mL, retNewFun.str().c_str());

  lua_pushstring(mL, className.c_str());
  lua_setfield(mL, -2, LuaClassConstructor::CONS_MD_FACTORY_NAME);

  // Pop the new function table.
  lua_pop(mL, 1);

  // Store the class in the 'registered class' stack.
  // This stack lets us get rid of the callback pointers stored inside of the
  // 'new' function in the class constructor.
  mRegisteredClasses.push_back(className);
}

template <typename T>
T LuaScripting::execRet(const std::string& cmd)
{
  LuaStackRAII _a = LuaStackRAII(mL, 0, 0);

  std::string retCmd = "return " + cmd;
  luaL_loadstring(mL, retCmd.c_str());
  lua_call(mL, 0, LUA_MULTRET);
  T ret = LuaStrictStack<T>::get(mL, lua_gettop(mL));
  lua_pop(mL, 1); // Pop return value.
  return ret;
}

template <typename T>
T LuaScripting::cexecRet(const std::string& name)
{
  LuaStackRAII _a = LuaStackRAII(mL, 0, 0);
  prepForExecution(name);
  executeFunctionOnStack(0, 1);
  T ret = LuaStrictStack<T>::get(mL, lua_gettop(mL));
  lua_pop(mL, 1); // Pop return value.
  return ret;
}

#ifdef TUVOK_DEBUG_LUA_USE_RTTI_CHECKS

template <typename T>
void Tuvok_luaCheckParam(lua_State* L, const std::string& name,
                         int typesTable, int check_pos)
{
  LuaStackRAII _a = LuaStackRAII(L, 0, 0);

  lua_pushinteger(L, check_pos++);
  lua_gettable(L, typesTable);
  if (LSS_compareToTypeOnStack<T>(L, -1) == false)
  {
    // Test the one special case (const char* --> std::string)
    if ((   LSS_compareToTypeOnStack<std::string>(L, -1)
         || LSS_compareToTypeOnStack<const char*>(L, -1)))
    {
      if (   LSS_compareTypes<std::string, T>()
          || LSS_compareTypes<const char*, T>())
      {
        lua_pop(L, 1);
        return;
      }
    }

    if (    LSS_compareToTypeOnStack<float>(L, -1)
         || LSS_compareToTypeOnStack<double>(L, -1)
         )
    {
      if (   LSS_compareTypes<float, T>()
          || LSS_compareTypes<double, T>()
          )
      {
        lua_pop(L, 1);
        return;
      }
    }

    if (     LSS_compareToTypeOnStack<int>(L, -1)
        ||   LSS_compareToTypeOnStack<unsigned int>(L, -1)
        )
    {
      if (   LSS_compareTypes<int, T>()
          || LSS_compareTypes<unsigned int, T>()
          )
      {
        lua_pop(L, 1);
        return;
      }
    }

    std::ostringstream os;
    os << "Invalid argument at position " << check_pos;
    os << " for call to function " << name;
    throw LuaInvalidType(os.str().c_str());
  }
  lua_pop(L, 1);
}

#endif

// Include cexec/cexecRet/setDefaults function bodies
#include "LuaScriptingExecBody.h"

template <typename FunPtr>
std::string LuaScripting::registerFunction(FunPtr f, const std::string& name,
                                           const std::string& desc,
                                           bool undoRedo)
{
  LuaStackRAII _a = LuaStackRAII(mL, 0, 0);

  // Idea: Build a 'callable' table.
  // Its metatable will have a __call metamethod that points to the C
  // function closure.

  // We do this because all metatables are unique per-type which eliminates
  // the possibilty of using a metatable on the function closure itself.
  // The only exception to this rule is the table type itself.

  // Create a callable function table and leave it on the stack.
  lua_CFunction proxyFunc = &LuaCallback<FunPtr, typename
      LuaCFunExec<FunPtr>::returnType>::exec;
  createCallableFuncTable(proxyFunc, reinterpret_cast<void*>(f));

  int tableIndex = lua_gettop(mL);

  // Add function metadata to the table.
  std::string sig = LuaCFunExec<FunPtr>::getSignature("");
  std::string sigWithName = LuaCFunExec<FunPtr>::getSignature(
      getUnqualifiedName(name));
  std::string sigNoRet = LuaCFunExec<FunPtr>::getSigNoReturn("");
  populateWithMetadata(name, desc, sig, sigWithName, sigNoRet, tableIndex);

  // Push default values for function parameters onto the stack.
  LuaCFunExec<FunPtr> defaultParams = LuaCFunExec<FunPtr>();
  lua_checkstack(mL, LUAC_MAX_NUM_PARAMS + 2);
  defaultParams.pushParamsToStack(mL);
  int numFunParams = lua_gettop(mL) - tableIndex;
  createDefaultsAndLastExecTables(tableIndex, numFunParams);
  lua_pushinteger(mL, numFunParams);
  lua_setfield(mL, tableIndex, TBL_MD_NUM_PARAMS);

#ifdef TUVOK_DEBUG_LUA_USE_RTTI_CHECKS
  // Generate the type table (buildTypeTable places table on top of the stack).
  LuaCFunExec<FunPtr>::buildTypeTable(mL);
  lua_setfield(mL, tableIndex, TBL_MD_TYPES_TABLE);
#endif

  // Install the callable table in the appropriate module based on its
  // fully qualified name.
  bindClosureTableWithFQName(name, tableIndex);

  lua_pop(mL, 1);   // Pop the callable table.

  if (undoRedo == false)  setUndoRedoStackExempt(name);

  return name;
}

template <typename FunPtr>
void LuaScripting::strictHookInternal(
    FunPtr f,
    const std::string& name,
    bool registerUndo,
    bool registerRedo)
{
  LuaStackRAII _a = LuaStackRAII(mL, 0, 0);

  // Need to check the signature of the function that we are trying to bind
  // into the script system.
  if (getFunctionTable(name) == false)
  {
    throw LuaNonExistantFunction("Unable to find function with which to"
                                 "associate a hook.");
  }

  int funcTable = lua_gettop(mL);

  // Check function signatures.
  lua_getfield(mL, funcTable, TBL_MD_SIG_NO_RET);
  std::string sigReg = lua_tostring(mL, -1);
  std::string sigHook = LuaCFunExec<FunPtr>::getSigNoReturn("");
  if (sigReg.compare(sigHook) != 0)
  {
    std::ostringstream os;
    os << "Hook's parameter signature and the parameter signature of the "
          "function to hook must match. Hook's signature: \"" << sigHook <<
          "\"Function to hook's signature: " << sigReg;
    throw LuaInvalidFunSignature(os.str().c_str());
  }
  lua_pop(mL, 1);

  // Obtain hook table.
  lua_getfield(mL, -1, TBL_MD_HOOKS);
  int hookTable = lua_gettop(mL);

  bool regUndoRedo = (registerUndo || registerRedo);
  std::ostringstream os;
  if (!regUndoRedo)
  {
    // Generate a hook descriptor (we make it a name as opposed to a natural
    // number because we want Lua to use the hash table implementation behind
    // the scenes, not the array table).
    lua_getfield(mL, funcTable, TBL_MD_HOOK_INDEX);
    int hookIndex = lua_tointeger(mL, -1);
    os << "h" << hookIndex;
    lua_pop(mL, 1);
    lua_pushinteger(mL, hookIndex + 1);
    lua_setfield(mL, funcTable, TBL_MD_HOOK_INDEX);
  }

  // Push closure
  lua_CFunction proxyFunc = &LuaCallback<FunPtr, typename
          LuaCFunExec<FunPtr>::returnType>::exec;
  lua_pushlightuserdata(mL, reinterpret_cast<void*>(f));
  lua_pushboolean(mL, 1);  // We ARE a hook. This affects the stack, and
                           // whether we want to perform provenance.
  // As a hook, we don't need to add mScriptSystem to the closure, since
  // we don't perform provenance on hooks.
  lua_pushcclosure(mL, proxyFunc, 2);

  if (!regUndoRedo)
  {
    // Associate closure with hook table.
    lua_setfield(mL, hookTable, os.str().c_str());
  }
  else
  {
    std::string fieldToQuery = LuaScripting::TBL_MD_UNDO_FUNC;
    bool isUndo = true;

    if (registerRedo)
    {
      fieldToQuery = LuaScripting::TBL_MD_REDO_FUNC;
      isUndo = false;
    }

    lua_getfield(mL, funcTable, fieldToQuery.c_str());

    if (lua_isnil(mL, -1) == 0)
    {
      if (isUndo) throw LuaUndoFuncAlreadySet("Undo function already set.");
      else        throw LuaRedoFuncAlreadySet("Redo function already set.");
    }

    lua_pop(mL, 1);
    lua_setfield(mL, funcTable, fieldToQuery.c_str());
  }

  lua_pop(mL, 2);  // Remove the function table and the hooks table.
}

template <typename FunPtr>
void LuaScripting::strictHook(FunPtr f, const std::string& name)
{
  strictHookInternal(f, name, false, false);
}

template <typename FunPtr>
void LuaScripting::setUndoFun(FunPtr f, const std::string& name)
{
  // Uses strict hook.
  strictHookInternal(f, name, true, false);
}

template <typename FunPtr>
void LuaScripting::setRedoFun(FunPtr f, const std::string& name)
{
  // Uses strict hook.
  strictHookInternal(f, name, false, true);
}

} /* namespace tuvok */
#endif /* LUASCRIPTING_H_ */


text:
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace AppUpdate
{
    public class GitHubReleaseMsiProvider : IMsiProvider
    {
        private const string ApiUrl = "https://api.github.com";

        private readonly string _owner;
        private readonly string _repository;

        private string LatestReleaseUrl => $"{ApiUrl}/repos/{_owner}/{_repository}/releases/latest";

        public GitHubReleaseMsiProvider(string owner, string repository)
        {
            _owner = owner;
            _repository = repository;
        }

        public async Task<bool> CheckIfNewVersionIsAvailable(Version currentVersion)
        {
            try
            {
                var release = await DownloadLatestRelease();
                return release.Version > currentVersion;
            }
            catch (Exception ex)
            {
                //todo log
                return false;
            }
        }

        public async Task DownloadLatestVersion(string destinationFile)
        {
            try
            {
                var release = await DownloadLatestRelease();
                await DownloadMsiFromUrl(release.Assets[0].DownloadUrl, destinationFile);

            }
            catch (Exception ex)
            {
                //todo log
            }
        }

        private async Task<GitHubRelease> DownloadLatestRelease()
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "AppUpdate");
                var response = await client.GetAsync(LatestReleaseUrl);
                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();
                var release = JsonConvert.DeserializeObject<GitHubRelease>(content);
                return release;
            }
        }

        private static async Task DownloadMsiFromUrl(string downloadUrl, string destinationFile)
        {
            using (var client = new WebClient())
            {
                var uri = new Uri(downloadUrl);
                await client.DownloadFileTaskAsync(uri, destinationFile);
            }
        }

        private class GitHubRelease
        {
            [JsonProperty("tag_name")]
            public string TagName { get; set; }

            [JsonProperty("assets")]
            public GitHubAsset[] Assets { get; set; }

            [JsonIgnore]
            public Version Version
            {
                get
                {
                    var version = TagName.StartsWith("v") ? TagName.Substring(1) : TagName;
                    var result = new Version(version);
                    return result;
                }
            }
        }

        private class GitHubAsset
        {
            [JsonProperty("browser_download_url")]
            public string DownloadUrl { get; set; }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>com.tencent.mm</groupId>
  <artifactId>AndResGuard-gradle-plugin</artifactId>
  <versioning>
    <release>1.3</release>
    <versions>
      <version>1.3</version>
    </versions>
    <lastUpdated>20190115090434</lastUpdated>
  </versioning>
</metadata>


text:
using Isaasoft.Core.Rss.Version2_0;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Isaasoft.Bugatti.Podcast.WebAPI.Models
{
    public class RssItemHash
    {
        public string HashKey { get; set; }

        public Item TheItem { get; set; }

        public string TitleComplexMetaphone { get; set; }

        public string SummaryComplexMetaphone { get; set; }
    }
}


text:
package org.apache.activemq.apollo.openwire.command;

import org.apache.activemq.apollo.util.IntrospectionSupport;

import java.util.Map;

/**
 *
 * @openwire:marshaller
 * @version $Revision: 1.11 $
 */
public abstract class BaseCommand implements Command {

    protected int commandId;
    protected boolean responseRequired;

    public void copy(BaseCommand copy) {
        copy.commandId = commandId;
        copy.responseRequired = responseRequired;
    }

    /**
     * @openwire:property version=1
     */
    public int getCommandId() {
        return commandId;
    }

    public void setCommandId(int commandId) {
        this.commandId = commandId;
    }

    /**
     * @openwire:property version=1
     */
    public boolean isResponseRequired() {
        return responseRequired;
    }

    public void setResponseRequired(boolean responseRequired) {
        this.responseRequired = responseRequired;
    }

    public String toString() {
        return toString(null);
    }

    public String toString(Map<String, Object>overrideFields) {
    	return IntrospectionSupport.simpleName(this.getClass()) + " " +
               IntrospectionSupport.toString(this, BaseCommand.class, false, overrideFields);
    }

    public boolean isWireFormatInfo() {
        return false;
    }

    public boolean isBrokerInfo() {
        return false;
    }

    public boolean isResponse() {
        return false;
    }

    public boolean isMessageDispatch() {
        return false;
    }

    public boolean isMessage() {
        return false;
    }

    public boolean isMarshallAware() {
        return false;
    }

    public boolean isMessageAck() {
        return false;
    }

    public boolean isMessageDispatchNotification() {
        return false;
    }

    public boolean isShutdownInfo() {
        return false;
    }

}


text:
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

public class Challenge4 extends Applet
    implements ActionListener
{

    public void stop()
    {
    }

    private String decrypt(String target, String phrase)
    {
        for(; target.length() > phrase.length(); phrase += phrase);
        String s1 = "";
        for(int i = 0; i < target.length(); i++)
            s1 = s1 + "" + (char)(target.charAt(i) - phrase.charAt(i) - i);

        return s1;
    }

    public Challenge4()
    {
        SubmitButton = null;
        PasswordField = null;
        SubmitButton = null;
        PasswordField = null;
        SubmitButton = new Button();
        PasswordField = new TextField("", 8);
    }

    public void destroy()
    {
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        String pass = PasswordField.getText();
        String base = getDocumentBase().toString();
        char urlchars[] = {
            '\301', '\317', '\310', '\332', '\227', '\351', '\271', '\334'
        };
        String crypturl = new String(urlchars);
        char passchars[] = {
            '\u0114', '\u0135', '\u012D', '\u014F', '\u0100', '\u0162', '\u010A', '\u0148', '\u0142'
        };
        String cryptpass = new String(passchars);
        String newurl = "";
        String newpass = "";
        newpass = encrypt(pass, crypturl);
        crypturl = decrypt(crypturl, pass);
        base = base.substring(0, base.lastIndexOf('/') + 1);
        if(newpass.compareTo(cryptpass) == 0)
            newurl = base + crypturl;
        else
            newurl = base + "level104.php";
        try
        {
            getAppletContext().showDocument(new URL(newurl), "_self");
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }

    public void start()
    {
    }

    private String encrypt(String target, String phrase)
    {
        for(; target.length() > phrase.length(); phrase += phrase);
        String s1 = "";
        for(int i = 0; i < target.length(); i++)
            s1 = s1 + "" + (char)(target.charAt(i) + phrase.charAt(i) + i);

        return s1;
    }

    public void init()
    {
        SubmitButton.setLabel("submit");
        SubmitButton.addActionListener(this);
        PasswordField.setEchoChar('*');
        PasswordField.setForeground(new Color(192, 192, 192));
        add(PasswordField);
        add(SubmitButton);
        setBackground(new Color(0, 0, 0));
    }

    private Button SubmitButton;
    private TextField PasswordField;
}


text:
module.exports = {
  oscarApp: {
    src: 'components/**/**.html',
    dest: 'scripts/js/app.templates.js',
    options: {
      htmlmin: {
        collapseWhitespace: true,
        collapseInlineTagWhitespace: true,
        minifyCSS: true,
        minifyJS: {
          mangle: false,
          compress: true
        },
        removeComments: true,
        preserveLineBreaks: true,
        conservativeCollapse: true
      }
    }
  }
};


text:
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.omnibox.suggestions.base;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.AccessibilityDelegate;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.widget.ImageView;

import androidx.annotation.ColorRes;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.view.ViewCompat;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.browser.omnibox.R;
import org.chromium.chrome.browser.omnibox.styles.OmniboxResourceProvider;
import org.chromium.chrome.browser.omnibox.suggestions.SuggestionCommonProperties;
import org.chromium.chrome.browser.omnibox.suggestions.base.BaseSuggestionViewProperties.Action;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor.ViewBinder;

import java.util.List;

/**
 * Binds base suggestion view properties.
 *
 * This binder should be used by all suggestions that also utilize BaseSuggestionView<T> to
 * construct the view, and manages shared suggestion properties (such as decorations or theme).
 *
 * @param <T> The inner content view type being updated.
 */
public final class BaseSuggestionViewBinder<T extends View>
        implements ViewBinder<PropertyModel, BaseSuggestionView<T>, PropertyKey> {
    private final ViewBinder<PropertyModel, T, PropertyKey> mContentBinder;

    public BaseSuggestionViewBinder(ViewBinder<PropertyModel, T, PropertyKey> contentBinder) {
        mContentBinder = contentBinder;
    }

    @Override
    public void bind(PropertyModel model, BaseSuggestionView<T> view, PropertyKey propertyKey) {
        mContentBinder.bind(model, view.getContentView(), propertyKey);

        if (BaseSuggestionViewProperties.ICON == propertyKey) {
            updateSuggestionIcon(model, view);
            updateContentViewPadding(model, view.getDecoratedSuggestionView());
        } else if (SuggestionCommonProperties.LAYOUT_DIRECTION == propertyKey) {
            ViewCompat.setLayoutDirection(
                    view, model.get(SuggestionCommonProperties.LAYOUT_DIRECTION));
            updateContentViewPadding(model, view.getDecoratedSuggestionView());
        } else if (SuggestionCommonProperties.OMNIBOX_THEME == propertyKey) {
            updateColorScheme(model, view);
        } else if (BaseSuggestionViewProperties.ACTIONS == propertyKey) {
            bindActionButtons(model, view, model.get(BaseSuggestionViewProperties.ACTIONS));
        } else if (BaseSuggestionViewProperties.ON_FOCUS_VIA_SELECTION == propertyKey) {
            view.setOnFocusViaSelectionListener(
                    model.get(BaseSuggestionViewProperties.ON_FOCUS_VIA_SELECTION));
        } else if (BaseSuggestionViewProperties.ON_CLICK == propertyKey) {
            Runnable listener = model.get(BaseSuggestionViewProperties.ON_CLICK);
            if (listener == null) {
                view.getDecoratedSuggestionView().setOnClickListener(null);
            } else {
                view.getDecoratedSuggestionView().setOnClickListener(v -> listener.run());
            }
        } else if (BaseSuggestionViewProperties.ON_LONG_CLICK == propertyKey) {
            Runnable listener = model.get(BaseSuggestionViewProperties.ON_LONG_CLICK);
            if (listener == null) {
                view.getDecoratedSuggestionView().setOnLongClickListener(null);
            } else {
                view.getDecoratedSuggestionView().setOnLongClickListener(v -> {
                    listener.run();
                    return true;
                });
            }
        }
    }

    /** Bind Action Icons for the suggestion view. */
    private static <T extends View> void bindActionButtons(
            PropertyModel model, BaseSuggestionView<T> view, List<Action> actions) {
        final int actionCount = actions != null ? actions.size() : 0;
        view.setActionButtonsCount(actionCount);

        // Drawable retrieved once here (expensive) and will be copied multiple times (cheap).
        Drawable backgroundDrawable = getSelectableBackgroundDrawable(view, model);
        final List<ImageView> actionViews = view.getActionButtons();
        for (int index = 0; index < actionCount; index++) {
            final ImageView actionView = actionViews.get(index);
            final Action action = actions.get(index);
            actionView.setOnClickListener(v -> action.callback.run());
            actionView.setContentDescription(action.accessibilityDescription);
            actionView.setBackground(copyDrawable(backgroundDrawable));
            updateIcon(actionView, action.icon,
                    ChromeColors.getPrimaryIconTintRes(!useDarkColors(model)));

            actionView.setAccessibilityDelegate(new AccessibilityDelegate() {
                @Override
                public void onInitializeAccessibilityNodeInfo(
                        View host, AccessibilityNodeInfo info) {
                    super.onInitializeAccessibilityNodeInfo(host, info);
                    info.addAction(AccessibilityAction.ACTION_CLICK);
                }

                @Override
                public boolean performAccessibilityAction(
                        View host, int accessibilityAction, Bundle arguments) {
                    if (accessibilityAction == AccessibilityNodeInfo.ACTION_CLICK
                            && action.onClickAnnouncement != null) {
                        actionView.announceForAccessibility(action.onClickAnnouncement);
                    }
                    return super.performAccessibilityAction(host, accessibilityAction, arguments);
                }
            });
        }
    }

    /** Update visual theme to reflect dark mode UI theme update. */
    private static <T extends View> void updateColorScheme(
            PropertyModel model, BaseSuggestionView<T> view) {
        updateSuggestionIcon(model, view);
        Drawable backgroundDrawable = getSelectableBackgroundDrawable(view, model);
        view.getDecoratedSuggestionView().setBackground(backgroundDrawable);

        final List<Action> actions = model.get(BaseSuggestionViewProperties.ACTIONS);
        // Setting ACTIONS and updating actionViews can happen later. Appropriate color scheme will
        // be applied then.
        if (actions == null) return;

        final List<ImageView> actionViews = view.getActionButtons();
        for (int index = 0; index < actionViews.size(); index++) {
            ImageView actionView = actionViews.get(index);
            actionView.setBackground(copyDrawable(backgroundDrawable));
            updateIcon(actionView, actions.get(index).icon,
                    ChromeColors.getPrimaryIconTintRes(!useDarkColors(model)));
        }
    }

    /** @return Whether currently used color scheme is considered to be dark. */
    private static boolean useDarkColors(PropertyModel model) {
        return !OmniboxResourceProvider.isDarkMode(
                model.get(SuggestionCommonProperties.OMNIBOX_THEME));
    }

    /** Update attributes of decorated suggestion icon. */
    private static <T extends View> void updateSuggestionIcon(
            PropertyModel model, BaseSuggestionView<T> baseView) {
        final ImageView rciv = baseView.getSuggestionImageView();
        final SuggestionDrawableState sds = model.get(BaseSuggestionViewProperties.ICON);

        if (sds != null) {
            final Resources res = rciv.getContext().getResources();
            final int paddingStart = res.getDimensionPixelSize(sds.isLarge
                            ? R.dimen.omnibox_suggestion_36dp_icon_margin_start
                            : R.dimen.omnibox_suggestion_24dp_icon_margin_start);
            final int paddingEnd = res.getDimensionPixelSize(sds.isLarge
                            ? R.dimen.omnibox_suggestion_36dp_icon_margin_end
                            : R.dimen.omnibox_suggestion_24dp_icon_margin_end);
            final int edgeSize = res.getDimensionPixelSize(sds.isLarge
                            ? R.dimen.omnibox_suggestion_36dp_icon_size
                            : R.dimen.omnibox_suggestion_24dp_icon_size);

            rciv.setPadding(paddingStart, 0, paddingEnd, 0);
            rciv.setMinimumHeight(edgeSize);
            rciv.setClipToOutline(sds.useRoundedCorners);
        }

        updateIcon(rciv, sds, ChromeColors.getSecondaryIconTintRes(!useDarkColors(model)));
    }

    /**
     * Update content view padding.
     * This is required only to adjust the leading padding for undecorated suggestions.
     * TODO(crbug.com/1019937): remove after suggestion favicons are launched.
     */
    private static <T extends View> void updateContentViewPadding(
            PropertyModel model, DecoratedSuggestionView<T> view) {
        final SuggestionDrawableState sds = model.get(BaseSuggestionViewProperties.ICON);
        final int startSpace = sds == null ? view.getResources().getDimensionPixelSize(
                                       R.dimen.omnibox_suggestion_start_offset_without_icon)
                                           : 0;

        // TODO(ender): Drop this view and expand the last icon size by 8dp to ensure it remains
        // centered with the omnibox "Clear" button.
        final int endSpace = view.getResources().getDimensionPixelSize(
                R.dimen.omnibox_suggestion_refine_view_modern_end_padding);
        view.setPaddingRelative(startSpace, 0, endSpace, 0);
    }

    /**
     * Retrieves selecatable background drawable from resources. If possible prefer
     * {@link #copyDrawable(Drawable)} over this operation, as it offers an order of magnitude
     * better performance in incognito.
     * The drawable should be used only once, all other uses should make a copy.
     *
     * @param view A view that provides context.
     * @param model A property model to look up relevant properties.
     * @return A selectable background drawable.
     */
    private static Drawable getSelectableBackgroundDrawable(View view, PropertyModel model) {
        return OmniboxResourceProvider.resolveAttributeToDrawable(view.getContext(),
                model.get(SuggestionCommonProperties.OMNIBOX_THEME),
                R.attr.selectableItemBackground);
    }

    /**
     * Creates a copy of the drawable. The drawable should be used only once, all other uses should
     * make a copy.
     *
     * @param original Original drawable to be copied.
     * @return Copied drawable.
     */
    private static Drawable copyDrawable(Drawable original) {
        return original.getConstantState().newDrawable();
    }

    /** Update image view using supplied drawable state object. */
    private static void updateIcon(
            ImageView view, SuggestionDrawableState sds, @ColorRes int tintRes) {
        final Resources res = view.getContext().getResources();

        view.setVisibility(sds == null ? View.GONE : View.VISIBLE);
        if (sds == null) {
            // Release any drawable that is still attached to this view to reclaim memory.
            view.setImageDrawable(null);
            return;
        }

        ColorStateList tint = null;
        if (sds.allowTint) {
            tint = AppCompatResources.getColorStateList(view.getContext(), tintRes);
        }

        view.setImageDrawable(sds.drawable);
        ApiCompatibilityUtils.setImageTintList(view, tint);
    }
}


text:
package com.ibm.icu.dev.test.timezone;

import java.util.Date;

import com.ibm.icu.dev.test.TestFmwk;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.util.AnnualTimeZoneRule;
import com.ibm.icu.util.BasicTimeZone;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.DateTimeRule;
import com.ibm.icu.util.GregorianCalendar;
import com.ibm.icu.util.InitialTimeZoneRule;
import com.ibm.icu.util.RuleBasedTimeZone;
import com.ibm.icu.util.SimpleTimeZone;
import com.ibm.icu.util.TimeZone;

/**
 * Testing getOffset APIs using local time
 */
public class TimeZoneOffsetLocalTest extends TestFmwk {

    public static void main(String[] args) throws Exception {
        new TimeZoneOffsetLocalTest().run(args);
    }

    /*
     * Testing getOffset APIs around rule transition by local standard/wall time.
     */
    public void TestGetOffsetAroundTransition() {
        final int HOUR = 60*60*1000;
        final int MINUTE = 60*1000;

        int[][] DATES = {
            {2006, Calendar.APRIL, 2, 1, 30, 1*HOUR+30*MINUTE},
            {2006, Calendar.APRIL, 2, 2, 00, 2*HOUR},
            {2006, Calendar.APRIL, 2, 2, 30, 2*HOUR+30*MINUTE},
            {2006, Calendar.APRIL, 2, 3, 00, 3*HOUR},
            {2006, Calendar.APRIL, 2, 3, 30, 3*HOUR+30*MINUTE},
            {2006, Calendar.OCTOBER, 29, 0, 30, 0*HOUR+30*MINUTE},
            {2006, Calendar.OCTOBER, 29, 1, 00, 1*HOUR},
            {2006, Calendar.OCTOBER, 29, 1, 30, 1*HOUR+30*MINUTE},
            {2006, Calendar.OCTOBER, 29, 2, 00, 2*HOUR},
            {2006, Calendar.OCTOBER, 29, 2, 30, 2*HOUR+30*MINUTE},
        };

        // Expected offsets by getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
        int[] OFFSETS1 = {
            // April 2, 2006
            -8*HOUR,
            -7*HOUR,
            -7*HOUR,
            -7*HOUR,
            -7*HOUR,

            // October 29, 2006
            -7*HOUR,
            -8*HOUR,
            -8*HOUR,
            -8*HOUR,
            -8*HOUR,
        };

        // Expected offsets by getOffset(long time, boolean local, int[] offsets) with local = true
        // or getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_STD/duplicatedTimeOpt = LOCAL_STD
        int[][] OFFSETS2 = {
            // April 2, 2006
            {-8*HOUR, 0},
            {-8*HOUR, 0},
            {-8*HOUR, 0},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},

            // Oct 29, 2006
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 0},
            {-8*HOUR, 0},
            {-8*HOUR, 0},
            {-8*HOUR, 0},
        };

        // Expected offsets by getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_DST/duplicatedTimeOpt = LOCAL_DST
        int[][] OFFSETS3 = {
            // April 2, 2006
            {-8*HOUR, 0},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},

            // October 29, 2006
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 1*HOUR},
            {-8*HOUR, 0},
            {-8*HOUR, 0},
        };

        int[] offsets = new int[2];

        TimeZone utc = TimeZone.getTimeZone("UTC");
        Calendar cal = Calendar.getInstance(utc);
        cal.clear();

        // Set up TimeZone objects - OlsonTimeZone, SimpleTimeZone and RuleBasedTimeZone
        BasicTimeZone[] TESTZONES = new BasicTimeZone[3];

        TESTZONES[0] = (BasicTimeZone)TimeZone.getTimeZone("America/Los_Angeles", TimeZone.TIMEZONE_ICU);
        TESTZONES[1] = new SimpleTimeZone(-8*HOUR, "Simple Pacific Time",
                                            Calendar.APRIL, 1, Calendar.SUNDAY, 2*HOUR,
                                            Calendar.OCTOBER, -1, Calendar.SUNDAY, 2*HOUR);

        InitialTimeZoneRule ir = new InitialTimeZoneRule(
                "Pacific Standard Time", // Initial time Name
                -8*HOUR,        // Raw offset
                0*HOUR);        // DST saving amount

        RuleBasedTimeZone rbPT = new RuleBasedTimeZone("Rule based Pacific Time", ir);

        DateTimeRule dtr;
        AnnualTimeZoneRule atzr;
        final int STARTYEAR = 2000;

        dtr = new DateTimeRule(Calendar.APRIL, 1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME); // 1st Sunday in April, at 2AM wall time
        atzr = new AnnualTimeZoneRule("Pacific Daylight Time",
                -8*HOUR /* rawOffset */, 1*HOUR /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbPT.addTransitionRule(atzr);

        dtr = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY,
                2*HOUR, DateTimeRule.WALL_TIME); // last Sunday in October, at 2AM wall time
        atzr = new AnnualTimeZoneRule("Pacific Standard Time",
                -8*HOUR /* rawOffset */, 0 /* dstSavings */, dtr,
                STARTYEAR, AnnualTimeZoneRule.MAX_YEAR);
        rbPT.addTransitionRule(atzr);

        TESTZONES[2] = rbPT;

        // Calculate millis
        long [] MILLIS = new long[DATES.length];
        for (int i = 0; i < DATES.length; i++) {
            cal.clear();
            cal.set(DATES[i][0], DATES[i][1], DATES[i][2], DATES[i][3], DATES[i][4]);
            MILLIS[i] = cal.getTimeInMillis();
        }

        DateFormat df = DateFormat.getInstance();
        df.setTimeZone(utc);

        // Test getOffset(int era, int year, int month, int day, int dayOfWeek, int millis)
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int d = 0; d < DATES.length; d++) {
                int offset = TESTZONES[i].getOffset(GregorianCalendar.AD, DATES[d][0], DATES[d][1], DATES[d][2],
                                                    Calendar.SUNDAY, DATES[d][5]);
                if (offset != OFFSETS1[d]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[d])) + "(standard) - Got: " + offset + " Expected: " + OFFSETS1[d]);
                }
            }
        }

        // Test getOffset(long time, boolean local, int[] offsets) with local=true
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int m = 0; m < MILLIS.length; m++) {
                TESTZONES[i].getOffset(MILLIS[m], true, offsets);
                if (offsets[0] != OFFSETS2[m][0] || offsets[1] != OFFSETS2[m][1]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[m])) + "(wall) - Got: "
                            + offsets[0] + "/" + offsets[1]
                            + " Expected: " + OFFSETS2[m][0] + "/" + OFFSETS2[m][1]);
                }
            }
        }

        // Test getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_STD/duplicatedTimeOpt = LOCAL_STD
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int m = 0; m < MILLIS.length; m++) {
                TESTZONES[i].getOffsetFromLocal(MILLIS[m], BasicTimeZone.LOCAL_STD, BasicTimeZone.LOCAL_STD, offsets);
                if (offsets[0] != OFFSETS2[m][0] || offsets[1] != OFFSETS2[m][1]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[m])) + "(wall/STD/STD) - Got: "
                            + offsets[0] + "/" + offsets[1]
                            + " Expected: " + OFFSETS2[m][0] + "/" + OFFSETS2[m][1]);
                }
            }
        }

        // Test getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_DST/duplicatedTimeOpt = LOCAL_DST
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int m = 0; m < MILLIS.length; m++) {
                TESTZONES[i].getOffsetFromLocal(MILLIS[m], BasicTimeZone.LOCAL_DST, BasicTimeZone.LOCAL_DST, offsets);
                if (offsets[0] != OFFSETS3[m][0] || offsets[1] != OFFSETS3[m][1]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[m])) + "(wall/DST/DST) - Got: "
                            + offsets[0] + "/" + offsets[1]
                            + " Expected: " + OFFSETS3[m][0] + "/" + OFFSETS3[m][1]);
                }
            }
        }

        // Test getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_FORMER/duplicatedTimeOpt = LOCAL_LATTER
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int m = 0; m < MILLIS.length; m++) {
                TESTZONES[i].getOffsetFromLocal(MILLIS[m], BasicTimeZone.LOCAL_FORMER, BasicTimeZone.LOCAL_LATTER, offsets);
                if (offsets[0] != OFFSETS2[m][0] || offsets[1] != OFFSETS2[m][1]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[m])) + "(wall/FORMER/LATTER) - Got: "
                            + offsets[0] + "/" + offsets[1]
                            + " Expected: " + OFFSETS2[m][0] + "/" + OFFSETS2[m][1]);
                }
            }
        }

        // Test getOffsetFromLocal(long time, int nonExistingTimeOpt, int duplicatedTimeOpt, int[] offsets)
        // with nonExistingTimeOpt = LOCAL_LATTER/duplicatedTimeOpt = LOCAL_FORMER
        for (int i = 0; i < TESTZONES.length; i++) {
            for (int m = 0; m < MILLIS.length; m++) {
                TESTZONES[i].getOffsetFromLocal(MILLIS[m], BasicTimeZone.LOCAL_LATTER, BasicTimeZone.LOCAL_FORMER, offsets);
                if (offsets[0] != OFFSETS3[m][0] || offsets[1] != OFFSETS3[m][1]) {
                    errln("Bad offset returned by " + TESTZONES[i].getID() + " at "
                            + df.format(new Date(MILLIS[m])) + "(wall/LATTER/FORMER) - Got: "
                            + offsets[0] + "/" + offsets[1]
                            + " Expected: " + OFFSETS3[m][0] + "/" + OFFSETS3[m][1]);
                }
            }
        }
    }
}


text:
// This class has been generated, DO NOT EDIT!

package org.tensorflow.op.data;

import java.util.Arrays;
import org.tensorflow.GraphOperation;
import org.tensorflow.Operand;
import org.tensorflow.Operation;
import org.tensorflow.OperationBuilder;
import org.tensorflow.op.RawOp;
import org.tensorflow.op.RawOpInputs;
import org.tensorflow.op.Scope;
import org.tensorflow.op.annotation.Endpoint;
import org.tensorflow.op.annotation.OpInputsMetadata;
import org.tensorflow.op.annotation.OpMetadata;
import org.tensorflow.types.family.TType;

/**
 * Set a summary_writer_interface to record statistics using given stats_aggregator.
 */
@OpMetadata(
    opType = StatsAggregatorSetSummaryWriter.OP_NAME,
    inputsClass = StatsAggregatorSetSummaryWriter.Inputs.class
)
public final class StatsAggregatorSetSummaryWriter extends RawOp {
  /**
   * The name of this op, as known by TensorFlow core engine
   */
  public static final String OP_NAME = "StatsAggregatorSetSummaryWriter";

  public StatsAggregatorSetSummaryWriter(Operation operation) {
    super(operation, OP_NAME);
  }

  /**
   * Factory method to create a class wrapping a new StatsAggregatorSetSummaryWriter operation.
   *
   * @param scope current scope
   * @param statsAggregator The statsAggregator value
   * @param summary The summary value
   * @return a new instance of StatsAggregatorSetSummaryWriter
   */
  @Endpoint(
      describeByClass = true
  )
  public static StatsAggregatorSetSummaryWriter create(Scope scope,
      Operand<? extends TType> statsAggregator, Operand<? extends TType> summary) {
    OperationBuilder opBuilder = scope.opBuilder(OP_NAME, "StatsAggregatorSetSummaryWriter");
    opBuilder.addInput(statsAggregator.asOutput());
    opBuilder.addInput(summary.asOutput());
    return new StatsAggregatorSetSummaryWriter(opBuilder.build());
  }

  @OpInputsMetadata(
      outputsClass = StatsAggregatorSetSummaryWriter.class
  )
  public static class Inputs extends RawOpInputs<StatsAggregatorSetSummaryWriter> {
    /**
     * The statsAggregator input
     */
    public final Operand<? extends TType> statsAggregator;

    /**
     * The summary input
     */
    public final Operand<? extends TType> summary;

    public Inputs(GraphOperation op) {
      super(new StatsAggregatorSetSummaryWriter(op), op, Arrays.asList());
      int inputIndex = 0;
      statsAggregator = (Operand<? extends TType>) op.input(inputIndex++);
      summary = (Operand<? extends TType>) op.input(inputIndex++);
    }
  }
}


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JeffBot2.Models;
using System.Data.Entity;

namespace JeffBot2Tools
{
    public static class Learner
    {
        public static void commit(NcDBContext db, List<string[]> queries)
        {
            foreach (string[] i in queries)
            {
                commit(db, i);
            }
        }
        public static void commit(NcDBContext db, string[] query)
        {
            var ns = from m in db.Ncs select m;
            // Somehow this fixes certain LINQ errors.
            string qa = query[0];
            string qb = query[1];
            string qc = query[2];
            ns = ns.Where(s => s.A.Equals(qa) && s.B.Equals(qb) && s.C.Equals(qc));
            List<Nc> preld = ns.ToList();
            if(preld.Count < 1)
            {
                Nc n = new Nc();
                n.A = qa;
                n.B = qb;
                n.C = qc;
                n.Count = 1;
                db.Ncs.Add(n);
                db.SaveChanges();
            }
            else
            {
                preld[0].Count += 1;
                db.Entry(preld[0]).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
    }
}


text:
package com.amazonaws.services.connect.model;

import javax.annotation.Generated;

/**
 *
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public enum ContactFlowType {

    CONTACT_FLOW("CONTACT_FLOW"),
    CUSTOMER_QUEUE("CUSTOMER_QUEUE"),
    CUSTOMER_HOLD("CUSTOMER_HOLD"),
    CUSTOMER_WHISPER("CUSTOMER_WHISPER"),
    AGENT_HOLD("AGENT_HOLD"),
    AGENT_WHISPER("AGENT_WHISPER"),
    OUTBOUND_WHISPER("OUTBOUND_WHISPER"),
    AGENT_TRANSFER("AGENT_TRANSFER"),
    QUEUE_TRANSFER("QUEUE_TRANSFER");

    private String value;

    private ContactFlowType(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return this.value;
    }

    /**
     * Use this in place of valueOf.
     *
     * @param value
     *        real value
     * @return ContactFlowType corresponding to the value
     *
     * @throws IllegalArgumentException
     *         If the specified value does not map to one of the known values in this enum.
     */
    public static ContactFlowType fromValue(String value) {
        if (value == null || "".equals(value)) {
            throw new IllegalArgumentException("Value cannot be null or empty!");
        }

        for (ContactFlowType enumEntry : ContactFlowType.values()) {
            if (enumEntry.toString().equals(value)) {
                return enumEntry;
            }
        }

        throw new IllegalArgumentException("Cannot create enum from " + value + " value!");
    }
}


text:
<?php
/**
 * DriverUnavailabilityFiltersModel
 *
 * PHP version 5
 *
 * @category Class
 * @package  BumbalClient
 * @author   Swaagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * Bumbal Client Api
 *
 * Bumbal API documentation
 *
 * OpenAPI spec version: 2.0
 * Contact: gerb@bumbal.eu
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 *
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace BumbalClient\Model;

use \ArrayAccess;

/**
 * DriverUnavailabilityFiltersModel Class Doc Comment
 *
 * @category    Class
 * @package     BumbalClient
 * @author      Swagger Codegen team
 * @link        https://github.com/swagger-api/swagger-codegen
 */
class DriverUnavailabilityFiltersModel implements ArrayAccess
{
    const DISCRIMINATOR = null;

    /**
      * The original name of the model.
      * @var string
      */
    protected static $swaggerModelName = 'DriverUnavailabilityFiltersModel';

    /**
      * Array of property to type mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerTypes = [
        'id' => 'int[]',
        'user_id' => 'int[]',
        'reference' => 'string[]',
        'updated_at_since' => '\DateTime',
        'updated_at_till' => '\DateTime',
        'created_at_since' => '\DateTime',
        'created_at_till' => '\DateTime'
    ];

    /**
      * Array of property to format mappings. Used for (de)serialization
      * @var string[]
      */
    protected static $swaggerFormats = [
        'id' => null,
        'user_id' => null,
        'reference' => null,
        'updated_at_since' => 'date-time',
        'updated_at_till' => 'date-time',
        'created_at_since' => 'date-time',
        'created_at_till' => 'date-time'
    ];

    public static function swaggerTypes()
    {
        return self::$swaggerTypes;
    }

    public static function swaggerFormats()
    {
        return self::$swaggerFormats;
    }

    /**
     * Array of attributes where the key is the local name, and the value is the original name
     * @var string[]
     */
    protected static $attributeMap = [
        'id' => 'id',
        'user_id' => 'user_id',
        'reference' => 'reference',
        'updated_at_since' => 'updated_at_since',
        'updated_at_till' => 'updated_at_till',
        'created_at_since' => 'created_at_since',
        'created_at_till' => 'created_at_till'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'user_id' => 'setUserId',
        'reference' => 'setReference',
        'updated_at_since' => 'setUpdatedAtSince',
        'updated_at_till' => 'setUpdatedAtTill',
        'created_at_since' => 'setCreatedAtSince',
        'created_at_till' => 'setCreatedAtTill'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'user_id' => 'getUserId',
        'reference' => 'getReference',
        'updated_at_since' => 'getUpdatedAtSince',
        'updated_at_till' => 'getUpdatedAtTill',
        'created_at_since' => 'getCreatedAtSince',
        'created_at_till' => 'getCreatedAtTill'
    ];

    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    public static function setters()
    {
        return self::$setters;
    }

    public static function getters()
    {
        return self::$getters;
    }

    /**
     * Associative array for storing property values
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor
     * @param mixed[] $data Associated array of property values initializing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['id'] = isset($data['id']) ? $data['id'] : null;
        $this->container['user_id'] = isset($data['user_id']) ? $data['user_id'] : null;
        $this->container['reference'] = isset($data['reference']) ? $data['reference'] : null;
        $this->container['updated_at_since'] = isset($data['updated_at_since']) ? $data['updated_at_since'] : null;
        $this->container['updated_at_till'] = isset($data['updated_at_till']) ? $data['updated_at_till'] : null;
        $this->container['created_at_since'] = isset($data['created_at_since']) ? $data['created_at_since'] : null;
        $this->container['created_at_till'] = isset($data['created_at_till']) ? $data['created_at_till'] : null;
    }

    /**
     * show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalid_properties = [];

        return $invalid_properties;
    }

    /**
     * validate all the properties in the model
     * return true if all passed
     *
     * @return bool True if all properties are valid
     */
    public function valid()
    {

        return true;
    }

    /**
     * Gets id
     * @return int[]
     */
    public function getId()
    {
        return $this->container['id'];
    }

    /**
     * Sets id
     * @param int[] $id DriverUnavailability id's
     * @return $this
     */
    public function setId($id)
    {
        $this->container['id'] = $id;

        return $this;
    }

    /**
     * Gets user_id
     * @return int[]
     */
    public function getUserId()
    {
        return $this->container['user_id'];
    }

    /**
     * Sets user_id
     * @param int[] $user_id DriverUnavailability user_id's
     * @return $this
     */
    public function setUserId($user_id)
    {
        $this->container['user_id'] = $user_id;

        return $this;
    }

    /**
     * Gets reference
     * @return string[]
     */
    public function getReference()
    {
        return $this->container['reference'];
    }

    /**
     * Sets reference
     * @param string[] $reference DriverUnavailability references
     * @return $this
     */
    public function setReference($reference)
    {
        $this->container['reference'] = $reference;

        return $this;
    }

    /**
     * Gets updated_at_since
     * @return \DateTime
     */
    public function getUpdatedAtSince()
    {
        return $this->container['updated_at_since'];
    }

    /**
     * Sets updated_at_since
     * @param \DateTime $updated_at_since Show updated since
     * @return $this
     */
    public function setUpdatedAtSince($updated_at_since)
    {
        $this->container['updated_at_since'] = $updated_at_since;

        return $this;
    }

    /**
     * Gets updated_at_till
     * @return \DateTime
     */
    public function getUpdatedAtTill()
    {
        return $this->container['updated_at_till'];
    }

    /**
     * Sets updated_at_till
     * @param \DateTime $updated_at_till Show updated till
     * @return $this
     */
    public function setUpdatedAtTill($updated_at_till)
    {
        $this->container['updated_at_till'] = $updated_at_till;

        return $this;
    }

    /**
     * Gets created_at_since
     * @return \DateTime
     */
    public function getCreatedAtSince()
    {
        return $this->container['created_at_since'];
    }

    /**
     * Sets created_at_since
     * @param \DateTime $created_at_since Show create since
     * @return $this
     */
    public function setCreatedAtSince($created_at_since)
    {
        $this->container['created_at_since'] = $created_at_since;

        return $this;
    }

    /**
     * Gets created_at_till
     * @return \DateTime
     */
    public function getCreatedAtTill()
    {
        return $this->container['created_at_till'];
    }

    /**
     * Sets created_at_till
     * @param \DateTime $created_at_till Show created till
     * @return $this
     */
    public function setCreatedAtTill($created_at_till)
    {
        $this->container['created_at_till'] = $created_at_till;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     * @param  integer $offset Offset
     * @return boolean
     */
    public function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     * @param  integer $offset Offset
     * @return mixed
     */
    public function offsetGet($offset)
    {
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
    }

    /**
     * Sets value based on offset.
     * @param  integer $offset Offset
     * @param  mixed   $value  Value to be set
     * @return void
     */
    public function offsetSet($offset, $value)
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     * @param  integer $offset Offset
     * @return void
     */
    public function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    /**
     * Gets the string presentation of the object
     * @return string
     */
    public function __toString()
    {
        if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print
            return json_encode(\BumbalClient\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT);
        }

        return json_encode(\BumbalClient\ObjectSerializer::sanitizeForSerialization($this));
    }
}


text:
package org.apache.ojb.broker.core;

import org.apache.ojb.broker.accesslayer.RsIterator;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.QueryBySQL;

/**
 * Interface for RsIteratorFactory
 *
 * @author Jakob Braeuchi
 * @version $Id: RsIteratorFactory.java,v 1.1 2007-08-24 22:17:35 ewestfal Exp $
 */
interface RsIteratorFactory
{

	/**
	 * Create a RsIterator based on a Query
	 */
	RsIterator createRsIterator(Query query, ClassDescriptor cld, PersistenceBrokerImpl broker);

	/**
	 * Create a RsIterator based on a SQL-Statement
	 */
	RsIterator createRsIterator(QueryBySQL query, ClassDescriptor cld, PersistenceBrokerImpl broker);

}


text:
var base_url = "http://localhost/energia/index.php/";

angular.module("sigere", []);
angular.module("sigere").controller("telaDeLoginCtrl", function ($scope, $http) {

    $scope.app = "sigere";

    $scope.openModal = function () {
        $scope.modalCadastro = {'display': ' inline'};
        $scope.modalMascara = {'display': ' inline'};

    };

    $scope.closeModal = function () {
        $scope.modalCadastro = {'display': 'none'};
        $scope.modalMascara = {'display': 'none'};
    };

    $scope.validaEmail = function (tipoCampo) {

    };

    $scope.validaCadastro = function (dadosCadastro) {

    };

});


text:
import '@glint/environment-ember-loose';

import type CssTransitionsRegistry from 'ember-css-transitions/template-registry';

declare module '@glint/environment-ember-loose/registry' {
  // Remove this once entries have been added! 👇
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
  export default interface Registry
    extends CssTransitionsRegistry /* other addon registries */ {
    // local entries
  }
}


text:
<?php include('header.php'); ?>

	<a href="<?php echo site_url($this->config->item('admin_folder').'/attributes/attribute_form'); ?>">Add New Attributes

			Name

<?php foreach ($attributes as $attribute):?>
		<tr id="attributes-<?php echo $attribute->id;?>">
			<?php echo  ucfirst($attribute->name); ?>

				<a href="<?php echo site_url($this->config->item('admin_folder').'/attributes/view/'.$attribute->id); ?>">View
				<a href="<?php echo site_url($this->config->item('admin_folder').'/attributes/attribute_form/'.$attribute->id); ?>">Edit
                <a href="<?php echo site_url($this->config->item('admin_folder').'/attributes/delete_attribute/'.$attribute->id); ?>" onclick="return areyousure();">Delete

<?php endforeach; ?>

<?php include('footer.php'); ?>


text:
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**brands** | [**\Swagger\Client\Model\Brand[]**](Brand.md) |  |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


text:
import assert from 'assert'
import React from 'react'
import { mount } from 'enzyme'

import { Overlay, Popup } from '../src'

describe('react-overlay-popup', function () {
  describe('<Overlay />', function () {
    it('puts overlay in detached DOM node', function () {
      mount(

          <Overlay>

          </Overlay>

,
        { attachTo: document.body }
      )
      assertElementExists('#a')
      assertElementExists('#b')
      assertElementNotExists('#b #a')
    })
  })

  //           x=120
  //            | x=150
  //            |  |
  //
  //          +---+  -- y=100
  //          |   |:
  //          |   |:
  //          |   |:
  //          +---+:
  //           ::::: -- y = 150
  //            +-+  -- y = 150
  //            | |:
  //            +-+:
  //             :::
  describe('<Popup />', function () {
    it('sets position relative to element', function () {
      mount(

          <Popup strategy='bottom right' gap={10}>

          </Popup>

,
        { attachTo: document.body }
      )
      assertElementExists('#x')
      assertElementExists('#y')
      const y = document.querySelector('#y')
      const container = y.parentNode
      assert.equal(container.style.top, '160px')
      assert.equal(container.style.left, '120px')
    })
  })
})

function assertElementNotExists (selector) {
  assert(!document.querySelector(selector), 'Element "' + selector + '" must not exist')
}
function assertElementExists (selector) {
  assert(document.querySelector(selector), 'Element "' + selector + '" must exist')
}