text:
#ifndef ALIGENMUONLIB_H
#define ALIGENMUONLIB_H

/* $Id$ */

// Library class for particle pt and y distributions used for
// muon spectrometer simulations.
// To be used with AliGenParam.
//
// andreas.morsch@cern.ch

#include "AliGenLib.h"

class AliGenMUONlib :
  public AliGenLib
{
 public:
  enum constants{kPhi, kOmega, kEta, kJpsi, kJpsiFamily, kPsiP, kJpsiFromB, kUpsilon, kUpsilonFamily,
		 kUpsilonP, kUpsilonPP, kCharm, kBeauty, kPion, kKaon, kChic, kChic0, kChic1, kChic2, kRho };

    GenFunc   GetPt(Int_t param, const char* tname=0) const;
    GenFunc   GetY (Int_t param, const char* tname=0) const;
    GenFuncIp GetIp(Int_t param, const char* tname=0) const;
 private:

// pions
    static Double_t PtPion(const Double_t *px, const Double_t *dummy);
    static Double_t PtScal(Double_t pt, Int_t np);
    static Double_t YPion( const Double_t *py, const Double_t *dummy);
    static Int_t    IpPion(TRandom *ran);
// kaons
    static Double_t PtKaon(const Double_t *px, const Double_t *dummy);
    static Double_t YKaon( const Double_t *py, const Double_t *dummy);
    static Int_t    IpKaon(TRandom *ran);
//  XZhang 20110621
    static Double_t PtPionPos2010PP(const Double_t *px, const Double_t *dummy);
    static Double_t PtPionNeg2010PP(const Double_t *px, const Double_t *dummy);
    static Double_t PtKaonPos2010PP(const Double_t *px, const Double_t *dummy);
    static Double_t PtKaonNeg2010PP(const Double_t *px, const Double_t *dummy);
    static Double_t YKaonPion2010PP(const Double_t *px, const Double_t *dummy);
    static Int_t    IpPionPos(TRandom *ran);
    static Int_t    IpPionNeg(TRandom *ran);
    static Int_t    IpKaonPos(TRandom *ran);
    static Int_t    IpKaonNeg(TRandom *ran);
// Phi
    static Double_t PtPhi( const Double_t *px, const Double_t *dummy);
    static Double_t YPhi( const  Double_t *px, const Double_t *dummy);
    static Int_t    IpPhi(TRandom *ran);
// Omega
    static Double_t PtOmega( const Double_t *px, const Double_t *dummy);
    static Double_t YOmega( const Double_t *px, const Double_t *dummy);
    static Int_t    IpOmega(TRandom *ran);
// Eta
    static Double_t PtEta( const Double_t *px, const Double_t *dummy);
    static Double_t YEta( const Double_t *px, const Double_t *dummy);
    static Int_t    IpEta(TRandom *ran);
// Rho
    static Double_t PtRho( const Double_t *px, const Double_t *dummy);
    static Double_t YRho( const Double_t *px, const Double_t *dummy);
    static Int_t    IpRho(TRandom *ran);

// J/Psi
    static Double_t PtJpsiPPdummy(Double_t px, Double_t en);
    static Double_t PtJpsiPP7000(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP8000(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP2760(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP4400(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP5030(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP8800(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760ShFdummy(Double_t px, Int_t n);
    static Double_t PtJpsiPbPb2760(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c1(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c2(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c3(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c4(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c5(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c6(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c7(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c8(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c9(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c10(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbPb2760c11(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb5030ShFdummy(Double_t px, Int_t n);
    static Double_t PtJpsiPPb5030(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb5030c1(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb5030c2(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb5030c3(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb5030c4(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP5030ShFdummy(Double_t px, Int_t n);
    static Double_t PtJpsiPbP5030(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP5030c1(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP5030c2(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP5030c3(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP5030c4(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb8800ShFdummy(Double_t px, Int_t n);
    static Double_t PtJpsiPPb8800(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb8800c1(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb8800c2(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb8800c3(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPPb8800c4(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP8800ShFdummy(Double_t px, Int_t n);
    static Double_t PtJpsiPbP8800(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP8800c1(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP8800c2(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP8800c3(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPbP8800c4(const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsi( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaled( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP10( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP9( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP7( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP4( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP3( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPP2( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPPb9( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPbP9( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiCDFscaledPbPb4( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsi(const Double_t *py, const Double_t *dummy);
    static Double_t PtJpsiPbPb( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiBPbPb( const Double_t *px, const Double_t *dummy);

    static Double_t YJpsiPPdummy(Double_t px, Double_t en);
    static Double_t YJpsiPPpoly(Double_t px, Double_t en);
    static Double_t YJpsiPP7000(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP8000(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP2760(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPpoly7000(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPpoly2760(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP4400(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP5030(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP8800(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760ShFdummy(Double_t px, Int_t n);
    static Double_t YJpsiPbPb2760(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c1(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c2(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c3(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c4(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c5(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c6(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c7(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c8(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c9(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c10(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb2760c11(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP5030dummy(Double_t px);
    static Double_t YJpsiPPb5030ShFdummy(Double_t px, Int_t n);
    static Double_t YJpsiPPb5030(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb5030c1(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb5030c2(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb5030c3(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb5030c4(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP5030(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP5030c1(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP5030c2(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP5030c3(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP5030c4(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP8800dummy(Double_t px);
    static Double_t YJpsiPPb8800ShFdummy(Double_t px, Int_t n);
    static Double_t YJpsiPPb8800(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb8800c1(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb8800c2(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb8800c3(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPPb8800c4(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP8800(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP8800c1(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP8800c2(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP8800c3(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbP8800c4(const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPbPb(const Double_t *py, const Double_t *dummy);
    static Double_t YJpsiCDFscaled(const Double_t *py, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP10( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP9( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP9dummy(Double_t px);
    static Double_t YJpsiCDFscaledPP7( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP4( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP3( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPP2( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPPb9( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPbP9( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiCDFscaledPbPb4( const Double_t *px, const Double_t *dummy);
    static Double_t PtJpsiPP( const Double_t *px, const Double_t *dummy);
    static Double_t YJpsiPP(const Double_t *py, const Double_t *dummy);
    static Double_t YJpsiBPbPb(const Double_t *py, const Double_t *dummy);
    static Int_t    IpJpsi(TRandom *ran);
    static Int_t    IpJpsiFamily(TRandom *ran);
    static Int_t    IpPsiP(TRandom *ran);
    static Double_t PtJpsiFlat( const Double_t *px, const Double_t *dummy );
    static Double_t YJpsiFlat(const Double_t *py, const Double_t *dummy);

// Upsilon
    static Double_t PtUpsilonPPdummy(Double_t px, Double_t en);
    static Double_t PtUpsilonPP8000(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPP7000(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPP2760(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPP4400(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPP5030(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPP8800(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760ShFdummy(Double_t px, Int_t n);
    static Double_t PtUpsilonPbPb2760(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c1(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c2(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c3(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c4(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c5(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c6(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c7(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c8(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c9(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c10(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb2760c11(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb5030ShFdummy(Double_t px, Int_t n);
    static Double_t PtUpsilonPPb5030(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb5030c1(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb5030c2(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb5030c3(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb5030c4(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP5030ShFdummy(Double_t px, Int_t n);
    static Double_t PtUpsilonPbP5030(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP5030c1(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP5030c2(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP5030c3(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP5030c4(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb8800ShFdummy(Double_t px, Int_t n);
    static Double_t PtUpsilonPPb8800(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb8800c1(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb8800c2(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb8800c3(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPPb8800c4(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP8800ShFdummy(Double_t px, Int_t n);
    static Double_t PtUpsilonPbP8800(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP8800c1(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP8800c2(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP8800c3(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbP8800c4(const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilon( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaled( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPP( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPP10( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPP9( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPP7( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPP4( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPPb9( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPbP9( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonCDFscaledPbPb4( const Double_t *px, const Double_t *dummy );

    static Double_t YUpsilonPPdummy(Double_t px, Double_t en);
    static Double_t YUpsilonPPpoly(Double_t px, Double_t en);
    static Double_t YUpsilonPP7000(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP8000(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP2760(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPpoly7000(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPpoly2760(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP4400(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP5030(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP8800(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760ShFdummy(Double_t px, Int_t n);
    static Double_t YUpsilonPbPb2760(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c1(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c2(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c3(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c4(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c5(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c6(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c7(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c8(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c9(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c10(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb2760c11(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP5030dummy(Double_t px);
    static Double_t YUpsilonPPb5030ShFdummy(Double_t px, Int_t n);
    static Double_t YUpsilonPPb5030(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb5030c1(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb5030c2(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb5030c3(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb5030c4(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP5030(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP5030c1(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP5030c2(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP5030c3(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP5030c4(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP8800dummy(Double_t px);
    static Double_t YUpsilonPPb8800ShFdummy(Double_t px, Int_t n);
    static Double_t YUpsilonPPb8800(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb8800c1(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb8800c2(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb8800c3(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPPb8800c4(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP8800(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP8800c1(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP8800c2(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP8800c3(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbP8800c4(const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilon(const Double_t *py, const Double_t *dummy);
    static Double_t YUpsilonCDFscaled(const Double_t *py, const Double_t *dummy);
    static Double_t YUpsilonCDFscaledPP( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPP10( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPP9( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPP9dummy(Double_t px);
    static Double_t YUpsilonCDFscaledPP7( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPP4( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPPb9( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPbP9( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonCDFscaledPbPb4( const Double_t *px, const Double_t *dummy );
    static Double_t PtUpsilonPbPb( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPbPb(const Double_t *py, const Double_t *dummy);
    static Double_t PtUpsilonPP( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonPP(const Double_t *py, const Double_t *dummy);
    static Int_t    IpUpsilon(TRandom *ran);
    static Int_t    IpUpsilonFamily(TRandom *ran);
    static Int_t    IpUpsilonP(TRandom *ran);
    static Int_t    IpUpsilonPP(TRandom *ran);
    static Double_t PtUpsilonFlat( const Double_t *px, const Double_t *dummy );
    static Double_t YUpsilonFlat(const Double_t *py, const Double_t *dummy);
//
// Charm
    static Double_t PtCharm( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmCentral( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF1M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF2M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M1S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M2S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S1PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S2PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S3PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S4PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S5PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtCharmF0M0S6PP( const Double_t *px, const Double_t *dummy );
    static Double_t YCharm(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF1M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF2M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M1S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M2S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S1PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S2PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S3PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S4PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S5PP(const Double_t *py, const Double_t *dummy);
    static Double_t YCharmF0M0S6PP(const Double_t *py, const Double_t *dummy);
    static Int_t    IpCharm(TRandom *ran);
//
// Beauty
    static Double_t PtBeauty( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF1M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF2M0S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M1S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M2S0PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S1PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S2PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S3PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S4PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S5PP( const Double_t *px, const Double_t *dummy );
    static Double_t PtBeautyF0M0S6PP( const Double_t *px, const Double_t *dummy );
    static Double_t YBeauty(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF1M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF2M0S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M1S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M2S0PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S1PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S2PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S3PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S4PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S5PP(const Double_t *py, const Double_t *dummy);
    static Double_t YBeautyF0M0S6PP(const Double_t *py, const Double_t *dummy);
    static Double_t PtBeautyCentral( const Double_t *px, const Double_t *dummy );
    static Int_t    IpBeauty(TRandom *ran);
//

   // Chi 1c 2c
   static Double_t PtChic0( const Double_t *px, const Double_t *dummy);
   static Double_t YChic0(const Double_t *py, const Double_t *dummy);
   static Int_t    IpChic0(TRandom *ran);

   static Double_t PtChic1( const Double_t *px, const Double_t *dummy);
   static Double_t YChic1(const Double_t *py, const Double_t *dummy);
   static Int_t    IpChic1(TRandom *ran);

   static Double_t PtChic2( const Double_t *px, const Double_t *dummy);
   static Double_t YChic2(const Double_t *py, const Double_t *dummy);
   static Int_t    IpChic2(TRandom *ran);

   static Double_t PtChic( const Double_t *px, const Double_t *dummy);
   static Double_t YChic(const Double_t *py, const Double_t *dummy);
   static Int_t    IpChic(TRandom *ran);

//

    static Float_t Interpolate(Float_t x, Float_t* y, Float_t x0,
			Float_t dx,
			Int_t n, Int_t no);

    ClassDef(AliGenMUONlib,0) // Library providing y and pT parameterisations
};
#endif


text:
echo "poppler-utils, which contains these related apps (from Synaptic package description):

Quote:
This package contains pdftops (PDF to PostScript converter), pdfinfo
(PDF document information extractor), pdfimages (PDF image extractor),
pdftohtml (PDF to HTML converter), pdftotext (PDF to text converter),
and pdffonts (PDF font analyzer).
"
read readline
sudo apt-get install -y -y poppler-utils

sudo apt-get install -y -y openoffice.org-pdfimport
sudo apt-get install -y -y squid3
 sudo apt-get install -y -y evince
 sudo apt-get install -y -y wireshark
 sudo apt-get install -y -y pstotext #ps,pdf to txt

 sudo apt-get install -y -y catdoc   #word,tex to txt
 sudo apt-get install -y -y xpdf
 sudo apt-get install -y -y acroread
 sudo apt-get install -y -y  unoconv

redpajama_set_name: RedPajamaGithub


text:
package com.google.common.primitives;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkPositionIndexes;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Converter;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.RandomAccess;
import javax.annotation.CheckForNull;

/**
 * Static utility methods pertaining to {@code short} primitives, that are not already found in
 * either {@link Short} or {@link Arrays}.
 *
 *
See the Guava User Guide article on primitive utilities.
 *
 * @author Kevin Bourrillion
 * @since 1.0
 */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public final class Shorts extends ShortsMethodsForWeb {
  private Shorts() {}

  /**
   * The number of bytes required to represent a primitive {@code short} value.
   *
   *
Java 8 users: use {@link Short#BYTES} instead.
   */
  public static final int BYTES = Short.SIZE / Byte.SIZE;

  /**
   * The largest power of two that can be represented as a {@code short}.
   *
   * @since 10.0
   */
  public static final short MAX_POWER_OF_TWO = 1 << (Short.SIZE - 2);

  /**
   * Returns a hash code for {@code value}; equal to the result of invoking {@code ((Short)
   * value).hashCode()}.
   *
   *
Java 8 users: use {@link Short#hashCode(short)} instead.
   *
   * @param value a primitive {@code short} value
   * @return a hash code for the value
   */
  public static int hashCode(short value) {
    return value;
  }

  /**
   * Returns the {@code short} value that is equal to {@code value}, if possible.
   *
   * @param value any value in the range of the {@code short} type
   * @return the {@code short} value that equals {@code value}
   * @throws IllegalArgumentException if {@code value} is greater than {@link Short#MAX_VALUE} or
   *     less than {@link Short#MIN_VALUE}
   */
  public static short checkedCast(long value) {
    short result = (short) value;
    checkArgument(result == value, "Out of range: %s", value);
    return result;
  }

  /**
   * Returns the {@code short} nearest in value to {@code value}.
   *
   * @param value any {@code long} value
   * @return the same value cast to {@code short} if it is in the range of the {@code short} type,
   *     {@link Short#MAX_VALUE} if it is too large, or {@link Short#MIN_VALUE} if it is too small
   */
  public static short saturatedCast(long value) {
    if (value > Short.MAX_VALUE) {
      return Short.MAX_VALUE;
    }
    if (value < Short.MIN_VALUE) {
      return Short.MIN_VALUE;
    }
    return (short) value;
  }

  /**
   * Compares the two specified {@code short} values. The sign of the value returned is the same as
   * that of {@code ((Short) a).compareTo(b)}.
   *
   *
Note for Java 7 and later: this method should be treated as deprecated; use the
   * equivalent {@link Short#compare} method instead.
   *
   * @param a the first {@code short} to compare
   * @param b the second {@code short} to compare
   * @return a negative value if {@code a} is less than {@code b}; a positive value if {@code a} is
   *     greater than {@code b}; or zero if they are equal
   */
  public static int compare(short a, short b) {
    return a - b; // safe due to restricted range
  }

  /**
   * Returns {@code true} if {@code target} is present as an element anywhere in {@code array}.
   *
   * @param array an array of {@code short} values, possibly empty
   * @param target a primitive {@code short} value
   * @return {@code true} if {@code array[i] == target} for some value of {@code i}
   */
  public static boolean contains(short[] array, short target) {
    for (short value : array) {
      if (value == target) {
        return true;
      }
    }
    return false;
  }

  /**
   * Returns the index of the first appearance of the value {@code target} in {@code array}.
   *
   * @param array an array of {@code short} values, possibly empty
   * @param target a primitive {@code short} value
   * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no
   *     such index exists.
   */
  public static int indexOf(short[] array, short target) {
    return indexOf(array, target, 0, array.length);
  }

  // TODO(kevinb): consider making this public
  private static int indexOf(short[] array, short target, int start, int end) {
    for (int i = start; i < end; i++) {
      if (array[i] == target) {
        return i;
      }
    }
    return -1;
  }

  /**
   * Returns the start position of the first occurrence of the specified {@code target} within
   * {@code array}, or {@code -1} if there is no such occurrence.
   *
   *
More formally, returns the lowest index {@code i} such that {@code Arrays.copyOfRange(array,
   * i, i + target.length)} contains exactly the same elements as {@code target}.
   *
   * @param array the array to search for the sequence {@code target}
   * @param target the array to search for as a sub-sequence of {@code array}
   */
  public static int indexOf(short[] array, short[] target) {
    checkNotNull(array, "array");
    checkNotNull(target, "target");
    if (target.length == 0) {
      return 0;
    }

    outer:
    for (int i = 0; i < array.length - target.length + 1; i++) {
      for (int j = 0; j < target.length; j++) {
        if (array[i + j] != target[j]) {
          continue outer;
        }
      }
      return i;
    }
    return -1;
  }

  /**
   * Returns the index of the last appearance of the value {@code target} in {@code array}.
   *
   * @param array an array of {@code short} values, possibly empty
   * @param target a primitive {@code short} value
   * @return the greatest index {@code i} for which {@code array[i] == target}, or {@code -1} if no
   *     such index exists.
   */
  public static int lastIndexOf(short[] array, short target) {
    return lastIndexOf(array, target, 0, array.length);
  }

  // TODO(kevinb): consider making this public
  private static int lastIndexOf(short[] array, short target, int start, int end) {
    for (int i = end - 1; i >= start; i--) {
      if (array[i] == target) {
        return i;
      }
    }
    return -1;
  }

  /**
   * Returns the least value present in {@code array}.
   *
   * @param array a nonempty array of {@code short} values
   * @return the value present in {@code array} that is less than or equal to every other value in
   *     the array
   * @throws IllegalArgumentException if {@code array} is empty
   */
  @GwtIncompatible(
      "Available in GWT! Annotation is to avoid conflict with GWT specialization of base class.")
  public static short min(short... array) {
    checkArgument(array.length > 0);
    short min = array[0];
    for (int i = 1; i < array.length; i++) {
      if (array[i] < min) {
        min = array[i];
      }
    }
    return min;
  }

  /**
   * Returns the greatest value present in {@code array}.
   *
   * @param array a nonempty array of {@code short} values
   * @return the value present in {@code array} that is greater than or equal to every other value
   *     in the array
   * @throws IllegalArgumentException if {@code array} is empty
   */
  @GwtIncompatible(
      "Available in GWT! Annotation is to avoid conflict with GWT specialization of base class.")
  public static short max(short... array) {
    checkArgument(array.length > 0);
    short max = array[0];
    for (int i = 1; i < array.length; i++) {
      if (array[i] > max) {
        max = array[i];
      }
    }
    return max;
  }

  /**
   * Returns the value nearest to {@code value} which is within the closed range {@code [min..max]}.
   *
   *
If {@code value} is within the range {@code [min..max]}, {@code value} is returned
   * unchanged. If {@code value} is less than {@code min}, {@code min} is returned, and if {@code
   * value} is greater than {@code max}, {@code max} is returned.
   *
   * @param value the {@code short} value to constrain
   * @param min the lower bound (inclusive) of the range to constrain {@code value} to
   * @param max the upper bound (inclusive) of the range to constrain {@code value} to
   * @throws IllegalArgumentException if {@code min > max}
   * @since 21.0
   */
  @Beta
  public static short constrainToRange(short value, short min, short max) {
    checkArgument(min <= max, "min (%s) must be less than or equal to max (%s)", min, max);
    return value < min ? min : value < max ? value : max;
  }

  /**
   * Returns the values from each provided array combined into a single array. For example, {@code
   * concat(new short[] {a, b}, new short[] {}, new short[] {c}} returns the array {@code {a, b,
   * c}}.
   *
   * @param arrays zero or more {@code short} arrays
   * @return a single array containing all the values from the source arrays, in order
   */
  public static short[] concat(short[]... arrays) {
    int length = 0;
    for (short[] array : arrays) {
      length += array.length;
    }
    short[] result = new short[length];
    int pos = 0;
    for (short[] array : arrays) {
      System.arraycopy(array, 0, result, pos, array.length);
      pos += array.length;
    }
    return result;
  }

  /**
   * Returns a big-endian representation of {@code value} in a 2-element byte array; equivalent to
   * {@code ByteBuffer.allocate(2).putShort(value).array()}. For example, the input value {@code
   * (short) 0x1234} would yield the byte array {@code {0x12, 0x34}}.
   *
   *
If you need to convert and concatenate several values (possibly even of different types),
   * use a shared {@link java.nio.ByteBuffer} instance, or use {@link
   * com.google.common.io.ByteStreams#newDataOutput()} to get a growable buffer.
   */
  @GwtIncompatible // doesn't work
  public static byte[] toByteArray(short value) {
    return new byte[] {(byte) (value >> 8), (byte) value};
  }

  /**
   * Returns the {@code short} value whose big-endian representation is stored in the first 2 bytes
   * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getShort()}. For example, the
   * input byte array {@code {0x54, 0x32}} would yield the {@code short} value {@code 0x5432}.
   *
   *
Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more
   * flexibility at little cost in readability.
   *
   * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements
   */
  @GwtIncompatible // doesn't work
  public static short fromByteArray(byte[] bytes) {
    checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES);
    return fromBytes(bytes[0], bytes[1]);
  }

  /**
   * Returns the {@code short} value whose byte representation is the given 2 bytes, in big-endian
   * order; equivalent to {@code Shorts.fromByteArray(new byte[] {b1, b2})}.
   *
   * @since 7.0
   */
  @GwtIncompatible // doesn't work
  public static short fromBytes(byte b1, byte b2) {
    return (short) ((b1 << 8) | (b2 & 0xFF));
  }

  private static final class ShortConverter extends Converter<String, Short>
      implements Serializable {
    static final ShortConverter INSTANCE = new ShortConverter();

    @Override
    protected Short doForward(String value) {
      return Short.decode(value);
    }

    @Override
    protected String doBackward(Short value) {
      return value.toString();
    }

    @Override
    public String toString() {
      return "Shorts.stringConverter()";
    }

    private Object readResolve() {
      return INSTANCE;
    }

    private static final long serialVersionUID = 1;
  }

  /**
   * Returns a serializable converter object that converts between strings and shorts using {@link
   * Short#decode} and {@link Short#toString()}. The returned converter throws {@link
   * NumberFormatException} if the input string is invalid.
   *
   *
Warning: please see {@link Short#decode} to understand exactly how strings are
   * parsed. For example, the string {@code "0123"} is treated as octal and converted to the
   * value {@code 83}.
   *
   * @since 16.0
   */
  @Beta
  public static Converter<String, Short> stringConverter() {
    return ShortConverter.INSTANCE;
  }

  /**
   * Returns an array containing the same values as {@code array}, but guaranteed to be of a
   * specified minimum length. If {@code array} already has a length of at least {@code minLength},
   * it is returned directly. Otherwise, a new array of size {@code minLength + padding} is
   * returned, containing the values of {@code array}, and zeroes in the remaining places.
   *
   * @param array the source array
   * @param minLength the minimum length the returned array must guarantee
   * @param padding an extra amount to "grow" the array by if growth is necessary
   * @throws IllegalArgumentException if {@code minLength} or {@code padding} is negative
   * @return an array containing the values of {@code array}, with guaranteed minimum length {@code
   *     minLength}
   */
  public static short[] ensureCapacity(short[] array, int minLength, int padding) {
    checkArgument(minLength >= 0, "Invalid minLength: %s", minLength);
    checkArgument(padding >= 0, "Invalid padding: %s", padding);
    return (array.length < minLength) ? Arrays.copyOf(array, minLength + padding) : array;
  }

  /**
   * Returns a string containing the supplied {@code short} values separated by {@code separator}.
   * For example, {@code join("-", (short) 1, (short) 2, (short) 3)} returns the string {@code
   * "1-2-3"}.
   *
   * @param separator the text that should appear between consecutive values in the resulting string
   *     (but not at the start or end)
   * @param array an array of {@code short} values, possibly empty
   */
  public static String join(String separator, short... array) {
    checkNotNull(separator);
    if (array.length == 0) {
      return "";
    }

    // For pre-sizing a builder, just get the right order of magnitude
    StringBuilder builder = new StringBuilder(array.length * 6);
    builder.append(array[0]);
    for (int i = 1; i < array.length; i++) {
      builder.append(separator).append(array[i]);
    }
    return builder.toString();
  }

  /**
   * Returns a comparator that compares two {@code short} arrays lexicographically. That is, it
   * compares, using {@link #compare(short, short)}), the first pair of values that follow any
   * common prefix, or when one array is a prefix of the other, treats the shorter array as the
   * lesser. For example, {@code [] < [(short) 1] < [(short) 1, (short) 2] < [(short) 2]}.
   *
   *
The returned comparator is inconsistent with {@link Object#equals(Object)} (since arrays
   * support only identity equality), but it is consistent with {@link Arrays#equals(short[],
   * short[])}.
   *
   * @since 2.0
   */
  public static Comparator<short[]> lexicographicalComparator() {
    return LexicographicalComparator.INSTANCE;
  }

  private enum LexicographicalComparator implements Comparator<short[]> {
    INSTANCE;

    @Override
    public int compare(short[] left, short[] right) {
      int minLength = Math.min(left.length, right.length);
      for (int i = 0; i < minLength; i++) {
        int result = Shorts.compare(left[i], right[i]);
        if (result != 0) {
          return result;
        }
      }
      return left.length - right.length;
    }

    @Override
    public String toString() {
      return "Shorts.lexicographicalComparator()";
    }
  }

  /**
   * Sorts the elements of {@code array} in descending order.
   *
   * @since 23.1
   */
  public static void sortDescending(short[] array) {
    checkNotNull(array);
    sortDescending(array, 0, array.length);
  }

  /**
   * Sorts the elements of {@code array} between {@code fromIndex} inclusive and {@code toIndex}
   * exclusive in descending order.
   *
   * @since 23.1
   */
  public static void sortDescending(short[] array, int fromIndex, int toIndex) {
    checkNotNull(array);
    checkPositionIndexes(fromIndex, toIndex, array.length);
    Arrays.sort(array, fromIndex, toIndex);
    reverse(array, fromIndex, toIndex);
  }

  /**
   * Reverses the elements of {@code array}. This is equivalent to {@code
   * Collections.reverse(Shorts.asList(array))}, but is likely to be more efficient.
   *
   * @since 23.1
   */
  public static void reverse(short[] array) {
    checkNotNull(array);
    reverse(array, 0, array.length);
  }

  /**
   * Reverses the elements of {@code array} between {@code fromIndex} inclusive and {@code toIndex}
   * exclusive. This is equivalent to {@code
   * Collections.reverse(Shorts.asList(array).subList(fromIndex, toIndex))}, but is likely to be
   * more efficient.
   *
   * @throws IndexOutOfBoundsException if {@code fromIndex < 0}, {@code toIndex > array.length}, or
   *     {@code toIndex > fromIndex}
   * @since 23.1
   */
  public static void reverse(short[] array, int fromIndex, int toIndex) {
    checkNotNull(array);
    checkPositionIndexes(fromIndex, toIndex, array.length);
    for (int i = fromIndex, j = toIndex - 1; i < j; i++, j--) {
      short tmp = array[i];
      array[i] = array[j];
      array[j] = tmp;
    }
  }

  /**
   * Performs a right rotation of {@code array} of "distance" places, so that the first element is
   * moved to index "distance", and the element at index {@code i} ends up at index {@code (distance
   * + i) mod array.length}. This is equivalent to {@code Collections.rotate(Shorts.asList(array),
   * distance)}, but is considerably faster and avoids allocation and garbage collection.
   *
   *
The provided "distance" may be negative, which will rotate left.
   *
   * @since NEXT
   */
  public static void rotate(short[] array, int distance) {
    rotate(array, distance, 0, array.length);
  }

  /**
   * Performs a right rotation of {@code array} between {@code fromIndex} inclusive and {@code
   * toIndex} exclusive. This is equivalent to {@code
   * Collections.rotate(Shorts.asList(array).subList(fromIndex, toIndex), distance)}, but is
   * considerably faster and avoids allocations and garbage collection.
   *
   *
The provided "distance" may be negative, which will rotate left.
   *
   * @throws IndexOutOfBoundsException if {@code fromIndex < 0}, {@code toIndex > array.length}, or
   *     {@code toIndex > fromIndex}
   * @since NEXT
   */
  public static void rotate(short[] array, int distance, int fromIndex, int toIndex) {
    // See Ints.rotate for more details about possible algorithms here.
    checkNotNull(array);
    checkPositionIndexes(fromIndex, toIndex, array.length);
    if (array.length <= 1) {
      return;
    }

    int length = toIndex - fromIndex;
    // Obtain m = (-distance mod length), a non-negative value less than "length". This is how many
    // places left to rotate.
    int m = -distance % length;
    m = (m < 0) ? m + length : m;
    // The current index of what will become the first element of the rotated section.
    int newFirstIndex = m + fromIndex;
    if (newFirstIndex == fromIndex) {
      return;
    }

    reverse(array, fromIndex, newFirstIndex);
    reverse(array, newFirstIndex, toIndex);
    reverse(array, fromIndex, toIndex);
  }

  /**
   * Returns an array containing each value of {@code collection}, converted to a {@code short}
   * value in the manner of {@link Number#shortValue}.
   *
   *
Elements are copied from the argument collection as if by {@code collection.toArray()}.
   * Calling this method is as thread-safe as calling that method.
   *
   * @param collection a collection of {@code Number} instances
   * @return an array containing the same values as {@code collection}, in the same order, converted
   *     to primitives
   * @throws NullPointerException if {@code collection} or any of its elements is null
   * @since 1.0 (parameter was {@code Collection<Short>} before 12.0)
   */
  public static short[] toArray(Collection<? extends Number> collection) {
    if (collection instanceof ShortArrayAsList) {
      return ((ShortArrayAsList) collection).toShortArray();
    }

    Object[] boxedArray = collection.toArray();
    int len = boxedArray.length;
    short[] array = new short[len];
    for (int i = 0; i < len; i++) {
      // checkNotNull for GWT (do not optimize)
      array[i] = ((Number) checkNotNull(boxedArray[i])).shortValue();
    }
    return array;
  }

  /**
   * Returns a fixed-size list backed by the specified array, similar to {@link
   * Arrays#asList(Object[])}. The list supports {@link List#set(int, Object)}, but any attempt to
   * set a value to {@code null} will result in a {@link NullPointerException}.
   *
   *
The returned list maintains the values, but not the identities, of {@code Short} objects
   * written to or read from it. For example, whether {@code list.get(0) == list.get(0)} is true for
   * the returned list is unspecified.
   *
   * @param backingArray the array to back the list
   * @return a list view of the array
   */
  public static List<Short> asList(short... backingArray) {
    if (backingArray.length == 0) {
      return Collections.emptyList();
    }
    return new ShortArrayAsList(backingArray);
  }

  @GwtCompatible
  private static class ShortArrayAsList extends AbstractList<Short>
      implements RandomAccess, Serializable {
    final short[] array;
    final int start;
    final int end;

    ShortArrayAsList(short[] array) {
      this(array, 0, array.length);
    }

    ShortArrayAsList(short[] array, int start, int end) {
      this.array = array;
      this.start = start;
      this.end = end;
    }

    @Override
    public int size() {
      return end - start;
    }

    @Override
    public boolean isEmpty() {
      return false;
    }

    @Override
    public Short get(int index) {
      checkElementIndex(index, size());
      return array[start + index];
    }

    @Override
    public boolean contains(@CheckForNull Object target) {
      // Overridden to prevent a ton of boxing
      return (target instanceof Short) && Shorts.indexOf(array, (Short) target, start, end) != -1;
    }

    @Override
    public int indexOf(@CheckForNull Object target) {
      // Overridden to prevent a ton of boxing
      if (target instanceof Short) {
        int i = Shorts.indexOf(array, (Short) target, start, end);
        if (i >= 0) {
          return i - start;
        }
      }
      return -1;
    }

    @Override
    public int lastIndexOf(@CheckForNull Object target) {
      // Overridden to prevent a ton of boxing
      if (target instanceof Short) {
        int i = Shorts.lastIndexOf(array, (Short) target, start, end);
        if (i >= 0) {
          return i - start;
        }
      }
      return -1;
    }

    @Override
    public Short set(int index, Short element) {
      checkElementIndex(index, size());
      short oldValue = array[start + index];
      // checkNotNull for GWT (do not optimize)
      array[start + index] = checkNotNull(element);
      return oldValue;
    }

    @Override
    public List<Short> subList(int fromIndex, int toIndex) {
      int size = size();
      checkPositionIndexes(fromIndex, toIndex, size);
      if (fromIndex == toIndex) {
        return Collections.emptyList();
      }
      return new ShortArrayAsList(array, start + fromIndex, start + toIndex);
    }

    @Override
    public boolean equals(@CheckForNull Object object) {
      if (object == this) {
        return true;
      }
      if (object instanceof ShortArrayAsList) {
        ShortArrayAsList that = (ShortArrayAsList) object;
        int size = size();
        if (that.size() != size) {
          return false;
        }
        for (int i = 0; i < size; i++) {
          if (array[start + i] != that.array[that.start + i]) {
            return false;
          }
        }
        return true;
      }
      return super.equals(object);
    }

    @Override
    public int hashCode() {
      int result = 1;
      for (int i = start; i < end; i++) {
        result = 31 * result + Shorts.hashCode(array[i]);
      }
      return result;
    }

    @Override
    public String toString() {
      StringBuilder builder = new StringBuilder(size() * 6);
      builder.append('[').append(array[start]);
      for (int i = start + 1; i < end; i++) {
        builder.append(", ").append(array[i]);
      }
      return builder.append(']').toString();
    }

    short[] toShortArray() {
      return Arrays.copyOfRange(array, start, end);
    }

    private static final long serialVersionUID = 0;
  }
}


text:
import os
import unittest
import libameh
from . import data_dir

class TestConfig (unittest.TestCase):
    def setUp(self):
        self.ini_file = os.path.join(data_dir, 'test.ini')
        self.config = libameh.config.Config(self.ini_file)

    def test_init(self):
        conf = libameh.config.Config(self.ini_file)
        self.assertEqual(conf.filename, self.ini_file)

    def test_init_missing_config(self):
        self.assertRaises(libameh.exceptions.MissingConfig,
                          libameh.config.Config, 'bogus.ini')

    def test_apps(self):
        self.assertEqual(self.config.apps(), ['jira', 'confluence'])

    def test_check_app(self):
        self.assertTrue(self.config.check_app('jira'))
        self.assertTrue(self.config.check_app('confluence'))

    def test_check_app_unknown_app(self):
        self.assertRaises(libameh.exceptions.UnknownApplication,
                          self.config.check_app, 'bogus')

    def test_properties_string(self):
        props = self.config.properties_string('jira')
        self.assertIn('jira home', props)
        self.assertIn('jira install', props)

    def test_properties_string_unknown_app(self):
        self.assertRaises(libameh.exceptions.UnknownApplication,
                          self.config.properties_string, 'bogus')

    def test_property(self):
        self.assertEqual(self.config.property('jira', 'install'),
                         '/opt/atlassian/jira')

    def test_property_unknown_app(self):
        self.assertRaises(libameh.exceptions.UnknownApplication,
                          self.config.property, 'bogus', 'install')

    def test_defaults(self):
        self.assertEqual(self.config.defaults('jira'), {
            'app': 'jira',
            'user': 'jira',
            'install': '/opt/atlassian/jira',
            'home': '/var/atlassian/application-data/jira-home',
        })

    def test_properties_dict(self):
        props = self.config.properties_dict('jira')
        self.assertIn('home', props)
        self.assertIn('install', props)

    def test_properties_dict_unknown_app(self):
        self.assertRaises(libameh.exceptions.UnknownApplication,
                          self.config.properties_dict, 'bogus')


text:
namespace blink {

class CSSMotionRotationNonInterpolableValue : public NonInterpolableValue {
public:
    ~CSSMotionRotationNonInterpolableValue() {}

    static PassRefPtr<CSSMotionRotationNonInterpolableValue> create(MotionRotationType rotationType)
    {
        return adoptRef(new CSSMotionRotationNonInterpolableValue(rotationType));
    }

    MotionRotationType rotationType() const { return m_rotationType; }

    DECLARE_NON_INTERPOLABLE_VALUE_TYPE();

private:
    CSSMotionRotationNonInterpolableValue(MotionRotationType rotationType)
        : m_rotationType(rotationType)
    { }

    MotionRotationType m_rotationType;
};

DEFINE_NON_INTERPOLABLE_VALUE_TYPE(CSSMotionRotationNonInterpolableValue);
DEFINE_NON_INTERPOLABLE_VALUE_TYPE_CASTS(CSSMotionRotationNonInterpolableValue);

namespace {

class UnderlyingRotationTypeChecker : public InterpolationType::ConversionChecker {
public:
    static PassOwnPtr<UnderlyingRotationTypeChecker> create(MotionRotationType underlyingRotationType)
    {
        return adoptPtr(new UnderlyingRotationTypeChecker(underlyingRotationType));
    }

    bool isValid(const InterpolationEnvironment&, const InterpolationValue& underlying) const final
    {
        return m_underlyingRotationType == toCSSMotionRotationNonInterpolableValue(*underlying.nonInterpolableValue).rotationType();
    }

private:
    UnderlyingRotationTypeChecker(MotionRotationType underlyingRotationType)
        : m_underlyingRotationType(underlyingRotationType)
    { }

    MotionRotationType m_underlyingRotationType;
};

class InheritedRotationTypeChecker : public InterpolationType::ConversionChecker {
public:
    static PassOwnPtr<InheritedRotationTypeChecker> create(MotionRotationType inheritedRotationType)
    {
        return adoptPtr(new InheritedRotationTypeChecker(inheritedRotationType));
    }

    bool isValid(const InterpolationEnvironment& environment, const InterpolationValue& underlying) const final
    {
        return m_inheritedRotationType == environment.state().parentStyle()->motionRotation().type;
    }

private:
    InheritedRotationTypeChecker(MotionRotationType inheritedRotationType)
        : m_inheritedRotationType(inheritedRotationType)
    { }

    MotionRotationType m_inheritedRotationType;
};

InterpolationValue convertMotionRotation(const StyleMotionRotation& rotation)
{
    return InterpolationValue(
        InterpolableNumber::create(rotation.angle),
        CSSMotionRotationNonInterpolableValue::create(rotation.type));
}

} // namespace

InterpolationValue CSSMotionRotationInterpolationType::maybeConvertNeutral(const InterpolationValue& underlying, ConversionCheckers& conversionCheckers) const
{
    MotionRotationType underlyingRotationType = toCSSMotionRotationNonInterpolableValue(*underlying.nonInterpolableValue).rotationType();
    conversionCheckers.append(UnderlyingRotationTypeChecker::create(underlyingRotationType));
    return convertMotionRotation(StyleMotionRotation(0, underlyingRotationType));
}

InterpolationValue CSSMotionRotationInterpolationType::maybeConvertInitial(const StyleResolverState&, ConversionCheckers& conversionCheckers) const
{
    return convertMotionRotation(StyleMotionRotation(0, MotionRotationAuto));
}

InterpolationValue CSSMotionRotationInterpolationType::maybeConvertInherit(const StyleResolverState& state, ConversionCheckers& conversionCheckers) const
{
    MotionRotationType inheritedRotationType = state.parentStyle()->motionRotation().type;
    conversionCheckers.append(InheritedRotationTypeChecker::create(inheritedRotationType));
    return convertMotionRotation(state.parentStyle()->motionRotation());
}

InterpolationValue CSSMotionRotationInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState&, ConversionCheckers&) const
{
    return convertMotionRotation(StyleBuilderConverter::convertMotionRotation(value));
}

PairwiseInterpolationValue CSSMotionRotationInterpolationType::maybeMergeSingles(InterpolationValue&& start, InterpolationValue&& end) const
{
    const MotionRotationType& startType = toCSSMotionRotationNonInterpolableValue(*start.nonInterpolableValue).rotationType();
    const MotionRotationType& endType = toCSSMotionRotationNonInterpolableValue(*end.nonInterpolableValue).rotationType();
    if (startType != endType)
        return nullptr;
    return PairwiseInterpolationValue(
        std::move(start.interpolableValue),
        std::move(end.interpolableValue),
        start.nonInterpolableValue.release());
}

InterpolationValue CSSMotionRotationInterpolationType::maybeConvertUnderlyingValue(const InterpolationEnvironment& environment) const
{
    return convertMotionRotation(environment.state().style()->motionRotation());
}

void CSSMotionRotationInterpolationType::composite(UnderlyingValueOwner& underlyingValueOwner, double underlyingFraction, const InterpolationValue& value, double interpolationFraction) const
{
    const MotionRotationType& underlyingType = toCSSMotionRotationNonInterpolableValue(*underlyingValueOwner.value().nonInterpolableValue).rotationType();
    const MotionRotationType& rotationType = toCSSMotionRotationNonInterpolableValue(*value.nonInterpolableValue).rotationType();
    if (underlyingType == rotationType)
        underlyingValueOwner.mutableValue().interpolableValue->scaleAndAdd(underlyingFraction, *value.interpolableValue);
    else
        underlyingValueOwner.set(*this, value);
}

void CSSMotionRotationInterpolationType::apply(const InterpolableValue& interpolableValue, const NonInterpolableValue* nonInterpolableValue, InterpolationEnvironment& environment) const
{
    environment.state().style()->setMotionRotation(StyleMotionRotation(
        toInterpolableNumber(interpolableValue).value(),
        toCSSMotionRotationNonInterpolableValue(*nonInterpolableValue).rotationType()));
}

} // namespace blink


text:
"""
Model of cash operation.
Needed when client want to put or get cash from machine.

"""

from mgnemu.models.base_model import BaseModel
from mgnemu.models.sales_types import CASH_RECIEPT

class CashOperation(BaseModel):

    def __init__(self, data):

        if CASH_RECIEPT in list(data.keys()):
            BaseModel.__init__(self, CASH_RECIEPT)
        else:
            raise KeyError('Unknown check key error.')

        self.__data = data[CASH_RECIEPT]

    def dumps(self):
        return {
            'id': BaseModel.check_id(),
            self.model_type: self.__data
        }

    def gen_check(self):
        dump = self.dumps()
        nums = [1 for cr in dump[CASH_RECIEPT]]
        sums = [cr[CASH_RECIEPT]['sum']
                for cr in dump[CASH_RECIEPT]]

        return dict(zip(nums, sums))


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>LogStrategy (RESThub Spring stack 2.2.0-SNAPSHOT API)</title>
<meta name="date" content="2014-09-16">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

org.resthub.web.log

Interface LogStrategy

All Known Implementing Classes:

DefaultLogStrategy

public interface LogStrategy

Implement this interface to define the behaviour of the log controller

Method Summary

Methods

Modifier and Type
Method and Description

void
logDebug(Log log)

void
logError(Log log)

void
logInfo(Log log)

void
logWarn(Log log)

Method Detail

logError

void logError(Log log)

logWarn

void logWarn(Log log)

logInfo

void logInfo(Log log)

logDebug

void logDebug(Log log)

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

Copyright © 2009–2014. All rights reserved.


text:
package io.spine.server.commandbus;

import io.spine.base.CommandMessage;
import io.spine.base.Identifier;
import io.spine.client.ActorRequestFactory;
import io.spine.core.Ack;
import io.spine.core.Command;
import io.spine.core.CommandContext;
import io.spine.core.CommandValidationError;
import io.spine.core.Status;
import io.spine.core.TenantId;
import io.spine.grpc.MemoizingObserver;
import io.spine.protobuf.AnyPacker;
import io.spine.server.BoundedContext;
import io.spine.server.ServerEnvironment;
import io.spine.server.command.AbstractAssignee;
import io.spine.server.command.Assign;
import io.spine.server.commandbus.given.DirectScheduledExecutor;
import io.spine.server.commandbus.given.MemoizingCommandFlowWatcher;
import io.spine.server.event.EventBus;
import io.spine.server.tenant.TenantIndex;
import io.spine.system.server.NoOpSystemWriteSide;
import io.spine.system.server.SystemWriteSide;
import io.spine.test.commandbus.command.CmdBusCreateProject;
import io.spine.test.commandbus.event.CmdBusProjectCreated;
import io.spine.testing.client.TestActorRequestFactory;
import io.spine.testing.server.model.ModelTests;
import io.spine.validate.ValidationError;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newHashSet;
import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat;
import static io.spine.core.CommandValidationError.INVALID_COMMAND;
import static io.spine.grpc.StreamObservers.memoizingObserver;
import static io.spine.protobuf.AnyPacker.unpack;
import static io.spine.server.commandbus.Given.ACommand.createProject;
import static io.spine.testing.core.given.GivenTenantId.generate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * Abstract base for test suites of {@code CommandBus}.
 */
@SuppressWarnings("ProtectedField") // for brevity of derived tests.
abstract class AbstractCommandBusTestSuite {

    private final boolean multitenant;

    protected ActorRequestFactory requestFactory;

    protected CommandBus commandBus;
    protected EventBus eventBus;
    protected CreateProjectAssignee createProjectAssignee;
    protected MemoizingObserver<Ack> observer;
    protected MemoizingCommandFlowWatcher watcher;
    protected TenantIndex tenantIndex;
    protected SystemWriteSide systemWriteSide;
    protected BoundedContext context;

    /**
     * A public constructor for derived test cases.
     *
     * @param multitenant the multi-tenancy status of the {@code CommandBus} under tests
     */
    AbstractCommandBusTestSuite(boolean multitenant) {
        this.multitenant = multitenant;
    }

    static Command newCommandWithoutContext() {
        var cmd = createProject();
        var invalidCmd = cmd.toBuilder()
                .setContext(CommandContext.getDefaultInstance())
                .buildPartial();
        return invalidCmd;
    }

    static void checkCommandError(Ack sendingResult,
                                  CommandValidationError validationError,
                                  Class<? extends CommandException> exceptionClass,
                                  Command cmd) {
        checkCommandError(sendingResult,
                          validationError,
                          exceptionClass.getCanonicalName(),
                          cmd);
    }

    static void checkCommandError(Ack sendingResult,
                                  CommandValidationError validationError,
                                  String errorType,
                                  Command cmd) {
        var status = sendingResult.getStatus();
        assertEquals(status.getStatusCase(), Status.StatusCase.ERROR);
        var commandId = cmd.getId();
        assertEquals(commandId, unpack(sendingResult.getMessageId()));

        var error = status.getError();
        assertEquals(errorType,
                     error.getType());
        assertEquals(validationError.getNumber(), error.getCode());
        assertFalse(error.getMessage()
                         .isEmpty());
        if (validationError == INVALID_COMMAND) {
            assertTrue(error.hasDetails());
            var details = AnyPacker.unpack(error.getDetails());
            assertThat(details).isInstanceOf(ValidationError.class);
            assertThat(((ValidationError)details).getConstraintViolationList())
                    .isNotEmpty();
        }
    }

    protected static Command newCommandWithoutTenantId() {
        var cmd = createProject();
        var commandBuilder = cmd.toBuilder();
        commandBuilder
                .getContextBuilder()
                .getActorContextBuilder()
                .setTenantId(TenantId.getDefaultInstance());
        return commandBuilder.build();
    }

    protected static Command clearTenantId(Command cmd) {
        var result = cmd.toBuilder();
        result.getContextBuilder()
              .getActorContextBuilder()
              .clearTenantId();
        return result.build();
    }

    @BeforeEach
    void setUp() {
        ModelTests.dropAllModels();

        ScheduledExecutorService executorService = new DirectScheduledExecutor();
        CommandScheduler scheduler = new ExecutorCommandScheduler(executorService);
        ServerEnvironment.instance()
                         .scheduleCommandsUsing(() -> scheduler);

        context = createContext();

        var contextAccess = context.internalAccess();
        tenantIndex = contextAccess.tenantIndex();
        systemWriteSide = NoOpSystemWriteSide.INSTANCE;

        eventBus = context.eventBus();
        watcher = new MemoizingCommandFlowWatcher();
        commandBus = CommandBus.newBuilder()
                .setMultitenant(this.multitenant)
                .injectContext(context)
                .injectSystem(systemWriteSide)
                .injectTenantIndex(tenantIndex)
                .setWatcher(watcher)
                .build();
        requestFactory =
                multitenant
                ? new TestActorRequestFactory(getClass(), generate())
                : new TestActorRequestFactory(getClass());
        createProjectAssignee = new CreateProjectAssignee();
        contextAccess.registerCommandDispatcher(createProjectAssignee);
        observer = memoizingObserver();
    }

    private BoundedContext createContext() {
        var cls = getClass();
        var name = cls.getSimpleName();
        var builder = multitenant
                      ? BoundedContext.multitenant(name)
                      : BoundedContext.singleTenant(name);
        return builder.build();
    }

    @AfterEach
    void tearDown() throws Exception {
        context.close();
    }

    @Test
    @DisplayName("post commands in bulk")
    void postCommandsInBulk() {
        var first = newCommand();
        var second = newCommand();
        List<Command> commands = newArrayList(first, second);

        // Some derived test suite classes may register the handler in setUp().
        // This prevents the repeating registration (which is an illegal operation).
        commandBus.unregister(createProjectAssignee);
        commandBus.register(createProjectAssignee);

        commandBus.post(commands, memoizingObserver());

        assertTrue(createProjectAssignee.received(first.enclosedMessage()));
        assertTrue(createProjectAssignee.received(second.enclosedMessage()));
        commandBus.unregister(createProjectAssignee);
    }

    protected Command newCommand() {
        return Given.ACommand.createProject();
    }

    protected void checkResult(Command cmd) {
        assertNull(observer.getError());
        assertTrue(observer.isCompleted());
        var ack = observer.firstResponse();
        var messageId = ack.getMessageId();
        assertEquals(cmd.getId(), Identifier.unpack(messageId));
    }

    /**
     * A sample command assignee that tells whether a handling method was invoked.
     */
    final class CreateProjectAssignee extends AbstractAssignee {

        private boolean handlerInvoked = false;
        private final Set<CommandMessage> receivedCommands = newHashSet();

        @Assign
        CmdBusProjectCreated handle(CmdBusCreateProject command, CommandContext ctx) {
            handlerInvoked = true;
            receivedCommands.add(command);
            return CmdBusProjectCreated.newBuilder()
                    .setProjectId(command.getProjectId())
                    .build();
        }

        boolean received(CommandMessage command) {
            return receivedCommands.contains(command);
        }

        boolean wasHandlerInvoked() {
            return handlerInvoked;
        }
    }
}


text:
"use strict";
var expect = require("chai").expect;

var error = require("../../lib/error");
var util  = require("util");

describe("The error factory", function () {
	it("is a function", function () {
		expect(error).to.be.a("function");
	});

	describe("creating an error object", function () {
		var result;

		var type = "collector";
		var name = "test";
		var message = "test error message";

		before(function () {
			result = error(type, name, message);
		});

		it("creates a valid error", function () {
			expect(result, "invalid").to.deep.equal({
				type    : type,
				name    : name,
				message : util.format("[%s][%s] %s", type, name, message)
			});
		});
	});
});


text:
const types = {
  INFO: Symbol('info'),
  WARN: Symbol('warn'),
  ERROR: Symbol('error')
};

const log = (type, ...args) => {
  switch (type) {
    case types.INFO:
      console.info(...args);
      break;
    case types.WARN:
      console.warn(...args);
      break;
    case types.ERROR:
      console.error(...args);
      break;
  }
}

log(types.INFO, 'Lorem ipsum dolor sit amet consectetur.');
log(types.WARN, 'CAUTION!');
log(types.ERROR, 'WTF...');


text:
#ifndef __ERRORS_H_
#define __ERRORS_H_

/**
 * Library, which encapsulates informations about various errors, which can occur during
 * user operations.
 *
 * @file		errors.h
 * @author 		Michal Konopa
 * @version		1.0.0
 * @date		25.4.2013
 */

/**
 * Encapsulates information about error, which occurred during user operation.
 */
typedef struct errors_OperError {
    int errorCode; /**< error code */
    int isSystemErrorCode; /**< indicates, wheather the error code designates system error code */
    char* descr; /**< description of the error */
} errors_OperError;

/**
 * Returns a copy of specified operation error. If the specified error is @c NULL,
 * @c NULL is returned.
 * @return copy of specified operation error
 * @return @c NULL, if the specified error is @c NULL
 */
extern errors_OperError* errors_getErrorCopy(errors_OperError* operError);

/**
 * Sets specified operation error to specified values. If both @c isSSystemErrorCode
 * and @c addErrnoString are >= 1, a string, which describes the @c errorCode will be
 * added at the end of @c userErrorDescr.
 * If pointer to operation error is @c NULL, new operation error will be created.
 * If @c operError is @c NULL, nothing is done.
 * @param @c operError pointer to pointer to operation error to set. If @c NULL, nothing
 *           is done.
 * @param @c userErrorDescr user string, describing the error
 * @param @c errorCode error code
 * @param @c isSystemErrorCode indication of system error code
 * @param @c addErrnoString indicates, whether to add an error description to user string.
 *           Applies only for system errors.
 */
extern void errors_setError(
        errors_OperError** operError, const char* userErrorDescr, int errorCode,
        int isSystemErrorCode, int addErrnoString
        );

#endif // __ERRORS_H_


text:
angular.module('ot.dialog.project.labels', [
    'ot.service.core',
    'ot.service.form',
    'ot.service.label'
])
    .controller('otDialogProjectLabels', function ($scope, $modalInstance, $http, config, ot, otFormService, otLabelService) {
        // Inject the configuration into the scope
        $scope.config = config;
        // Preparing the data
        $scope.data = config.labels;
        // Flags each label according to its presence in the project
        angular.forEach($scope.data, (label) => {
            const projectIndex = $scope.config.project.labels.findIndex((projectLabel) => {
                return projectLabel.id === label.id;
            });
            label.selected = (projectIndex >= 0);
        });
        // Label filter
        $scope.filter = {text: ""};
        $scope.labelFilterFn = function (label) {
            return labelFilterUnselectedAutoFn(label) && labelFilterTextFn(otLabelService.formatLabel(label));
        };

        function labelFilterUnselectedAutoFn(label) {
            return label.computedBy == null || label.selected;
        }

        function labelFilterTextFn(text) {
            return !$scope.filter.text || (text && text.toLowerCase().indexOf($scope.filter.text.toLowerCase()) >= 0);
        }

        // Watching for filter text change to decide if we allow the creation of a label
        $scope.labelCreation = false;
        if ($scope.config.project.links._labelFromToken && $scope.config.project.links._labelsCreate) {
            $scope.$watch("filter.text", function () {
                // If there is no match in the labels
                $scope.labelCreation = $scope.filter.text && !$scope.data.some($scope.labelFilterFn);
            });
            // Creation of the label
            $scope.createLabelFromToken = () => {
                if ($scope.filter.text) {
                    // Gets the creation form
                    ot.pageCall($http.post($scope.config.project.links._labelFromToken, {token: $scope.filter.text}))
                        .then((form) => {
                            let formConfig = {
                                form: form,
                                title: "New label",
                                submit: (data) => {
                                    return ot.call($http.post($scope.config.project.links._labelsCreate, data));
                                }
                            };
                            return otFormService.display(formConfig);
                        })
                        .then((label) => {
                            let selectedLabel = label;
                            selectedLabel.selected = true;
                            $scope.data.unshift(selectedLabel);
                            $scope.filter.text = otLabelService.formatLabel(selectedLabel);
                            $scope.labelCreation = false;
                        });
                }
            };
        }
        // Toggling the label selection
        $scope.toggleLabel = function (label) {
            if (label.computedBy == null) {
                label.selected = !label.selected;
            }
        };
        // Unselecting all (non automated) lavels
        $scope.selectNone = () => {
            angular.forEach($scope.data, (label) => {
                if (label.computedBy == null) {
                    label.selected = false;
                }
            });
        };
        // Cancelling the dialog
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
        // Submitting the dialog
        $scope.submit = function (isValid) {
            if (isValid) {
                otFormService.submitDialog(
                    config.submit,
                    $scope.data,
                    $modalInstance,
                    $scope
                );
            }
        };
    })
;