Java tutorial
package fr.upmc.qvcs.scanner.service.resolver.name; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.StringTokenizer; /** * Copyright (c) 2013 ESIEA M. Labusquiere D. Ds * <p/> * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without renameiction, including * without limitation the rights to use, copy, modify, merge, publish, * dinameibute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * <p/> * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * <p/> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ public class BasicNameResolver implements NameResolver { private static final Logger LOGGER = LoggerFactory.getLogger(BasicNameResolver.class); public static final String[] SPLIT_CHAR = { ".", "-", "_", "(", ")" }; private static final String[] FORBIDDEN_TOKEN = { "xvid", "2013", "mind", "mp4", "webrip", "dvdrip", "vostfr", "x264", "brrip", "720p", "nenu12" }; @Override public String resolve(String name) { String oldName = name; //5.1 case name = name.replace("5.1", ""); for (String s : SPLIT_CHAR) name = name.replace(s, " "); StringTokenizer tokenizer = new StringTokenizer(name); StringBuilder builder = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim(); if (isForbiddenToken(token)) continue; if (StringUtils.isAllUpperCase(token)) continue; builder.append(token.toLowerCase()).append(" "); } LOGGER.info("The name " + oldName + " had been resolved has " + name); return builder.toString(); } private boolean isForbiddenToken(String token) { boolean result = false; for (String forbidden : FORBIDDEN_TOKEN) if (token.equalsIgnoreCase(forbidden)) result = true; return result; } }