List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:se.uu.it.cs.recsys.ruleminer.datastructure.builder.FPTreeHeaderTableBuilder.java
/** * * @param idAndCount item id and count/* w w w . j a v a 2 s .c om*/ * @param threshold, min support * @return non-null HeaderTableItem if the input contains id meets threshold * requirement; otherwise null. */ public static List<HeaderTableItem> build(Map<Integer, Integer> idAndCount, Integer threshold) { List<HeaderTableItem> instance = new ArrayList<>(); Map<Integer, Integer> filteredIdAndCount = Util.filter(idAndCount, threshold); if (filteredIdAndCount.isEmpty()) { LOGGER.debug("Empty map after filtering. Empty list will be returned. Source: {}", idAndCount); return instance; } List<Integer> countList = new ArrayList<>(filteredIdAndCount.values()); Collections.sort(countList); Collections.reverse(countList);// now the count is in DESC order for (int i = 1; i <= filteredIdAndCount.size(); i++) { instance.add(new HeaderTableItem()); // in order to call list.set(idx,elem) } Map<Integer, Set<Integer>> forIdsHavingSameCount = new HashMap<>();//different ids may have same count filteredIdAndCount.entrySet().forEach((entry) -> { Integer courseId = entry.getKey(); Integer count = entry.getValue(); Integer countFrequence = Collections.frequency(countList, count); if (countFrequence == 1) { Integer countIdx = countList.indexOf(count); instance.set(countIdx, new HeaderTableItem(new Item(courseId, count))); } else { // different ids have same count if (!forIdsHavingSameCount.containsKey(count)) { forIdsHavingSameCount.put(count, Util.findDuplicatesIndexes(countList, count)); } Iterator<Integer> itr = forIdsHavingSameCount.get(count).iterator(); Integer idx = itr.next(); itr.remove(); instance.set(idx, new HeaderTableItem(new Item(courseId, count))); } }); // LOGGER.debug("Final built header table: {}", // instance.stream() // .map(headerItem -> headerItem.getItem()).collect(Collectors.toList())); return instance; }
From source file:edu.wpi.checksims.algorithm.similaritymatrix.SimilarityMatrix.java
/** * Generate a Similarity Matrix with archive submissions. * * The result is not a square matrix. Only the input submissions are on the X axis, but the Y axis contains both * input and archive submissions./* w w w. j av a 2 s. c om*/ * * @param inputSubmissions Submissions used to generate matrix * @param archiveSubmissions Archive submissions - only compared to input submissions, not to each other * @param results Results used to build matrix * @return Similarity matrix built from given results * @throws InternalAlgorithmError Thrown on missing results, or results containing a submission not in the input */ public static SimilarityMatrix generateMatrix(Set<Submission> inputSubmissions, Set<Submission> archiveSubmissions, Set<AlgorithmResults> results) throws InternalAlgorithmError { checkNotNull(inputSubmissions); checkNotNull(archiveSubmissions); checkNotNull(results); checkArgument(!inputSubmissions.isEmpty(), "Must provide at least 1 submission to build matrix from"); checkArgument(!results.isEmpty(), "Must provide at least 1 AlgorithmResults to build matrix from!"); Set<Submission> setOfBoth = new HashSet<>(); setOfBoth.addAll(inputSubmissions); setOfBoth.addAll(archiveSubmissions); checkArgument(setOfBoth.size() == (archiveSubmissions.size() + inputSubmissions.size()), "Some submissions were found in both archive and input submissions!"); // If there are no archive submissions, just generate using the other function if (archiveSubmissions.isEmpty()) { return generateMatrix(inputSubmissions, results); } List<Submission> xSubmissions = Ordering.natural().immutableSortedCopy(inputSubmissions); List<Submission> ySubmissions = new ArrayList<>(); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(inputSubmissions)); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(archiveSubmissions)); MatrixEntry[][] matrix = new MatrixEntry[xSubmissions.size()][ySubmissions.size()]; // Generate the matrix // First, handle identical submissions for (Submission xSub : xSubmissions) { // Get the X index int xIndex = xSubmissions.indexOf(xSub); int yIndex = ySubmissions.indexOf(xSub); matrix[xIndex][yIndex] = new MatrixEntry(xSub, xSub, xSub.getNumTokens()); } // Now iterate through all given algorithm results for (AlgorithmResults result : results) { int aXCoord = xSubmissions.indexOf(result.a); int bXCoord = xSubmissions.indexOf(result.b); if (aXCoord == -1 && bXCoord == -1) { throw new InternalAlgorithmError("Neither submission \"" + result.a.getName() + "\" nor \"" + result.b.getName() + "\" were found in input submissions!"); } if (aXCoord != -1) { int bYCoord = ySubmissions.indexOf(result.b); matrix[aXCoord][bYCoord] = new MatrixEntry(result.a, result.b, result.identicalTokensA); } if (bXCoord != -1) { int aYCoord = ySubmissions.indexOf(result.a); matrix[bXCoord][aYCoord] = new MatrixEntry(result.b, result.a, result.identicalTokensB); } } // Verification pass - ensure we built a matrix with no nulls for (int x = 0; x < xSubmissions.size(); x++) { for (int y = 0; y < ySubmissions.size(); y++) { if (matrix[x][y] == null) { throw new InternalAlgorithmError("Missing Algorithm Results for comparison of submissions \"" + xSubmissions.get(x).getName() + "\" and \"" + ySubmissions.get(y).getName() + "\""); } } } return new SimilarityMatrix(matrix, xSubmissions, ySubmissions, results); }
From source file:Main.java
public Object getNextValue() { List list = getList(); int index = list.indexOf(getValue()); index = (index >= list.size() - 1) ? 0 : index + 1; return list.get(index); }
From source file:Main.java
public Object getPreviousValue() { List list = getList(); int index = list.indexOf(getValue()); index = (index <= 0) ? list.size() - 1 : index - 1; return list.get(index); }
From source file:Main.java
/** * Method by Adrian: [//from ww w. j a v a 2 s . c o m * <a href="http://stackoverflow.com/a/15704264/5620200">StackOverflow</a> ] * & Mike: [ <a href= * "http://stackoverflow.com/questions/1542170/arranging-nodes-in-a-jtree"> * StackOverflow</a> ] * * @param node * @return */ @SuppressWarnings("unchecked") public static DefaultMutableTreeNode sort(DefaultMutableTreeNode node) { List<DefaultMutableTreeNode> children = Collections.list(node.children()); List<String> orgCnames = new ArrayList<String>(); List<String> cNames = new ArrayList<String>(); DefaultMutableTreeNode temParent = new DefaultMutableTreeNode(); for (DefaultMutableTreeNode child : children) { DefaultMutableTreeNode ch = (DefaultMutableTreeNode) child; temParent.insert(ch, 0); String uppser = ch.toString().toUpperCase(); // Not dependent on package name, so if duplicates are found // they will later on be confused. Adding this is of // very little consequence and fixes the issue. if (cNames.contains(uppser)) { uppser += "$COPY"; } cNames.add(uppser); orgCnames.add(uppser); if (!child.isLeaf()) { sort(child); } } Collections.sort(cNames); for (String name : cNames) { int indx = orgCnames.indexOf(name); int insertIndex = node.getChildCount(); node.insert(children.get(indx), insertIndex); } // Fixing folder placement for (int i = 0; i < node.getChildCount() - 1; i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i); for (int j = i + 1; j <= node.getChildCount() - 1; j++) { DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) node.getChildAt(j); if (!prevNode.isLeaf() && child.isLeaf()) { node.insert(child, j); node.insert(prevNode, i); } } } return node; }
From source file:net.lldp.checksims.algorithm.similaritymatrix.SimilarityMatrix.java
/** * Generate a Similarity Matrix with archive submissions. * * The result is not a square matrix. Only the input submissions are on the X axis, but the Y axis contains both * input and archive submissions.// w w w. ja v a2 s. co m * * @param inputSubmissions Submissions used to generate matrix * @param archiveSubmissions Archive submissions - only compared to input submissions, not to each other * @param results Results used to build matrix * @return Similarity matrix built from given results * @throws InternalAlgorithmError Thrown on missing results, or results containing a submission not in the input */ public static SimilarityMatrix generateMatrix(Set<Submission> inputSubmissions, Set<Submission> archiveSubmissions, Set<AlgorithmResults> results) throws InternalAlgorithmError { checkNotNull(inputSubmissions); checkNotNull(archiveSubmissions); checkNotNull(results); checkArgument(!inputSubmissions.isEmpty(), "Must provide at least 1 submission to build matrix from"); checkArgument(!results.isEmpty(), "Must provide at least 1 AlgorithmResults to build matrix from!"); Set<Submission> setOfBoth = new HashSet<>(); setOfBoth.addAll(inputSubmissions); setOfBoth.addAll(archiveSubmissions); checkArgument(setOfBoth.size() == (archiveSubmissions.size() + inputSubmissions.size()), "Some submissions were found in both archive and input submissions!"); // If there are no archive submissions, just generate using the other function if (archiveSubmissions.isEmpty()) { return generateMatrix(inputSubmissions, results); } List<Submission> xSubmissions = Ordering.natural().immutableSortedCopy(inputSubmissions); List<Submission> ySubmissions = new ArrayList<>(); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(inputSubmissions)); ySubmissions.addAll(Ordering.natural().immutableSortedCopy(archiveSubmissions)); AlgorithmResults[][] matrix = new AlgorithmResults[xSubmissions.size()][ySubmissions.size()]; // Generate the matrix // First, handle identical submissions for (Submission xSub : xSubmissions) { // Get the X index int xIndex = xSubmissions.indexOf(xSub); int yIndex = ySubmissions.indexOf(xSub); matrix[xIndex][yIndex] = new AlgorithmResults(Pair.of(xSub, xSub), Real.ONE, Real.ONE); } // Now iterate through all given algorithm results for (AlgorithmResults result : results) { int aXCoord = xSubmissions.indexOf(result.a); int bXCoord = xSubmissions.indexOf(result.b); if (aXCoord == -1 && bXCoord == -1) { throw new InternalAlgorithmError("Neither submission \"" + result.a.getName() + "\" nor \"" + result.b.getName() + "\" were found in input submissions!"); } if (aXCoord != -1) { int bYCoord = ySubmissions.indexOf(result.b); matrix[aXCoord][bYCoord] = result.inverse(); } if (bXCoord != -1) { int aYCoord = ySubmissions.indexOf(result.a); matrix[bXCoord][aYCoord] = result; } } // Verification pass - ensure we built a matrix with no nulls for (int x = 0; x < xSubmissions.size(); x++) { for (int y = 0; y < ySubmissions.size(); y++) { if (matrix[x][y] == null) { throw new InternalAlgorithmError("Missing Algorithm Results for comparison of submissions \"" + xSubmissions.get(x).getName() + "\" and \"" + ySubmissions.get(y).getName() + "\""); } } } return new SimilarityMatrix(matrix, xSubmissions, ySubmissions, results); }
From source file:com.funambol.common.pim.utility.PDIMergeUtils.java
/** * Merges the given two lists of TypifiedProperty objects * * @param list1 the first list (must be not null) * @param list2 the second list/* ww w. j a v a 2 s . c o m*/ * @return true if the first list is changed */ public static MergeResult mergeTypifiedPropertiestList(List list1, List list2) { if (list1 == null || list2 == null) { throw new IllegalStateException("The lists must not be null"); } List typeAlreadyHandled = new ArrayList(); MergeResult listMergeResult = new MergeResult(); if (list2.size() > 0) { Iterator it = list2.iterator(); TypifiedProperty p = null; int pos2 = -1; while (it.hasNext()) { p = (TypifiedProperty) it.next(); pos2 = list2.indexOf(p); typeAlreadyHandled.add(p.getPropertyType()); // // We add/set a property only if his value isn't empty (or null) // int pos1 = list1.indexOf(p); if (pos1 < 0) { if (StringUtils.isNotEmpty(p.getPropertyValueAsString())) { list1.add(p); listMergeResult.addPropertyA(p.getPropertyType()); } } else { // // There is already a property with the same type // MergeResult mergePropertyResult = compareProperties((TypifiedProperty) list1.get(pos1), p); if (mergePropertyResult.isSetARequired()) { list1.set(pos1, p); listMergeResult.addPropertyA(p.getPropertyType()); } if (mergePropertyResult.isSetBRequired()) { list2.set(pos2, (TypifiedProperty) list1.get(pos1)); listMergeResult.addPropertyB(((TypifiedProperty) list1.get(pos1)).getPropertyType()); } } } } // // Now we loop on list1 ignoring the properties already handled // The properties not handled are sure only in list1 // if (list1.size() > 0) { Iterator it = list1.iterator(); TypifiedProperty p = null; while (it.hasNext()) { p = (TypifiedProperty) it.next(); if (typeAlreadyHandled.indexOf(p.getPropertyType()) != -1) { // // This property is already handled // continue; } // // We add/set a property only if his value isn't empty (or null) // if (StringUtils.isNotEmpty(p.getPropertyValueAsString())) { list2.add(p); listMergeResult.addPropertyB(p.getPropertyType()); } } } return listMergeResult; }
From source file:com.vaadin.sass.testcases.scss.W3ConformanceTests.java
public static void extractCSS(final URI url, File targetdir) throws Exception { /*//from ww w . ja v a 2 s.co m * For each test URL: 1) extract <style> tag contents 2) extract from * <link rel="stylesheet"> files 3) extract inline style attributes from * all elements and wrap the result in .style {} */ Document doc = Jsoup.connect(url.toString()).timeout(20000).get(); List<String> tests = new ArrayList<String>(); for (Element e : doc.select("style[type=text/css]")) { tests.add(e.data()); } for (Element e : doc.select("link[rel=stylesheet][href][type=text/css]")) { URI cssUri = new URI(e.attr("href")); if (!cssUri.isAbsolute()) { cssUri = url.resolve(cssUri); } String encoding = doc.outputSettings().charset().name(); tests.add(IOUtils.toString(cssUri, encoding)); } for (Element e : doc.select("*[style]")) { tests.add(String.format(".style { %s }", e.attr("style"))); } for (final String test : tests) { targetdir.mkdirs(); String logfile = String.format("%s.%d.scss", FilenameUtils.getBaseName(url.toString()), tests.indexOf(test)); PrintStream dataLogger = new PrintStream(new File(targetdir, logfile)); dataLogger.println("/* Source: " + url + " */"); dataLogger.println(test); } }
From source file:io.personium.core.model.DavRsCmp.java
static final org.apache.wink.webdav.model.Response createDavResponse(final String pathName, final String href, final DavCmp dCmp, final Propfind propfind, final boolean isAclRead) { ObjectFactory of = new ObjectFactory(); org.apache.wink.webdav.model.Response ret = of.createResponse(); ret.getHref().add(href);/* w w w . j a va 2 s .com*/ // TODO v1.1 PROPFIND??????? if (propfind != null) { log.debug("isAllProp:" + propfind.isAllprop()); log.debug("isPropName:" + propfind.isPropname()); } else { log.debug("propfind is null"); } /* * Displayname dn = of.createDisplayname(); dn.setValue(name); ret.setPropertyOk(dn); */ Long updated = dCmp.getUpdated(); if (updated != null) { Getlastmodified lm = of.createGetlastmodified(); lm.setValue(new Date(updated)); ret.setPropertyOk(lm); } Long published = dCmp.getPublished(); if (published != null) { Creationdate cd = of.createCreationdate(); cd.setValue(new Date(published)); ret.setPropertyOk(cd); } String type = dCmp.getType(); if (DavCmp.TYPE_DAV_FILE.equals(type)) { // Dav ????? Resourcetype rt1 = of.createResourcetype(); ret.setPropertyOk(rt1); Getcontentlength gcl = new Getcontentlength(); gcl.setValue(String.valueOf(dCmp.getContentLength())); ret.setPropertyOk(gcl); String contentType = dCmp.getContentType(); Getcontenttype gct = new Getcontenttype(); gct.setValue(contentType); ret.setPropertyOk(gct); } else if (DavCmp.TYPE_COL_ODATA.equals(type)) { // OData ????? Resourcetype colRt = of.createResourcetype(); colRt.setCollection(of.createCollection()); List<Element> listElement = colRt.getAny(); QName qname = new QName(PersoniumCoreUtils.XmlConst.NS_PERSONIUM, PersoniumCoreUtils.XmlConst.ODATA, PersoniumCoreUtils.XmlConst.NS_PREFIX_PERSONIUM); Element element = WebDAVModelHelper.createElement(qname); listElement.add(element); ret.setPropertyOk(colRt); } else if (DavCmp.TYPE_COL_SVC.equals(type)) { // Service ????? Resourcetype colRt = of.createResourcetype(); colRt.setCollection(of.createCollection()); List<Element> listElement = colRt.getAny(); QName qname = new QName(PersoniumCoreUtils.XmlConst.NS_PERSONIUM, PersoniumCoreUtils.XmlConst.SERVICE, PersoniumCoreUtils.XmlConst.NS_PREFIX_PERSONIUM); Element element = WebDAVModelHelper.createElement(qname); listElement.add(element); ret.setPropertyOk(colRt); } else { // Col ????? Resourcetype colRt = of.createResourcetype(); colRt.setCollection(of.createCollection()); ret.setPropertyOk(colRt); } // ACL?? Acl acl = dCmp.getAcl(); if (isAclRead && acl != null) { Document aclDoc = null; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); try { aclDoc = dbf.newDocumentBuilder().newDocument(); ObjectIo.marshal(acl, aclDoc); } catch (Exception e) { throw new WebApplicationException(e); } if (aclDoc != null) { Element e = aclDoc.getDocumentElement(); ret.setPropertyOk(e); } } Map<String, String> props = dCmp.getProperties(); if (props != null) { List<String> nsList = new ArrayList<String>(); for (Map.Entry<String, String> entry : props.entrySet()) { String key = entry.getKey(); String val = entry.getValue(); int idx = key.indexOf("@"); String ns = key.substring(idx + 1, key.length()); int nsIdx = nsList.indexOf(ns); if (nsIdx == -1) { nsList.add(ns); } Element e = parseProp(val); ret.setPropertyOk(e); } } return ret; }
From source file:jmri.InstanceManager.java
/** * Store an object of a particular type for later retrieval via * {@link #getDefault} or {@link #getList}. * * @param <T> The type of the class * @param item The object of type T to be stored * @param type The class Object for the item's type. This will be used as * the key to retrieve the object later. *///from w ww .java2s . com static public <T> void store(@Nonnull T item, @Nonnull Class<T> type) { log.debug("Store item of type {}", type.getName()); if (item == null) { NullPointerException npe = new NullPointerException(); log.error("Should not store null value of type {}", type.getName()); throw npe; } List<T> l = getList(type); l.add(item); getDefault().pcs.fireIndexedPropertyChange(getListPropertyName(type), l.indexOf(item), null, item); }