Merge "Refactor ConvertORTopoToTapiTopoTest"
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / SortPort221ByName.java
1 /*
2  * Copyright © 2019 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.common.mapping;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.io.Serializable;
12 import java.util.Comparator;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.Port;
14
15
16 /**
17  * Class to compare two String containing integer.
18  *
19  * @author Martial Coulibaly (martial.coulibaly@gfi.com) on behalf of Orange
20  *
21  */
22 @SuppressWarnings("serial")
23 @SuppressFBWarnings(
24     value = "SE_NO_SERIALVERSIONID",
25     justification = "https://github.com/rzwitserloot/lombok/wiki/WHY-NOT:-serialVersionUID")
26 public class SortPort221ByName implements Comparator<Port>, Serializable {
27
28     @Override
29     public int compare(Port port1, Port port2) {
30         return extractInt(port1) - extractInt(port2);
31     }
32
33     private int extractInt(Port port) {
34         String num = port.getPortName().replaceAll("\\D", "");
35         return num.isEmpty() ? 0 : Integer.parseInt(num);
36     }
37 }