56672a827dc4ff87d05d161468e5ac99e8eb5a55
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / SortPort121ByName.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 java.util.Comparator;
11
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
13
14
15 /**
16  * Class to compare two String containing integer.
17  *
18  * @author Martial Coulibaly (martial.coulibaly@gfi.com) on behalf of Orange
19  *
20  */
21 public class SortPort121ByName implements Comparator<Port> {
22
23     @Override
24     public int compare(Port port1, Port port2) {
25         return extractInt(port1) - extractInt(port2);
26     }
27
28     private int extractInt(Port port) {
29         String num = port.getPortName().replaceAll("\\D", "");
30         return num.isEmpty() ? 0 : Integer.parseInt(num);
31     }
32 }