Here you can find the source of normalizeMatchup(final String matchup)
Parameter | Description |
---|---|
matchup | match-up to be normalized |
public static String normalizeMatchup(final String matchup)
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { /**//from w w w . j av a 2s .c om * Returns a normalized form of the specified match-up string (which can be either a race match-up or a league match-up). * * <p> * The gain of this normalization is that 2 different match-ups which are the permutations of each other have the same normalized form therefore match-up * permutations can be tested if they are equal by a simple equality filter (where we compare the normalized forms of the match-up filter and the match-up * of the entities). * </p> * * <p> * Normalization consists of the following steps: * <ol> * <li>make match-up lower-cased (e.g. <code>"ZZPvTPZ"</code> => <code>"zzpvtpz"</code>) * <li>sort letters inside teams (e.g. <code>"zzpvtpz"</code> => <code>"pzzvptz"</code>) * <li>sort teams (e.g. <code>"pzzvptz"</code> => <code>"ptzvpzz"</code>) * </ol> * </p> * * @param matchup match-up to be normalized * @return a normalized form of the specified match-up string */ public static String normalizeMatchup(final String matchup) { if (matchup == null) return null; // Step 1: lower-case final String[] teams = matchup.toLowerCase().split("v"); // Step 2: sort letters inside teams for (int i = 0; i < teams.length; i++) { final char[] letters = teams[i].toCharArray(); Arrays.sort(letters); teams[i] = new String(letters); } // Step 3: sort teams Arrays.sort(teams); // Concatenate teams and return the normalized form: final StringBuilder sb = new StringBuilder(); for (int i = 0; i < teams.length; i++) { if (i > 0) sb.append('v'); sb.append(teams[i]); } return sb.toString(); } }