All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webcohesion.enunciate.util.ResourceComparator Maven / Gradle / Ivy

package com.webcohesion.enunciate.util;

import com.webcohesion.enunciate.api.resources.Method;
import com.webcohesion.enunciate.api.resources.Resource;

import java.util.Comparator;
import java.util.List;

/**
 * @author Ryan Heaton
 */
public class ResourceComparator implements Comparator {

  private final Comparator pathComparator;

  public ResourceComparator(PathSortStrategy strategy) {
    if (strategy == PathSortStrategy.breadth_first) {
      pathComparator = new BreadthFirstResourcePathComparator();
    }
    else {
      pathComparator = new DepthFirstResourcePathComparator();
    }
  }

  @Override
  public int compare(Resource g1, Resource g2) {
    int compare = pathComparator.compare(g1.getPath(), g2.getPath());
    if (compare == 0) {
      List m1 = g1.getMethods();
      List m2 = g2.getMethods();
      if (m1.size() == 1 && m2.size() == 1) {
        compare = (m1.get(0).getHttpMethod().compareTo(m2.get(0).getHttpMethod()));
      }
    }
    return compare;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy