List of usage examples for java.util ArrayList indexOf
public int indexOf(Object o)
From source file:psidev.psi.mi.filemakers.xsd.AbstractXsdTreeStruct.java
public void redoChoice(String path, String choice) { try {// ww w .j ava 2 s. c om XsdNode currentNode = rootNode; /* never a choice on rootNode */ String nextIndexes = path.substring(path.indexOf(".") + 1); int index = 0; Annotated annotated = (Annotated) (currentNode.getUserObject()); /* for each element on the path */ while (nextIndexes.length() > 0 && nextIndexes != "-1") { /* if choice do it */ annotated = (Annotated) (currentNode.getUserObject()); /* if not extended, do it */ if (!currentNode.isExtended) { extendPath(currentNode); } else { if (nextIndexes.indexOf(".") >= 0) { index = Integer.parseInt(nextIndexes.substring(0, nextIndexes.indexOf("."))); nextIndexes = nextIndexes.substring(nextIndexes.indexOf(".") + 1); try { currentNode = (XsdNode) currentNode.getChildAt(index); } catch (java.lang.ArrayIndexOutOfBoundsException aiobe) { /* * to keep compatibility: if mapping done without auto-duplication of nodes and * applied without this option, an exception will be raised if the node has not * been manually duplicated. In this case try to duplicate "upper" node. */ /* get upper node's index */ log.error("Index: " + path + " -> " + choice + " , " + index); duplicateNode((XsdNode) currentNode.getChildAt(index - 1)); currentNode = (XsdNode) currentNode.getChildAt(index); aiobe.printStackTrace(); } } else { index = Integer.parseInt(nextIndexes); nextIndexes = "-1"; try { currentNode = (XsdNode) currentNode.getChildAt(index); } catch (ArrayIndexOutOfBoundsException e) { e.printStackTrace(); return; } } } } /* add choice */ annotated = (Annotated) (currentNode.getUserObject()); Group g = (Group) annotated; try { if (g.getOrder().getType() == Order.CHOICE && manageChoices) { XsdNode parent = (XsdNode) currentNode.getParent(); int position = parent.getIndex(currentNode); ArrayList<Annotated> choices = getChoices(g); ArrayList<String> possibilities = new ArrayList<String>(); for (int i = 0; i < choices.size(); i++) { try { possibilities.add(((ElementDecl) choices.get(i)).getName()); } catch (ClassCastException e) { /* a group: give an overview */ possibilities.add(XsdNode.choiceToString((Group) choices.get(i))); } } XsdNode newNode; newNode = new XsdNode(choices.get(possibilities.indexOf(choice))); newNode.isRequired = currentNode.isRequired; /** * If the max occurs is specified, transfer it to the child. */ /** * TODO: check if we should verify that max/min is indedd specified for the * group. */ newNode.min = g.getMinOccurs(); // node.min; newNode.max = g.getMaxOccurs(); // node.max; // // newNode.min = currentNode.min; // newNode.max = currentNode.max; newNode.originalParent = currentNode; currentNode.transparent = true; currentNode.isExtended = true; currentNode.add(newNode); currentNode = newNode; } } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); return; } } catch (ArrayIndexOutOfBoundsException aioobe) { log.error("Restore choice, path not found: " + path); throw aioobe; } check((XsdNode) treeModel.getRoot()); treeModel.reload((XsdNode) treeModel.getRoot()); expendChoices.add(path); expendChoices.add(choice); }
From source file:psidev.psi.mi.filemakers.xsd.AbstractXsdTreeStruct.java
/** * check elements and attributes for the structure contained in this node create * nodes and add'em to the tree// w w w. j av a2 s. com */ public void extendPath(XsdNode node) { if (node.isExtended) { return; } Annotated annotated = (Annotated) (node.getUserObject()); String path = getPathForNode(node); switch (annotated.getStructureType()) { case Structure.ATTRIBUTE: break; case Structure.GROUP: /* if it's a complex type, look inside */ Group g = (Group) annotated; XsdNode parent = (XsdNode) node.getParent(); /* position is important when adding new node */ // int position = parent.getIndex(node); /* * if a sequence: add all childs, if a choice, ask user */ if (g.getOrder().getType() == Order.CHOICE && manageChoices) { XsdNode newNode; String choice = expendChoices.get(expendChoices.indexOf(path) + 1); ArrayList<Annotated> choices = getChoices(g); ArrayList<String> possibilities = new ArrayList<String>(); for (int i = 0; i < choices.size(); i++) { try { possibilities.add(((ElementDecl) choices.get(i)).getName()); } catch (ClassCastException e) { /* a group: give an overview */ possibilities.add(XsdNode.choiceToString((Group) choices.get(i))); } } newNode = new XsdNode(choices.get(possibilities.indexOf(choice))); newNode.isRequired = node.isRequired; /** * If the max occurs is specified, transfer it to the child. */ /** * TODO: check if we should verify that max/min is indedd specified for the * group. */ newNode.min = g.getMinOccurs(); // node.min; newNode.max = g.getMaxOccurs(); // node.max; newNode.originalParent = node; node.transparent = true; node.add(newNode); extendPath(newNode); // if (((Annotated) newNode.getUserObject()).getStructureType() != // Structure.GROUP) { // extendPath(newNode); // } else if (((Group) newNode.getUserObject()).getOrder().getType() != // Order.CHOICE) { // extendPath(newNode); // } } else { /* sequence */ if (g.getOrder().getType() == Order.CHOICE) { expendChoices.add(path); } int parentIndex = parent.getIndex(node); ((XsdNode) node.getParent()).remove(parent.getIndex(node)); Enumeration<Annotated> elts = g.enumerate(); boolean firstElement = true; while (elts.hasMoreElements()) { Annotated element = elts.nextElement(); XsdNode newNode = new XsdNode(element); /* * In some cases the minOccurs argument is on the sequence element instead of * the chidrens themseves. In those cases propagat it from sequence element to * the children elements */ if (node.min == 0) { newNode.min = 0; newNode.isRequired = false; } if (firstElement) { parent.insert(newNode, parentIndex); firstElement = false; } else { parent.add(newNode); } if (((Annotated) newNode.getUserObject()).getStructureType() != Structure.GROUP) { extendPath(newNode); } else if (((Group) newNode.getUserObject()).getOrder().getType() != Order.CHOICE) { extendPath(newNode); } if (autoDuplicate) { if (element.getStructureType() == Structure.ELEMENT) { for (int i = 1; i < ((ElementDecl) element).getMinOccurs(); i++) { newNode = new XsdNode(element); parent.add(newNode); if (((Annotated) newNode.getUserObject()).getStructureType() != Structure.GROUP) { extendPath(newNode); } else if (((Group) newNode.getUserObject()).getOrder().getType() != Order.CHOICE) { extendPath(newNode); } } } } } } // check((XsdNode) treeModel.getRoot()); treeModel.reload(parent); break; case Structure.ELEMENT: /* if it's a complex type, look inside */ XMLType type = ((ElementDecl) annotated).getType(); /* no type : send message */ if (type == null) { log.warn("WARNING: no type declaration for element " + node.toString()); return; } if (type.isSimpleType()) { return; } Enumeration<AttributeDecl> attributes = ((ComplexType) type).getAttributeDecls(); while (attributes.hasMoreElements()) { node.add(new XsdNode(attributes.nextElement())); } Enumeration<Particle> elements = ((ComplexType) type).enumerate(); while (elements.hasMoreElements()) { Particle ptc = elements.nextElement(); XsdNode child = new XsdNode((Annotated) ptc); node.add(child); if (ptc.getStructureType() != Structure.GROUP) { extendPath(child); } else if (((Group) child.getUserObject()).getOrder().getType() != Order.CHOICE) { extendPath(child); } } /* do not forget the base type */ try { attributes = ((ComplexType) type.getBaseType()).getAttributeDecls(); while (attributes.hasMoreElements()) { node.add(new XsdNode(attributes.nextElement())); } elements = ((ComplexType) type.getBaseType()).enumerate(); while (elements.hasMoreElements()) { Particle ptc = elements.nextElement(); XsdNode child = new XsdNode((Annotated) ptc); node.add(child); if (ptc.getStructureType() != Structure.GROUP) { extendPath(child); } else if (((Group) child.getUserObject()).getOrder().getType() != Order.CHOICE) { extendPath(child); } } } catch (Exception e) { /* no base type */ } // check((XsdNode) treeModel.getRoot()); // treeModel.reload(node); break; default: log.debug("default type: " + annotated.getStructureType()); } node.isExtended = true; }
From source file:im.vector.activity.HomeActivity.java
private void refreshPublicRoomsList(final ArrayList<MXSession> sessions, final ArrayList<String> checkedHomeServers, final int index, final ArrayList<List<PublicRoom>> publicRoomsListList) { // sanity checks if ((null == sessions) || (index >= sessions.size())) { mAdapter.setPublicRoomsList(publicRoomsListList, checkedHomeServers); mPublicRoomsListList = publicRoomsListList; mHomeServerNames = checkedHomeServers; return;/*w w w . j av a 2s . c o m*/ } final MXSession session = sessions.get(index); final String homeServer = session.getCredentials().homeServer; // the home server has already been checked ? if (checkedHomeServers.indexOf(homeServer) >= 0) { // jump to the next session refreshPublicRoomsList(sessions, checkedHomeServers, index + 1, publicRoomsListList); } else { // use any session to get the public rooms list session.getEventsApiClient().loadPublicRooms(new SimpleApiCallback<List<PublicRoom>>(this) { @Override public void onSuccess(List<PublicRoom> publicRooms) { checkedHomeServers.add(homeServer); publicRoomsListList.add(publicRooms); // jump to the next session refreshPublicRoomsList(sessions, checkedHomeServers, index + 1, publicRoomsListList); } }); } }
From source file:com.vgi.mafscaling.ClosedLoop.java
private boolean getColumnsFilters(String[] elements) { boolean ret = true; ArrayList<String> columns = new ArrayList<String>(Arrays.asList(elements)); String logClOlStatusColName = Config.getClOlStatusColumnName(); String logAfLearningColName = Config.getAfLearningColumnName(); String logAfCorrectionColName = Config.getAfCorrectionColumnName(); String logAfrColName = Config.getAfrColumnName(); String logRpmColName = Config.getRpmColumnName(); String logLoadColName = Config.getLoadColumnName(); String logTimeColName = Config.getTimeColumnName(); String logMafvColName = Config.getMafVoltageColumnName(); String logIatColName = Config.getIatColumnName(); logClOlStatusColIdx = columns.indexOf(logClOlStatusColName); logAfLearningColIdx = columns.indexOf(logAfLearningColName); logAfCorrectionColIdx = columns.indexOf(logAfCorrectionColName); logAfrColIdx = columns.indexOf(logAfrColName); logRpmColIdx = columns.indexOf(logRpmColName); logLoadColIdx = columns.indexOf(logLoadColName); logTimeColIdx = columns.indexOf(logTimeColName); logMafvColIdx = columns.indexOf(logMafvColName); logIatColIdx = columns.indexOf(logIatColName); if (logClOlStatusColIdx == -1) { Config.setClOlStatusColumnName(Config.NO_NAME); ret = false;//www. j ava2s . c o m } if (logAfLearningColIdx == -1) { Config.setAfLearningColumnName(Config.NO_NAME); ret = false; } if (logAfCorrectionColIdx == -1) { Config.setAfCorrectionColumnName(Config.NO_NAME); ret = false; } if (logAfrColIdx == -1) { Config.setAfrColumnName(Config.NO_NAME); ret = false; } if (logRpmColIdx == -1) { Config.setRpmColumnName(Config.NO_NAME); ret = false; } if (logLoadColIdx == -1) { Config.setLoadColumnName(Config.NO_NAME); ret = false; } if (logTimeColIdx == -1) { Config.setTimeColumnName(Config.NO_NAME); ret = false; } if (logMafvColIdx == -1) { Config.setMafVoltageColumnName(Config.NO_NAME); ret = false; } if (logIatColIdx == -1) { Config.setIatColumnName(Config.NO_NAME); ret = false; } clValue = Config.getClOlStatusValue(); minCellHitCount = Config.getCLMinCellHitCount(); afrMin = Config.getAfrMinimumValue(); afrMax = Config.getAfrMaximumValue(); minLoad = Config.getLoadMinimumValue(); maxDvDt = Config.getDvDtMaximumValue(); maxMafV = Config.getMafVMaximumValue(); maxIat = Config.getIatMaximumValue(); return ret; }
From source file:me.lizheng.deckview.views.DeckView.java
/** * Synchronizes the views with the model *//* w ww .j a v a2 s. co m*/ boolean synchronizeStackViewsWithModel() { if (mStackViewsDirty) { // Get all the task transforms ArrayList<T> data = mCallback.getData(); float stackScroll = mStackScroller.getStackScroll(); int[] visibleRange = mTmpVisibleRange; boolean isValidVisibleRange = updateStackTransforms(mCurrentTaskTransforms, data, stackScroll, visibleRange, false); // Return all the invisible children to the pool mTmpTaskViewMap.clear(); int childCount = getChildCount(); for (int i = childCount - 1; i >= 0; i--) { @SuppressWarnings("unchecked") DeckChildView<T> tv = (DeckChildView) getChildAt(i); T key = tv.getAttachedKey(); int taskIndex = data.indexOf(key); if (visibleRange[1] <= taskIndex && taskIndex <= visibleRange[0]) { mTmpTaskViewMap.put(key, tv); } else { mViewPool.returnViewToPool(tv); } } for (int i = visibleRange[0]; isValidVisibleRange && i >= visibleRange[1]; i--) { T key = data.get(i); DeckChildViewTransform transform = mCurrentTaskTransforms.get(i); DeckChildView tv = mTmpTaskViewMap.get(key); if (tv == null) { // TODO Check tv = mViewPool.pickUpViewFromPool(key, key); if (mStackViewsAnimationDuration > 0) { // For items in the list, put them in start animating them from the // approriate ends of the list where they are expected to appear if (Float.compare(transform.p, 0f) <= 0) { mLayoutAlgorithm.getStackTransform(0f, 0f, mTmpTransform, null); } else { mLayoutAlgorithm.getStackTransform(1f, 0f, mTmpTransform, null); } tv.updateViewPropertiesToTaskTransform(mTmpTransform, 0); } } // Animate the task into place tv.updateViewPropertiesToTaskTransform(mCurrentTaskTransforms.get(i), mStackViewsAnimationDuration, mRequestUpdateClippingListener); } // Reset the request-synchronize params mStackViewsAnimationDuration = 0; mStackViewsDirty = false; mStackViewsClipDirty = true; return true; } return false; }
From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java
private T mapResults(T instance, List results, ArrayList<String> pList) throws InstantiationException, IllegalAccessException, IllegalArgumentException { pList.parallelStream().forEach(e -> { Object o = instance;//from w w w.ja v a 2s . c om for (String fieldName : e.split("\\.")) { BeanMap m = new BeanMap(o); Class type = m.getType(fieldName); if (isRedisEntity(type)) { o = m.get(fieldName); } else { Object value; Object result = results.get(pList.indexOf(e)); if (result == null) { value = null; } else if (String.class.isAssignableFrom(type)) { value = result.toString(); } else if (type.isEnum()) { try { value = type.getMethod("valueOf", String.class).invoke(null, results.get(pList.indexOf(e))); } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new IllegalArgumentException(ex); } } else if (result.getClass().isAssignableFrom(type)) { value = type.cast(result); } else { try { value = type.getConstructor(result.getClass()).newInstance(result); } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new IllegalArgumentException(ex); } } m.put(fieldName, value); } } }); return instance; }
From source file:trendanalisis.main.tools.weka.CoreWekaTFIDF.java
private double ScoreTittle(ArrayList<String> subtittles, int index) { double score = 0; if (isFitur_subtitle()) { String content = Words.get(index); if (subtittles.indexOf(content) != -1) { score = (0.5 * Math.log(1 + global_tf[index])) + (0.5 * Math.log(1 + m_DocsCounts[index])); }/*ww w . j av a 2 s. co m*/ } return score; }
From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.EditorPageHandler.java
private void previousPage(EditorState p_state, HttpSession p_session, boolean p_fromActivity, boolean isContextReview) throws EnvoyServletException { ArrayList<EditorState.PagePair> pages = p_state.getPages(); pages = (ArrayList<EditorState.PagePair>) getPagePairList(p_session, pages); if (isContextReview) { pages.removeAll(getRemovePages(pages)); }//from www .j a va2 s . com int i_index = pages.indexOf(p_state.getCurrentPage()); if (p_fromActivity) { boolean foundNonempty = false; boolean allEmptyBefore = true; while (i_index > 0) { --i_index; EditorState.PagePair pp = (EditorState.PagePair) pages.get(i_index); if (!foundNonempty) { p_state.setCurrentPage(pp); p_state.setIsFirstPage(i_index == 0); p_state.setIsLastPage(false); initState(p_state, p_session); if (p_state.getUserIsPm() && s_pmCanEditTargetPages) { if (EditorHelper.pmCanEditCurrentPage(p_state)) { p_state.setReadOnly(false); p_state.setAllowEditAll(true); p_state.setEditAllState(EDIT_ALL); } else { p_state.setReadOnly(true); } } foundNonempty = true; continue; } if (foundNonempty && allEmptyBefore) { allEmptyBefore = false; break; } } if (foundNonempty && allEmptyBefore) { p_state.setIsFirstPage(true); } } else { if (i_index > 0) { --i_index; p_state.setCurrentPage((EditorState.PagePair) pages.get(i_index)); p_state.setIsFirstPage(i_index == 0); p_state.setIsLastPage(false); initState(p_state, p_session); if (p_state.getUserIsPm() && s_pmCanEditTargetPages) { if (EditorHelper.pmCanEditCurrentPage(p_state)) { p_state.setReadOnly(false); p_state.setAllowEditAll(true); p_state.setEditAllState(EDIT_ALL); } else { p_state.setReadOnly(true); } } } } }
From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.EditorPageHandler.java
private void nextPage(EditorState p_state, HttpSession p_session, boolean p_fromActivity, boolean isContextReview) throws EnvoyServletException { ArrayList<EditorState.PagePair> pages = p_state.getPages(); pages = (ArrayList<EditorState.PagePair>) getPagePairList(p_session, pages); if (isContextReview) { pages.removeAll(getRemovePages(pages)); }// ww w .ja v a 2 s .co m int i_index = pages.indexOf(p_state.getCurrentPage()); if (p_fromActivity) { boolean foundNonempty = false; boolean allEmptyAfter = true; while (i_index >= 0 && i_index < (pages.size() - 1)) { ++i_index; EditorState.PagePair pp = (EditorState.PagePair) pages.get(i_index); if (!foundNonempty) { p_state.setCurrentPage(pp); p_state.setIsFirstPage(false); p_state.setIsLastPage(i_index == (pages.size() - 1)); initState(p_state, p_session); if (p_state.getUserIsPm() && s_pmCanEditTargetPages) { if (EditorHelper.pmCanEditCurrentPage(p_state)) { p_state.setReadOnly(false); p_state.setAllowEditAll(true); p_state.setEditAllState(EDIT_ALL); } else { p_state.setReadOnly(true); } } foundNonempty = true; continue; } if (foundNonempty && allEmptyAfter) { allEmptyAfter = false; break; } } if (foundNonempty && allEmptyAfter) { p_state.setIsLastPage(true); } } else { if (i_index >= 0 && i_index < (pages.size() - 1)) { ++i_index; p_state.setCurrentPage((EditorState.PagePair) pages.get(i_index)); p_state.setIsFirstPage(false); p_state.setIsLastPage(i_index == (pages.size() - 1)); initState(p_state, p_session); if (p_state.getUserIsPm() && s_pmCanEditTargetPages) { if (EditorHelper.pmCanEditCurrentPage(p_state)) { p_state.setReadOnly(false); p_state.setAllowEditAll(true); p_state.setEditAllState(EDIT_ALL); } else { p_state.setReadOnly(true); } } } } }
From source file:metdemo.Finance.SHNetworks.java
/** * /* w ww . j a v a2 s . co m*/ * * Method for creating the JUNG graph object using the HashMap version of * the graph * * @param fileNameNetwork * @param hmgraph * @param minEdgeWeight * @param viphm_hashmap * @return * @throws IOException */ public Graph getGraph(String fileNameNetwork, HashMap<String, HashMap> hmgraph, int minEdgeWeight, HashMap<String, vipUser> viphm_hashmap) throws IOException { // -- create the graph object ---------------------------------- Graph g = new UndirectedSparseGraph(); StringLabeller sl = StringLabeller.getLabeller(g); // -- create the connection matrix ----------------------------- // first fill acconts ArrayList Set keySet = hmgraph.keySet(); Iterator keyIter = keySet.iterator(); ArrayList<String> accounts_arraylist = new ArrayList<String>(); int i = 0; int j; while (keyIter.hasNext()) { String acct = (String) keyIter.next(); if (viphm_hashmap.containsKey(acct)) { accounts_arraylist.add(i++, acct); } } int size = i; int[][] connMatrix = new int[size][size]; // next, create the connection matrix for (i = 0; i < accounts_arraylist.size(); i++) { String acct1 = accounts_arraylist.get(i); HashMap<String, Edge> edges = hmgraph.get(acct1); Set edgeSet = edges.keySet(); Iterator edgeIter = edgeSet.iterator(); while (edgeIter.hasNext()) { String acct2 = (String) edgeIter.next(); if (accounts_arraylist.contains(acct2)) { CliqueEdge edge = (CliqueEdge) edges.get(acct2); int acctPlace = accounts_arraylist.indexOf(acct2); connMatrix[i][acctPlace] = edge.getWeight(); } } } // -- use the connection matrix to create the graph ------------ // first, create all the vertices and put them into a HashMap vertices_hashmap = new HashMap<String, VIPVertex>(); for (i = 0; i < size; i++) { /* * Vertex v1 = (Vertex) g.addVertex(new UndirectedSparseVertex()); */ VIPVertex v1 = (VIPVertex) g.addVertex(new VIPVertex(i, viphm_hashmap.get(accounts_arraylist.get(i)))); double responseScore = viphm_hashmap.get(accounts_arraylist.get(i)).getResponseScore(); double socialScore = (viphm_hashmap.get(accounts_arraylist.get(i)).getSocialScore()) / 100; transparency.setNumber(v1, responseScore); // index.setNumber(v1,i); voltages.setNumber(v1, socialScore); vertices_hashmap.put(accounts_arraylist.get(i), v1); } // next create the edges between the appropriate vertices using the // connMatrix for (i = 0; i < size; i++) { VIPVertex v1 = vertices_hashmap.get(accounts_arraylist.get(i)); for (j = i; j < size; j++) { VIPVertex v2 = vertices_hashmap.get(accounts_arraylist.get(j)); // System.out.println("Checked for Edge"); if (connMatrix[i][j] > minEdgeWeight) { // System.out.println("Added Edge"); // TODO CHECKTHE NEXT LINE IF DIR OR UNDIRECTED UndirectedEdge e = (UndirectedEdge) g.addEdge(new UndirectedSparseEdge(v1, v2)); } } } // assign the voltages (as strings) to the vertices vs = new NumberVertexValueStringer(voltages); // return the complete graph return g; }