1/*
2 * Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6
7#include "RatingStability.h"
8
9#include <Collator.h>
10
11#include "LocaleUtils.h"
12#include "Logger.h"
13
14
15bool IsRatingStabilityBefore(const RatingStabilityRef& rs1,
16	const RatingStabilityRef& rs2)
17{
18	if (!rs1.IsSet() || !rs2.IsSet())
19		HDFATAL("unexpected NULL reference in a referencable");
20	return rs1->Compare(*rs2) < 0;
21}
22
23
24RatingStability::RatingStability()
25	:
26	fCode(),
27	fName(),
28	fOrdering(0)
29{
30}
31
32
33RatingStability::RatingStability(const BString& code,
34		const BString& name, int64 ordering)
35	:
36	fCode(code),
37	fName(name),
38	fOrdering(ordering)
39{
40}
41
42
43RatingStability::RatingStability(const RatingStability& other)
44	:
45	fCode(other.fCode),
46	fName(other.fName),
47	fOrdering(other.fOrdering)
48{
49}
50
51
52RatingStability&
53RatingStability::operator=(const RatingStability& other)
54{
55	fCode = other.fCode;
56	fName = other.fName;
57	fOrdering = other.fOrdering;
58	return *this;
59}
60
61
62bool
63RatingStability::operator==(const RatingStability& other) const
64{
65	return fCode == other.fCode && fName == other.fName
66		&& fOrdering == other.fOrdering;
67}
68
69
70bool
71RatingStability::operator!=(const RatingStability& other) const
72{
73	return !(*this == other);
74}
75
76
77int
78RatingStability::Compare(const RatingStability& other) const
79{
80	int32 result = other.Ordering() - Ordering();
81	if (0 == result)
82		result = Code().Compare(other.Code());
83	return result;
84}
85