1 /*
2  * Hunt - A refined core library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11  module hunt.util.AcceptMimeType;
12 
13 import hunt.Functions;
14 
15 /**
16  * 
17  */
18 enum AcceptMimeMatchType {
19     PARENT, CHILD, ALL, EXACT
20 }
21 
22 
23 /**
24  * 
25  */
26 class AcceptMimeType {
27     private string parentType;
28     private string childType;
29     private float quality = 1.0f;
30     private AcceptMimeMatchType matchType;
31 
32     string getParentType() {
33         return parentType;
34     }
35 
36     void setParentType(string parentType) {
37         this.parentType = parentType;
38     }
39 
40     string getChildType() {
41         return childType;
42     }
43 
44     void setChildType(string childType) {
45         this.childType = childType;
46     }
47 
48     float getQuality() {
49         return quality;
50     }
51 
52     void setQuality(float quality) {
53         this.quality = quality;
54     }
55 
56     AcceptMimeMatchType getMatchType() {
57         return matchType;
58     }
59 
60     void setMatchType(AcceptMimeMatchType matchType) {
61         this.matchType = matchType;
62     }
63 
64     override bool opEquals(Object o) {
65         if (this is o) return true;
66         AcceptMimeType that = cast(AcceptMimeType) o;
67         if(that is null)  return false;
68 
69         return parentType == that.parentType &&
70                 childType == that.childType;
71     }
72 
73     override size_t toHash() @trusted nothrow {
74         return hashCode(parentType, childType);
75     }
76 
77     override string toString() {
78         import std.format;
79         string s = parentType ~ "/" ~ childType;
80         if(quality != 1.0f) 
81             s = s ~ format("; q=%0.1f", quality);
82         return s;
83     }
84 }