Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAbstractCollection.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JABSTRACTCOLLECTION__
2 #define __JTOOLS__JABSTRACTCOLLECTION__
3 
4 #include <math.h>
5 
6 
7 /**
8  * \author mdejong
9  */
10 
11 namespace JTOOLS {}
12 namespace JPP { using namespace JTOOLS; }
13 
14 namespace JTOOLS {
15 
16 
17  /**
18  * Abstract interface for abscissa values of a collection of elements.
19  */
20  template<class JAbscissa_t>
22  {
23  typedef JAbscissa_t abscissa_type;
24 
25 
26  /**
27  * Virtual destructor.
28  */
30  {}
31 
32 
33  /**
34  * Get number of elements.
35  *
36  * \return number of elements
37  */
38  virtual int getSize() const = 0;
39 
40 
41  /**
42  * Get abscissa value.
43  *
44  * \param index index
45  * \return abscissa value
46  */
47  virtual abscissa_type getX(int index) const = 0;
48 
49 
50  /**
51  * Get minimal abscissa value.
52  *
53  * \return abscissa value
54  */
55  virtual abscissa_type getXmin() const = 0;
56 
57 
58  /**
59  * Get maximal abscissa value.
60  *
61  * \return abscissa value
62  */
63  virtual abscissa_type getXmax() const = 0;
64 
65 
66  /**
67  * Test whether abstract collections are equal.
68  *
69  * \param collection abstract collection
70  * \return true if collections are equals; else false
71  */
72  bool is_equal(const JAbstractCollection& collection) const
73  {
74  if (this->getSize() == collection.getSize()) {
75 
76  for (int i = 0; i != this->getSize(); ++i) {
77 
78  if (this->getX(i) != collection.getX(i)) {
79  return false;
80  }
81  }
82 
83  return true;
84  }
85 
86  return false;
87  }
88 
89 
90  /**
91  * Less than method.
92  *
93  * \param first first abstract collection
94  * \param second second abstract collection
95  * \return true if first collection is less than second collection; else false
96  */
97  friend inline bool operator<(const JAbstractCollection& first,
98  const JAbstractCollection& second)
99  {
100  using namespace std;
101 
102  if (first.getSize() == second.getSize()) {
103 
104  if (fabs(first.getXmin() - second.getXmin()) > 0.0) {
105  return first.getXmin() < second.getXmin();
106  } else {
107  return first.getXmax() < second.getXmax();
108  }
109 
110  } else {
111 
112  return first.getSize() < second.getSize();
113  }
114  }
115  };
116 }
117 
118 #endif
Abstract interface for abscissa values of a collection of elements.
virtual abscissa_type getXmin() const =0
Get minimal abscissa value.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
friend bool operator<(const JAbstractCollection &first, const JAbstractCollection &second)
Less than method.
bool is_equal(const JAbstractCollection &collection) const
Test whether abstract collections are equal.
virtual ~JAbstractCollection()
Virtual destructor.
virtual abscissa_type getX(int index) const =0
Get abscissa value.
virtual abscissa_type getXmax() const =0
Get maximal abscissa value.
virtual int getSize() const =0
Get number of elements.