[LIB-13] Functional for working with strings moved to StringUtils
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / ScannerType.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.scanner;
18
19 import static org.hedgecode.chess.scanner.ScannerConstants.*;
20
21 /**
22  * ScannerType
23  *
24  * @author Dmitry Samoshin aka gotty
25  */
26 public enum ScannerType {
27
28     CHESSGAMES ( TYPE_CHESSGAMES, DOMAIN_CHESSGAMES ),
29     LICHESS    ( TYPE_LICHESS,    DOMAIN_LICHESS    ),
30     CHESSBOMB  ( TYPE_CHESSBOMB,  DOMAIN_CHESSBOMB  ),
31     CHESS24    ( TYPE_CHESS24,    DOMAIN_CHESS24    ),
32     CHESSCOM   ( TYPE_CHESSCOM,   DOMAIN_CHESSCOM   ),
33     CHESS2700  ( TYPE_2700CHESS,  DOMAIN_2700CHESS  );
34
35     private String type;
36     private String domain;
37
38     ScannerType(String type, String domain) {
39         this.type = type;
40         this.domain = domain;
41     }
42
43     public String type() {
44         return type;
45     }
46
47     public String domain() {
48         return domain;
49     }
50
51     public static ScannerType byType(String type) {
52         for (ScannerType scannerType : ScannerType.values()) {
53             if (scannerType.type.equals(type))
54                 return scannerType;
55         }
56         return null;
57     }
58
59     public static ScannerType byHost(String host) {
60         if (host != null) {
61             for (ScannerType scannerType : ScannerType.values()) {
62                 if (StringUtils.belongDomain(scannerType.domain, host)) {
63                     return scannerType;
64                 }
65             }
66         }
67         return null;
68     }
69
70 }