List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:com.asakusafw.dmdl.thundergate.Main.java
/** * ??/*from w w w.ja v a 2 s . com*/ * @param args ? * @return ?? * @throws IllegalStateException ???? */ public static Configuration loadConfigurationFromArguments(String[] args) { assert args != null; CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(OPTIONS, args); } catch (ParseException e) { throw new IllegalStateException(e); } Configuration result = new Configuration(); String jdbc = getOption(cmd, OPT_JDBC_CONFIG, true); try { Properties jdbcProps = loadProperties(jdbc); result.setJdbcDriver(findProperty(jdbcProps, Constants.K_JDBC_DRIVER)); result.setJdbcUrl(findProperty(jdbcProps, Constants.K_JDBC_URL)); result.setJdbcUser(findProperty(jdbcProps, Constants.K_JDBC_USER)); result.setJdbcPassword(findProperty(jdbcProps, Constants.K_JDBC_PASSWORD)); result.setDatabaseName(findProperty(jdbcProps, Constants.K_DATABASE_NAME)); LOG.info("JDBC??????: {}", jdbcProps); } catch (IOException e) { throw new IllegalStateException( MessageFormat.format("JDBC?????????: -{0}={1}", OPT_JDBC_CONFIG.getOpt(), jdbc), e); } String output = getOption(cmd, OPT_OUTPUT, true); result.setOutput(new File(output)); LOG.info("Output: {}", output); String includes = getOption(cmd, OPT_INCLUDES, false); if (includes != null && includes.isEmpty() == false) { try { Pattern pattern = Pattern.compile(includes, Pattern.CASE_INSENSITIVE); result.setMatcher(new ModelMatcher.Regex(pattern)); LOG.info("Inclusion: {}", pattern); } catch (PatternSyntaxException e) { throw new IllegalArgumentException(MessageFormat .format("??????????: {0}", includes), e); } } else { result.setMatcher(ModelMatcher.ALL); } String excludes = getOption(cmd, OPT_EXCLUDES, false); if (excludes != null && excludes.isEmpty() == false) { try { Pattern pattern = Pattern.compile(excludes, Pattern.CASE_INSENSITIVE); result.setMatcher(new ModelMatcher.And(result.getMatcher(), new ModelMatcher.Not(new ModelMatcher.ConstantTable(Constants.SYSTEM_TABLE_NAMES)), new ModelMatcher.Not(new ModelMatcher.Regex(pattern)))); LOG.info("Exclusion: {}", pattern); } catch (PatternSyntaxException e) { throw new IllegalArgumentException(MessageFormat .format("??????????: {0}", excludes), e); } } else { result.setMatcher(new ModelMatcher.And(result.getMatcher(), new ModelMatcher.Not(new ModelMatcher.ConstantTable(Constants.SYSTEM_TABLE_NAMES)))); } String encoding = getOption(cmd, OPT_ENCODING, false); if (encoding != null) { try { Charset charset = Charset.forName(encoding); result.setEncoding(charset); LOG.info("Encoding: {}", charset); } catch (Exception e) { result.setEncoding(Constants.OUTPUT_ENCODING); } } else { result.setEncoding(Constants.OUTPUT_ENCODING); } checkIf(cmd, OPT_SID_COLUMN, OPT_TIMESTAMP_COLUMN); checkIf(cmd, OPT_TIMESTAMP_COLUMN, OPT_SID_COLUMN); checkIf(cmd, OPT_SID_COLUMN, OPT_DELETE_FLAG_COLUMN); checkIf(cmd, OPT_SID_COLUMN, OPT_DELETE_FLAG_VALUE); checkIf(cmd, OPT_DELETE_FLAG_COLUMN, OPT_DELETE_FLAG_VALUE); checkIf(cmd, OPT_DELETE_FLAG_VALUE, OPT_DELETE_FLAG_COLUMN); String sidColumn = trim(getOption(cmd, OPT_SID_COLUMN, false)); String timestampColumn = trim(getOption(cmd, OPT_TIMESTAMP_COLUMN, false)); String deleteFlagColumn = trim(getOption(cmd, OPT_DELETE_FLAG_COLUMN, false)); String deleteFlagValue = trim(getOption(cmd, OPT_DELETE_FLAG_VALUE, false)); if (deleteFlagValue != null) { // FIXME get "bare" string List<String> arguments = Arrays.asList(args); int index = arguments.indexOf('-' + OPT_DELETE_FLAG_VALUE.getOpt()); assert index >= 0; assert arguments.size() > index + 1; deleteFlagValue = trim(arguments.get(index + 1)); } result.setSidColumn(sidColumn); result.setTimestampColumn(timestampColumn); result.setDeleteFlagColumn(deleteFlagColumn); if (deleteFlagValue != null) { try { DmdlParser dmdl = new DmdlParser(); AstLiteral literal = dmdl.parseLiteral(deleteFlagValue); result.setDeleteFlagValue(literal); } catch (DmdlSyntaxException e) { throw new IllegalArgumentException(MessageFormat.format( "???Java???????????: {0}", deleteFlagValue), e); } } String recordLockDdlOutput = getOption(cmd, OPT_RECORD_LOCK_DDL_OUTPUT, false); if (recordLockDdlOutput != null) { result.setRecordLockDdlOutput(new File(recordLockDdlOutput)); } return result; }
From source file:Main.java
public static <T> Collection<T> move(List<T> collection, int fromPosition, int toPosition) { int maxPosition = collection.size() - 1; if (fromPosition == toPosition || fromPosition > maxPosition || toPosition > maxPosition) return collection; if (fromPosition < toPosition) { T fromModel = collection.get(fromPosition); T toModel = collection.get(toPosition); collection.remove(fromPosition); collection.add(collection.indexOf(toModel) + 1, fromModel); } else {/* w w w.j a v a 2 s . co m*/ T fromModel = collection.get(fromPosition); collection.remove(fromPosition); collection.add(toPosition, fromModel); } return collection; }
From source file:forge.quest.QuestUtilUnlockSets.java
/** * Consider unlocking a new expansion in limited quest format. * @param qData the QuestController for the current quest * @param freeUnlock this unlock is free (e.g., a challenge reward), NOT IMPLEMENTED YET * @param presetChoices List<CardEdition> a pregenerated list of options, NOT IMPLEMENTED YET * @return CardEdition, the unlocked edition if any. *//*from ww w. jav a 2 s .c om*/ public static ImmutablePair<CardEdition, Integer> chooseSetToUnlock(final QuestController qData, final boolean freeUnlock, List<CardEdition> presetChoices) { if (qData.getFormat() == null || !qData.getFormat().canUnlockSets()) { return null; } final ReadPriceList prices = new ReadPriceList(); final Map<String, Integer> mapPrices = prices.getPriceList(); final List<ImmutablePair<CardEdition, Integer>> setPrices = new ArrayList<ImmutablePair<CardEdition, Integer>>(); for (CardEdition ed : getUnlockableEditions(qData)) { int price = UNLOCK_COST; if (mapPrices.containsKey(ed.getName() + " Booster Pack")) { price = Math.max( new Double(30 * Math.pow(Math.sqrt(mapPrices.get(ed.getName() + " Booster Pack")), 1.70)) .intValue(), UNLOCK_COST); } setPrices.add(ImmutablePair.of(ed, price)); } final String setPrompt = "You have " + qData.getAssets().getCredits() + " credits. Unlock:"; List<String> options = new ArrayList<String>(); for (ImmutablePair<CardEdition, Integer> ee : setPrices) { options.add(String.format("%s [PRICE: %d credits]", ee.left.getName(), ee.right)); } int index = options.indexOf(SGuiChoose.oneOrNone(setPrompt, options)); if (index < 0 || index >= options.size()) { return null; } ImmutablePair<CardEdition, Integer> toBuy = setPrices.get(index); int price = toBuy.right; CardEdition choosenEdition = toBuy.left; if (qData.getAssets().getCredits() < price) { SOptionPane.showMessageDialog( "Unfortunately, you cannot afford that set yet.\n" + "To unlock " + choosenEdition.getName() + ", you need " + price + " credits.\n" + "You have only " + qData.getAssets().getCredits() + " credits.", "Failed to unlock " + choosenEdition.getName(), null); return null; } if (!SOptionPane .showConfirmDialog( "Unlocking " + choosenEdition.getName() + " will cost you " + price + " credits.\n" + "You have " + qData.getAssets().getCredits() + " credits.\n\n" + "Are you sure you want to unlock " + choosenEdition.getName() + "?", "Confirm Unlocking " + choosenEdition.getName())) { return null; } return toBuy; }
From source file:cpcc.vvrte.services.task.AcoTspSimple.java
/** * @param costMatrix the cost matrix.//from w w w . jav a 2 s . co m * @param pheromoneTrails the pheromone trails. * @param used the list of used values. * @param current the current value. * @param soughtTotal the total sought. * @return the weight sum. */ private static int findSumWeight(double[][] costMatrix, double[][] pheromoneTrails, List<Integer> used, int current, double soughtTotal) { double runningTotal = 0.0; int next = 0; for (int city = 0; city < costMatrix.length; city++) { if (runningTotal >= soughtTotal) { break; } if (used.indexOf(city) == -1) { runningTotal += (1.0 + pheromoneTrails[current][city]) / (1.0 + costMatrix[current][city]); next = city; } } return next; }
From source file:edu.uci.ics.jung.algorithms.metrics.TriadicCensus.java
/** * Returns an array whose ith element (for i in [1,16]) is the number of * occurrences of the corresponding triad type in <code>g</code>. * (The 0th element is not meaningful; this array is effectively 1-based.) * //from w w w . j av a2 s.c om * @param g */ public static <V, E> long[] getCounts(DirectedGraph<V, E> g) { long[] count = new long[MAX_TRIADS]; List<V> id = new ArrayList<V>(g.getVertices()); // apply algorithm to each edge, one at at time for (int i_v = 0; i_v < g.getVertexCount(); i_v++) { V v = id.get(i_v); for (V u : g.getNeighbors(v)) { int triType = -1; if (id.indexOf(u) <= i_v) continue; Set<V> neighbors = new HashSet<V>(CollectionUtils.union(g.getNeighbors(u), g.getNeighbors(v))); neighbors.remove(u); neighbors.remove(v); if (g.isSuccessor(v, u) && g.isSuccessor(u, v)) { triType = 3; } else { triType = 2; } count[triType] += g.getVertexCount() - neighbors.size() - 2; for (V w : neighbors) { if (shouldCount(g, id, u, v, w)) { count[triType(triCode(g, u, v, w))]++; } } } } int sum = 0; for (int i = 2; i <= 16; i++) { sum += count[i]; } int n = g.getVertexCount(); count[1] = n * (n - 1) * (n - 2) / 6 - sum; return count; }
From source file:Main.java
/** * Returns a three-element array of mutable {@code List}s: * <ol>//from w w w. j a v a 2 s .co m * </li> * the intersection of {@code a} and {@code b} * <li> * </li> * the {@code a} - {@code b} difference * <li> * </li> * the {@code b} - {@code a} difference * <li> * </ol> * * @param comparator * a comparator to sort results, or {@code null} to remain * unsorted */ public static <T> List<T>[] getIntersectAndDiffs(Collection<? extends T> a, Collection<? extends T> b, Comparator<T> comparator) { int aSize = a.size(); List<T> aDiff = new ArrayList<T>(aSize); aDiff.addAll(a); int bSize = b.size(); List<T> bDiff = new ArrayList<T>(bSize); bDiff.addAll(b); if (comparator != null) { Collections.sort(aDiff, comparator); Collections.sort(bDiff, comparator); } List<T> abInter = new ArrayList<T>(Math.min(aSize, bSize)); for (int i = aDiff.size() - 1; i >= 0; i--) { T element = aDiff.get(i); int index = comparator == null ? bDiff.indexOf(element) : Collections.binarySearch(bDiff, element, comparator); if (index != -1) { bDiff.remove(index); aDiff.remove(i); abInter.add(element); } } @SuppressWarnings({ "unchecked" }) List<T>[] array = (List<T>[]) new List[] { abInter, aDiff, bDiff }; return array; }
From source file:de.micromata.genome.gwiki.page.impl.wiki.macros.GWikiScrollNextPrevPageMacro.java
public static GWikiElementInfo getSilbling(boolean prevPage, GWikiContext wikiContext, GWikiElementByOrderComparator comparator) { GWikiElement el = wikiContext.getCurrentElement(); if (el == null) { return null; }//from w w w . j a v a 2 s.co m GWikiElementInfo pif = el.getElementInfo().getParent(wikiContext); if (pif == null) { return null; } List<GWikiElementInfo> cl = wikiContext.getElementFinder().getDirectChilds(pif); if (comparator != null) { Collections.sort(cl, comparator); } else { Collections.sort(cl, new GWikiElementByChildOrderComparator( new GWikiElementByOrderComparator(new GWikiElementByIntPropComparator("ORDER", 0)))); } int curIdx = cl.indexOf(el.getElementInfo()); if (curIdx == -1) { return null; } if (prevPage == true) { --curIdx; if (curIdx < 0) { return null; } } else { ++curIdx; if (curIdx >= cl.size()) { return null; } } GWikiElementInfo ninf = cl.get(curIdx); return ninf; }
From source file:it.eng.spagobi.engines.worksheet.bo.WorkSheetDefinition.java
public static void addDomainValuesFilters(List<Attribute> toReturn, List<Attribute> sheetFilters) { Iterator<Attribute> it = sheetFilters.iterator(); while (it.hasNext()) { Attribute aFilter = it.next(); if (toReturn.contains(aFilter)) { int index = toReturn.indexOf(aFilter); Attribute previousFilter = toReturn.get(index); List<String> previousValues = previousFilter.getValuesAsList(); List<String> newValues = aFilter.getValuesAsList(); List<String> sum = ListUtils.sum(previousValues, newValues); previousFilter.setValues(sum); } else {//from w w w.j av a 2 s.c o m Attribute clone = aFilter.clone(); toReturn.add(clone); } } }
From source file:edu.illinois.cs.cogcomp.utils.Utils.java
/** * This reads data from the Anne Irvine, CCB paper called Transliterating from Any Language. * @return/*from w w w . j a v a 2s .c om*/ */ public static List<Example> readCCBData(String srccode, String targetcode) throws FileNotFoundException { List<Example> examples = new ArrayList<>(); String fname = "/shared/corpora/transliteration/from_anne_irvine/wikipedia_names"; List<String> lines = LineIO.read(fname); List<String> key = Arrays.asList(lines.get(0).split("\t")); int srcind = key.indexOf(srccode); int tgtind = key.indexOf(targetcode); System.out.println(srcind + ", " + tgtind); int i = 0; for (String line : lines) { if (i == 0 || line.trim().length() == 0) { i++; continue; } String[] sline = line.split("\t"); // Java removes whitespace at the end of a line. if (tgtind >= sline.length) { i++; continue; } String src = sline[srcind].trim(); String tgt = sline[tgtind].trim(); if (src.length() > 0 && tgt.length() > 0) { Example e = new Example(src, tgt); examples.add(e); } i++; } return examples; }
From source file:de.tudarmstadt.ukp.argumentation.data.roomfordebate.DataFetcher.java
/** * Saves first N comments of a given article to a text file * * @param comments comments/* w w w .j av a 2 s.c om*/ * @param outputFile output file * @param article corresponding article * @throws IOException exception */ private static void saveCommentsToText(List<Comment> comments, File outputFile, Article article) throws IOException { PrintWriter pw = new PrintWriter(outputFile, "utf-8"); // take first 10 comments List<Comment> firstTen = comments.subList(0, comments.size() > FIRST_N_COMMENTS ? FIRST_N_COMMENTS : comments.size()); // collect IDs for mapping to 1-10 List<String> ids = new ArrayList<>(); for (Comment comment : firstTen) { ids.add(comment.getId()); } // header pw.printf("Debate title: %s%n%nDebate description: %s%n%nArticle title: %s%n%n", article.getDebateTitle(), article.getDebateDescription(), article.getTitle()); for (Comment comment : firstTen) { pw.printf("#%s %s%s%n%n%s%n%n%n", ids.indexOf(comment.getId()) + 1, comment.getCommenterName().replaceAll("\\s+", "_"), comment.getParentId() != null ? " ReactsTo #" + (ids.indexOf(comment.getParentId()) + 1) : "", StringUtils.join(comment.getText().split("\n"), "\n\n")); } IOUtils.closeQuietly(pw); }