com.reprezen.genflow.openapi.diagram.swagger.StatusCodeComparator Maven / Gradle / Ivy
/**
* Copyright © 2013, 2016 Modelsolv, Inc.
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property
* of ModelSolv, Inc. See the file license.html in the root directory of
* this project for further information.
*/
package com.reprezen.genflow.openapi.diagram.swagger;
import com.google.common.base.Objects;
import java.util.Comparator;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
/**
* Natural ordering with exception of default response ('default') which is bigger than any normal response
*/
@SuppressWarnings("all")
public class StatusCodeComparator implements Comparator {
@Override
public int compare(final String s1, final String s2) {
final int code1 = StatusCodeComparator.safeParse(s1, Integer.MAX_VALUE);
final int code2 = StatusCodeComparator.safeParse(s2, Integer.MAX_VALUE);
return Integer.valueOf(code1).compareTo(Integer.valueOf(code2));
}
public static int safeParse(final String number, final int orDefault) {
if ((StringExtensions.isNullOrEmpty(number) || Objects.equal(number, "default"))) {
return orDefault;
}
try {
return Integer.parseInt(number);
} catch (final Throwable _t) {
if (_t instanceof NumberFormatException) {
return orDefault;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy