49217eace7641ad4f76bf9adba1f3cf57c759f20
[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
34     private String type;
35     private String domain;
36
37     ScannerType(String type, String domain) {
38         this.type = type;
39         this.domain = domain;
40     }
41
42     public String type() {
43         return type;
44     }
45
46     public String domain() {
47         return domain;
48     }
49
50     public static ScannerType byType(String type) {
51         for (ScannerType scannerType : ScannerType.values()) {
52             if (scannerType.type.equals(type))
53                 return scannerType;
54         }
55         return null;
56     }
57
58     public static ScannerType byHost(String host) {
59         if (host != null) {
60             for (ScannerType scannerType : ScannerType.values()) {
61                 if (host.contains(scannerType.domain))
62                     return scannerType;
63             }
64         }
65         return null;
66     }
67
68 }