List of usage examples for java.util List lastIndexOf
int lastIndexOf(Object o);
From source file:com.celements.navigation.Navigation.java
void addNavigationForParent(StringBuilder outStream, EntityReference parentRef, int numMoreLevels) throws XWikiException { LOGGER.debug("addNavigationForParent: parent [" + parentRef + "] numMoreLevels [" + numMoreLevels + "]."); if (numMoreLevels > 0) { getNavFilter().setMenuPart(getMenuPartForLevel(getCurrentLevel(numMoreLevels))); String parent = ""; if (parentRef != null) { parent = getWebUtilsService().getRefLocalSerializer().serialize(parentRef); }//from ww w. j a v a 2 s . com List<TreeNode> currentMenuItems = getTreeNodeService().getSubNodesForParent(parent, getMenuSpace(getContext()), getNavFilter()); if (currentMenuItems.size() > 0) { outStream.append("<ul " + addUniqueContainerId(parent) + " " + getMainUlCSSClasses() + ">"); boolean isFirstItem = true; int numItem = 0; for (TreeNode treeNode : currentMenuItems) { numItem = numItem + 1; DocumentReference nodeRef = treeNode.getDocumentReference(); boolean isLastItem = (currentMenuItems.lastIndexOf(treeNode) == (currentMenuItems.size() - 1)); writeMenuItemWithSubmenu(outStream, parent, numMoreLevels, nodeRef, isFirstItem, isLastItem, numItem); isFirstItem = false; } outStream.append("</ul>"); } else if ((getCurrentLevel(numMoreLevels) == 1) && hasedit()) { LOGGER.trace("addNavigationForParent: empty navigation hint for parent [" + parentRef + "] numMoreLevels [" + numMoreLevels + "], currentLevel [" + getCurrentLevel(numMoreLevels) + "]."); // is main Menu and no mainMenuItem found ; user has edit rights outStream.append("<ul>"); openMenuItemOut(outStream, null, true, true, false, 1); outStream.append("<span " + addUniqueElementId(null) + " " + addCssClasses(null, true, true, true, false, 1) + ">" + getWebUtilsService() .getAdminMessageTool().get(getPresentationType().getEmptyDictionaryKey()) + "</span>"); closeMenuItemOut(outStream); outStream.append("</ul>"); } else { LOGGER.debug("addNavigationForParent: empty output for parent [" + parentRef + "] numMoreLevels [" + numMoreLevels + "], currentLevel [" + getCurrentLevel(numMoreLevels) + "], hasEdit [" + hasedit() + "]."); } } }
From source file:org.kuali.kfs.module.purap.document.service.impl.PurapServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.PurapService#addBelowLineItems(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) *///w ww .j a v a2 s .com @Override @SuppressWarnings("unchecked") public void addBelowLineItems(PurchasingAccountsPayableDocument document) { LOG.debug("addBelowLineItems() started"); String[] itemTypes = getBelowTheLineForDocument(document); List<PurApItem> existingItems = document.getItems(); List<PurApItem> belowTheLine = new ArrayList<PurApItem>(); // needed in case they get out of sync below won't work sortBelowTheLine(itemTypes, existingItems, belowTheLine); List<String> existingItemTypes = new ArrayList<String>(); for (PurApItem existingItem : existingItems) { existingItemTypes.add(existingItem.getItemTypeCode()); } Class itemClass = document.getItemClass(); for (int i = 0; i < itemTypes.length; i++) { int lastFound; if (!existingItemTypes.contains(itemTypes[i])) { try { if (i > 0) { lastFound = existingItemTypes.lastIndexOf(itemTypes[i - 1]) + 1; } else { lastFound = existingItemTypes.size(); } PurApItem newItem = (PurApItem) itemClass.newInstance(); newItem.setItemTypeCode(itemTypes[i]); newItem.setPurapDocument(document); existingItems.add(lastFound, newItem); existingItemTypes.add(itemTypes[i]); } catch (Exception e) { // do something } } } document.fixItemReferences(); }
From source file:org.kuali.kfs.module.bc.businessobject.lookup.IntendedIncumbentLookupableHelperServiceImpl.java
/** * Builds URL to salary setting by Incumbent setting parameters based on the caller request. * * @param businessObject business object for result row * @return String holding the action column contents *//*from w w w. j a v a2 s.c om*/ public List<HtmlData> getSalarySettingByIncumbentUrls(BusinessObject businessObject) { List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); Properties parameters = getSalarySettingByIncumbentParameters(businessObject); String href = UrlFactory.parameterizeUrl(BCConstants.INCUMBENT_SALARY_SETTING_ACTION, parameters); AnchorHtmlData urlData1 = new AnchorHtmlData(href, BCConstants.INCUMBENT_SALARY_SETTING_METHOD, "Incmbnt Salset"); Map requestParameters = super.getParameters(); boolean linkToNewWindow = true; if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) { String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE); Boolean addNewFunding = (Boolean) (new BooleanFormatter()) .convertFromPresentationFormat(requestParm[0]); if (addNewFunding) { linkToNewWindow = false; } } if (linkToNewWindow) { urlData1.setTarget(BCConstants.SECOND_WINDOW_TARGET_NAME); } anchorHtmlDataList.add(urlData1); // now add refresh url if feed from payroll is on boolean payrollIncumbentFeed = BudgetParameterFinder.getPayrollIncumbentFeedIndictor(); if (payrollIncumbentFeed) { parameters.put(BCConstants.REFRESH_INCUMBENT_BEFORE_SALARY_SETTING, "true"); href = UrlFactory.parameterizeUrl(BCConstants.INCUMBENT_SALARY_SETTING_ACTION, parameters); AnchorHtmlData urlData2 = new AnchorHtmlData(href, BCConstants.INCUMBENT_SALARY_SETTING_METHOD, "Incmbnt Salset w/sync"); if (linkToNewWindow) { urlData2.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET); } anchorHtmlDataList.add(urlData2); anchorHtmlDataList.get(anchorHtmlDataList.lastIndexOf(urlData2)).setPrependDisplayText("<br />"); } return anchorHtmlDataList; }
From source file:org.kuali.kfs.module.bc.businessobject.lookup.PositionLookupableHelperServiceImpl.java
/** * Builds URL to salary setting by Position setting parameters based on the caller request. * * @param businessObject business object for result row * @return String holding the action column contents *//*from w w w . ja v a2 s . c om*/ public List<HtmlData> getSalarySettingByPositionUrls(BusinessObject businessObject) { List<HtmlData> anchorHtmlDataList = new ArrayList<HtmlData>(); Properties parameters = getSalarySettingByPositionParameters(businessObject); String href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters); AnchorHtmlData urlData1 = new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset"); Map requestParameters = super.getParameters(); boolean linkToNewWindow = true; if (requestParameters.containsKey(BCPropertyConstants.ADD_LINE)) { String[] requestParm = (String[]) requestParameters.get(BCPropertyConstants.ADD_LINE); Boolean addNewFunding = (Boolean) (new BooleanFormatter()) .convertFromPresentationFormat(requestParm[0]); if (addNewFunding) { linkToNewWindow = false; } } if (linkToNewWindow) { urlData1.setTarget(BCConstants.SECOND_WINDOW_TARGET_NAME); } anchorHtmlDataList.add(urlData1); // now add refresh url if feed from payroll is on boolean payrollPositionFeed = BudgetParameterFinder.getPayrollPositionFeedIndicator(); String url2 = ""; if (payrollPositionFeed) { parameters.put(BCConstants.REFRESH_POSITION_BEFORE_SALARY_SETTING, "true"); href = UrlFactory.parameterizeUrl(BCConstants.POSITION_SALARY_SETTING_ACTION, parameters); AnchorHtmlData urlData2 = new AnchorHtmlData(href, BCConstants.POSITION_SALARY_SETTING_METHOD, "Posn Salset w/sync"); if (linkToNewWindow) { urlData2.setTarget(KFSConstants.NEW_WINDOW_URL_TARGET); } anchorHtmlDataList.add(urlData2); anchorHtmlDataList.get(anchorHtmlDataList.lastIndexOf(urlData2)).setPrependDisplayText("<br />"); } return anchorHtmlDataList; }
From source file:com.taobao.weex.ui.animation.TransformParser.java
public static Map<Property<View, Float>, Float> parseTransForm(@Nullable String rawTransform, final int width, final int height, final int viewportW) { if (!TextUtils.isEmpty(rawTransform)) { FunctionParser<Property<View, Float>, Float> parser = new FunctionParser<>(rawTransform, new FunctionParser.Mapper<Property<View, Float>, Float>() { @Override//from w w w . ja v a2 s . c o m public Map<Property<View, Float>, Float> map(String functionName, List<String> raw) { if (raw != null && !raw.isEmpty()) { if (wxToAndroidMap.containsKey(functionName)) { return convertParam(width, height, viewportW, wxToAndroidMap.get(functionName), raw); } } return new HashMap<>(); } private Map<Property<View, Float>, Float> convertParam(int width, int height, int viewportW, @NonNull List<Property<View, Float>> propertyList, @NonNull List<String> rawValue) { Map<Property<View, Float>, Float> result = WXDataStructureUtil .newHashMapWithExpectedSize(propertyList.size()); List<Float> convertedList = new ArrayList<>(propertyList.size()); if (propertyList.contains(View.ROTATION) || propertyList.contains(View.ROTATION_X) || propertyList.contains(View.ROTATION_Y)) { convertedList.addAll(parseRotationZ(rawValue)); } else if (propertyList.contains(View.TRANSLATION_X) || propertyList.contains(View.TRANSLATION_Y)) { convertedList .addAll(parseTranslation(propertyList, width, height, rawValue, viewportW)); } else if (propertyList.contains(View.SCALE_X) || propertyList.contains(View.SCALE_Y)) { convertedList.addAll(parseScale(propertyList.size(), rawValue)); } else if (propertyList.contains(CameraDistanceProperty.getInstance())) { convertedList.add(parseCameraDistance(rawValue)); } if (propertyList.size() == convertedList.size()) { for (int i = 0; i < propertyList.size(); i++) { result.put(propertyList.get(i), convertedList.get(i)); } } return result; } private List<Float> parseScale(int size, @NonNull List<String> rawValue) { List<Float> convertedList = new ArrayList<>(rawValue.size() * 2); List<Float> rawFloat = new ArrayList<>(rawValue.size()); for (String item : rawValue) { rawFloat.add(WXUtils.fastGetFloat(item)); } convertedList.addAll(rawFloat); if (size != 1 && rawValue.size() == 1) { convertedList.addAll(rawFloat); } return convertedList; } private @NonNull List<Float> parseRotationZ(@NonNull List<String> rawValue) { List<Float> convertedList = new ArrayList<>(1); int suffix; for (String raw : rawValue) { if ((suffix = raw.lastIndexOf(DEG)) != -1) { convertedList.add(WXUtils.fastGetFloat(raw.substring(0, suffix))); } else { convertedList.add((float) Math.toDegrees(Double.parseDouble(raw))); } } return convertedList; } /** * As "translate(50%, 25%)" or "translate(25px, 30px)" both are valid, * parsing translate is complicated than other method. * Add your waste time here if you try to optimize this method like {@link #parseScale(int, List)} * Time: 0.5h */ private List<Float> parseTranslation(List<Property<View, Float>> propertyList, int width, int height, @NonNull List<String> rawValue, int viewportW) { List<Float> convertedList = new ArrayList<>(2); String first = rawValue.get(0); if (propertyList.size() == 1) { parseSingleTranslation(propertyList, width, height, convertedList, first, viewportW); } else { parseDoubleTranslation(width, height, rawValue, convertedList, first, viewportW); } return convertedList; } private void parseSingleTranslation(List<Property<View, Float>> propertyList, int width, int height, List<Float> convertedList, String first, int viewportW) { if (propertyList.contains(View.TRANSLATION_X)) { convertedList.add(parsePercentOrPx(first, width, viewportW)); } else if (propertyList.contains(View.TRANSLATION_Y)) { convertedList.add(parsePercentOrPx(first, height, viewportW)); } } private void parseDoubleTranslation(int width, int height, @NonNull List<String> rawValue, List<Float> convertedList, String first, int viewportW) { String second; if (rawValue.size() == 1) { second = first; } else { second = rawValue.get(1); } convertedList.add(parsePercentOrPx(first, width, viewportW)); convertedList.add(parsePercentOrPx(second, height, viewportW)); } private Float parseCameraDistance(List<String> rawValue) { float ret = Float.MAX_VALUE; if (rawValue.size() == 1) { float value = WXViewUtils.getRealPxByWidth(WXUtils.getFloat(rawValue.get(0)), viewportW); float scale = WXEnvironment.getApplication().getResources() .getDisplayMetrics().density; if (!Float.isNaN(value) && value > 0) { ret = value * scale; } } return ret; } }); return parser.parse(); } return new LinkedHashMap<>(); }
From source file:org.rhq.bindings.output.TabularWriter.java
private boolean consistentMaps(Collection list) { List<String> keys = null; String[][] data = new String[list.size()][]; int i = 0;/*w ww .j a va 2s . c o m*/ for (Object row : list) { if (!(row instanceof Map) && !(row instanceof PropertyMap)) { return false; } if (keys == null) { keys = new ArrayList<String>(); //insert check for PropertyMap as they are not instances of Map if (row instanceof PropertyMap) { //TODO: spinder 1/15/10. PropertyMap is arbitrarily complex. Only serialize simple props? for (Object key : ((PropertyMap) row).getMap().keySet()) { String headerKey = stringValueOf(key); keys.add(headerKey); } } else {//else row is a Map for (Object key : ((Map) row).keySet()) { String headerKey = stringValueOf(key); keys.add(headerKey); } } //conditionally put order on the headers to mimic core gui listing style/order //Ex. Pid Name Size User Time Kernel Time if (keys.contains("pid")) { String[] processAttribute = { "pid", "name", "size", "userTime", "kernelTime" }; List<String> newKeyOrder = new ArrayList<String>(); for (String attribute : processAttribute) { newKeyOrder.add(attribute); keys.remove(attribute); } //postpend remaining keys if any to the newHeader list for (String key : keys) { newKeyOrder.add(key); } keys = newKeyOrder; } } data[i] = new String[keys.size()]; if (row instanceof PropertyMap) { for (String key : keys) { if (!keys.contains(stringValueOf(key))) { return false; } data[i][keys.lastIndexOf(stringValueOf(key))] = shortVersion( ((PropertyMap) row).get(String.valueOf(key))); } } else {//else row is a Map for (Object key : ((Map) row).keySet()) { if (!keys.contains(stringValueOf(key))) { return false; } data[i][keys.lastIndexOf(stringValueOf(key))] = shortVersion(((Map) row).get(key)); } } i++; } if (keys != null) { headers = keys.toArray(new String[keys.size()]); print(data); return true; } else { return false; } }
From source file:com.eyeq.pivot4j.ui.impl.RenderStrategyImpl.java
/** * @param context/* w w w. j a v a2 s .c o m*/ * @param node * @param aggregator * @param position */ protected void aggregate(RenderContext context, TableHeaderNode node, Aggregator aggregator, AggregatorPosition position) { Measure measure = aggregator.getMeasure(); List<Member> members = aggregator.getMembers(); if (context.getCell() == null && (measure == null || context.getAggregator() == null)) { return; } if (context.getAggregator() != null && (context.getAggregator().getAxis() == aggregator.getAxis())) { return; } List<Member> positionMembers = aggregator.getPosition(context).getMembers(); int index = 0; for (Member member : members) { if (positionMembers.size() <= index) { return; } Member positionMember = positionMembers.get(index); if (positionMember.getDepth() > 1 && context.getParentMember(positionMember) == null) { positionMember = new RaggedMemberWrapper(positionMember, context.getModel().getCube()); } if (!OlapUtils.equals(member, positionMember) && (member.getDepth() >= positionMember.getDepth() || !context.getAncestorMembers(positionMember).contains(member))) { return; } index++; } if (measure != null && !positionMembers.isEmpty()) { Member member = positionMembers.get(positionMembers.size() - 1); if (!measure.equals(member)) { return; } } TableHeaderNode parent = node; while (parent != null) { if (parent.getHierarchyDescendents() == 1 && parent.getMemberChildren() > 0) { switch (position) { case Grand: return; case Hierarchy: if (!members.contains(parent.getMember())) { return; } break; case Member: if (node == parent || members.lastIndexOf(parent.getMember()) == members.size() - 1) { return; } break; default: assert false; } } parent = (TableHeaderNode) parent.getParent(); } aggregator.aggregate(context); }
From source file:org.pivot4j.ui.table.TableRenderer.java
/** * @param context//from w w w . ja v a 2s . c om * @param node * @param aggregator * @param position */ protected void aggregate(TableRenderContext context, TableHeaderNode node, Aggregator aggregator, AggregatorPosition position) { Measure measure = aggregator.getMeasure(); List<Member> members = aggregator.getMembers(); if (context.getCell() == null && (measure == null || context.getAggregator() == null)) { return; } if (context.getAggregator() != null && (context.getAggregator().getAxis() == aggregator.getAxis())) { return; } MemberHierarchyCache cache = node.getReference().getMemberHierarchyCache(); List<Member> positionMembers = context.getPosition().getMembers(); OlapUtils utils = new OlapUtils(context.getModel().getCube()); utils.setMemberHierarchyCache(cache); int index = 0; for (Member member : members) { if (positionMembers.size() <= index) { return; } Member positionMember = utils.wrapRaggedIfNecessary(positionMembers.get(index)); if (!OlapUtils.equals(member, positionMember) && (member.getDepth() >= positionMember.getDepth() || !cache.getAncestorMembers(positionMember).contains(member))) { return; } index++; } if (measure != null && !positionMembers.isEmpty()) { Member member = positionMembers.get(positionMembers.size() - 1); if (!measure.equals(member)) { return; } } TableHeaderNode parent = node; while (parent != null) { if (parent.getHierarchyDescendents() == 1 && parent.getMemberChildren() > 0) { switch (position) { case Grand: return; case Hierarchy: if (!members.contains(parent.getMember())) { return; } break; case Member: if (node == parent || members.lastIndexOf(parent.getMember()) == members.size() - 1) { return; } break; default: assert false; } } parent = (TableHeaderNode) parent.getParent(); } aggregator.aggregate(context); }
From source file:com.huateng.startup.init.MenuInfoUtil.java
/** * ???/* w ww .j a va2 s. c om*/ * @param degree */ @SuppressWarnings("unchecked") public static LinkedHashMap<String, Object> setOperatorMenuWithDegree(String degree, String contextPath, Document document) { String sql = "select * FROM TBL_ROLE_FUNC_MAP WHERE KEY_ID in ( " + degree + ")"; ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO"); List<Object[]> funcMapList = commQueryDAO.findBySQLQuery(sql); valueIdRole(funcMapList); List<Object> menuLvl1List = allMenuBean.getDataList(); LinkedHashMap<String, Object> menuIndexMap = new LinkedHashMap<String, Object>(); String panelStr = ""; //????? for (int i = 0, n = menuLvl1List.size(); i < n; i++) { Map<String, Object> menuLvl1Map = (Map<String, Object>) menuLvl1List.get(i); LinkedList<Object> menuLvl2List = (LinkedList<Object>) menuLvl1Map.get(Constants.MENU_CHILDREN); List<String> menuList = new ArrayList<String>(); for (int j = 0, m = menuLvl2List.size(); j < m; j++) { Map<String, Object> menuLvl2Map = (Map<String, Object>) menuLvl2List.get(j); LinkedList<Object> menuLvl3List = (LinkedList<Object>) menuLvl2Map.get(Constants.MENU_CHILDREN); for (int k = 0, l = menuLvl3List.size(); k < l; k++) { Map<String, Object> menuLvl3Map = (Map<String, Object>) menuLvl3List.get(k); for (int a = 0, b = funcMapList.size(); a < b; a++) { if (StringUtils.trim(funcMapList.get(a)[1].toString()) .equals(StringUtils.trim(menuLvl3Map.get(Constants.MENU_ID).toString()))) { if (!menuIndexMap.containsKey(menuLvl1Map.get(Constants.MENU_ID).toString())) { Map<String, Object> menuLvl1HashMap = new LinkedHashMap<String, Object>(); String menuId = menuLvl1Map.get(Constants.MENU_ID).toString(); menuLvl1HashMap.put(Constants.MENU_ID, menuLvl1Map.get(Constants.MENU_ID)); menuLvl1HashMap.put(Constants.MENU_TEXT, menuLvl1Map.get(Constants.MENU_TEXT)); menuLvl1HashMap.put(Constants.MENU_CLS, menuLvl1Map.get(Constants.MENU_CLS)); menuLvl1HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL1_FUNC); menuLvl1HashMap.put(Constants.TOOL_BAR_TYPE, Constants.TOOL_BAR_BUTTON); menuLvl1HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENU); menuLvl1HashMap.put(Constants.IS_EXPAND, true); if ("1".equals(menuId) && panelStr.indexOf("baseTree") == -1) { panelStr = panelStr + "baseTree,"; } if ("2".equals(menuId) && panelStr.indexOf("mchtTree") == -1) { panelStr = panelStr + "mchtTree,"; } if ("3".equals(menuId) && panelStr.indexOf("termTree") == -1) { panelStr = panelStr + "termTree,"; } if ("5".equals(menuId) && panelStr.indexOf("queryTree") == -1) { panelStr = panelStr + "queryTree,"; } if ("9".equals(menuId) && panelStr.indexOf("onLinePayTree") == -1) { panelStr = panelStr + "onLinePayTree,"; } if ("10".equals(menuId) && panelStr.indexOf("taskTree") == -1) { panelStr = panelStr + "taskTree,"; } if ("8".equals(menuId) && panelStr.indexOf("clearTree") == -1) { panelStr = panelStr + "clearTree,"; } if ("4".equals(menuId) && panelStr.indexOf("riskTree") == -1) { panelStr = panelStr + "riskTree,"; } if ("11".equals(menuId) && panelStr.indexOf("provisionsTree") == -1) { panelStr = panelStr + "provisionsTree,"; } if ("12".equals(menuId) && panelStr.indexOf("errorTree") == -1) { panelStr = panelStr + "errorTree,"; } Map<String, Object> menuLvl2HashMap = new LinkedHashMap<String, Object>(); menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID)); menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT)); menuLvl2HashMap.put(Constants.MENU_PARENT_ID, menuLvl2Map.get(Constants.MENU_PARENT_ID)); menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS)); menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl2HashMap.put(Constants.IS_EXPAND, true); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); int index = menuList.lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID)); LinkedList<Object> menuLvl3Child = new LinkedList<Object>(); //System.out.println((String)menuLvl3Map.get(Constants.MENU_ID) + ">>>>>>>>>" + index + ">>>>>" + menuList.size()); if (-1 == index) { String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID), (String) funcMapList.get(a)[5]); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); menuLvl3HashMap.put(Constants.IS_EXPAND, true); menuList.add((String) menuLvl3Map.get(Constants.MENU_ID)); menuLvl3Child.add(menuLvl3HashMap); } else { Map<String, Object> menu = (Map<String, Object>) menuLvl3Child.get(index); menu.put(Constants.ROLE_FLAG, (String) menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]); } menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); LinkedList<Object> menuLvl2Child = new LinkedList<Object>(); menuLvl2Child.add(menuLvl2HashMap); menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child); menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child); menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap); } else { Map<String, Object> menuLvl1HashMap = (Map<String, Object>) menuIndexMap .get(menuLvl1Map.get(Constants.MENU_ID).toString()); LinkedList<Object> menuLvl2Child = (LinkedList<Object>) menuLvl1HashMap .get(Constants.MENU_CHILDREN); boolean hasMenu = false; for (int c = 0, d = menuLvl2Child.size(); c < d; c++) { Map<String, Object> menuLvl2HashMap = (Map<String, Object>) menuLvl2Child .get(c); if (StringUtils.trim(menuLvl2HashMap.get(Constants.MENU_ID).toString()).equals( StringUtils.trim(menuLvl2Map.get(Constants.MENU_ID).toString()))) { LinkedList<Object> menuLvl3Child = (LinkedList<Object>) menuLvl2HashMap .get(Constants.MENU_CHILDREN); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); int index = menuList .lastIndexOf((String) menuLvl3Map.get(Constants.MENU_ID)); if (-1 == index) { String tbar = MenuUtil.initMenu( (String) menuLvl3Map.get(Constants.MENU_ID), (String) funcMapList.get(a)[5]); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); menuLvl3HashMap.put(Constants.IS_EXPAND, true); menuList.add((String) menuLvl3Map.get(Constants.MENU_ID)); menuLvl3Child.add(menuLvl3HashMap); } // else{ // Map<String, Object> menu = (Map<String, Object>)menuLvl3Child.get(index); // menu.put(Constants.ROLE_FLAG,(String)menu.get(Constants.ROLE_FLAG) + funcMapList.get(a)[5]); // } menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.IS_EXPAND, true); menuLvl2Child.set(c, menuLvl2HashMap); hasMenu = true; break; } } if (!hasMenu) { String tbar = MenuUtil.initMenu((String) menuLvl3Map.get(Constants.MENU_ID), (String) funcMapList.get(a)[5]); Map<String, Object> menuLvl2HashMap = new HashMap<String, Object>(); menuLvl2HashMap.put(Constants.MENU_ID, menuLvl2Map.get(Constants.MENU_ID)); menuLvl2HashMap.put(Constants.MENU_TEXT, menuLvl2Map.get(Constants.MENU_TEXT)); menuLvl2HashMap.put(Constants.MENU_PARENT_ID, menuLvl2Map.get(Constants.MENU_PARENT_ID)); menuLvl2HashMap.put(Constants.MENU_CLS, menuLvl2Map.get(Constants.MENU_CLS)); menuLvl2HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl2HashMap.put(Constants.IS_EXPAND, true); LinkedList<Object> menuLvl3Child = new LinkedList<Object>(); Map<String, Object> menuLvl3HashMap = new LinkedHashMap<String, Object>(); menuLvl3HashMap.put(Constants.MENU_ID, menuLvl3Map.get(Constants.MENU_ID)); menuLvl3HashMap.put(Constants.MENU_TEXT, menuLvl3Map.get(Constants.MENU_TEXT)); menuLvl3HashMap.put(Constants.MENU_PARENT_ID, menuLvl3Map.get(Constants.MENU_PARENT_ID)); menuLvl3HashMap.put(Constants.MENU_LEAF, true); menuLvl3HashMap.put(Constants.MENU_URL, menuLvl3Map.get(Constants.MENU_URL)); menuLvl3HashMap.put(Constants.MENU_CLS, menuLvl3Map.get(Constants.MENU_CLS)); menuLvl3HashMap.put(Constants.ROLE_FLAG, tbar); menuLvl3HashMap.put(Constants.MENU_HANDLER, Constants.MENU_LVL3_FUNC); //menuLvl3HashMap.put(Constants.TOOLBAR_ICON, Constants.TOOLBAR_ICON_MENUITEM); menuLvl3HashMap.put(Constants.TOOLBAR_ICON, menuLvl3Map.get(Constants.TOOLBAR_ICON)); menuLvl3HashMap.put(Constants.IS_EXPAND, true); menuLvl3Child.add(menuLvl3HashMap); menuLvl2HashMap.put(Constants.MENU_CHILDREN, menuLvl3Child); menuLvl2HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl3Child); menuLvl2Child.add(menuLvl2HashMap); } menuLvl1HashMap.put(Constants.MENU_CHILDREN, menuLvl2Child); menuLvl1HashMap.put(Constants.TOOL_BAR_CHILDREN, menuLvl2Child); menuLvl1HashMap.put(Constants.IS_EXPAND, true); menuIndexMap.put(menuLvl1Map.get(Constants.MENU_ID).toString(), menuLvl1HashMap); } } } } } } menuIndexMap.remove(Constants.TREE_MENU_PANEL); if (panelStr.length() != 0) { menuIndexMap.put(Constants.TREE_MENU_PANEL, panelStr.substring(0, panelStr.length() - 1)); } else { menuIndexMap.put(Constants.TREE_MENU_PANEL, ""); } return menuIndexMap; }
From source file:ro.uaic.info.nlptools.ggs.engine.core.StateMachine.java
private List<State> findInfiniteLoop(State currentState, List<State> currentPath, Stack<GraphNode> callStack, Stack<Integer> pathJumpsBeginIndexes, Map<State, State> jumpProxies) {//functie recursiva pentru gasit bucle infinite if (currentState.index == terminalStateIndex) return null; if (verifiedStates.contains(currentState)) { //this state has been passed before successfully return null; }/*from w w w.ja v a2 s. c o m*/ List<State> newPath = new ArrayList<State>(currentPath); State currentProxy = null; //handle correct jump transitions if (currentState.isGraphNodeEntry) { callStack.push(currentState.parentGraphNode); if (currentState.parentGraphNode == currentState.parentGraphNode.getParentGraph().getStartNode()) pathJumpsBeginIndexes.push(newPath.size()); } else if (currentState.isGraphNodeExit) { if (currentState.parentGraphNode != callStack.peek()) { return null; // this is not a valit transition according to jumps stack } callStack.pop(); if (currentState.parentGraphNode == currentState.parentGraphNode.getParentGraph().getEndNode()) {//if exit from a jump, the nodes inside the jump must be treated as one empty or non empty node, to avoid false detection when recursivity is used int pathJumpStart = pathJumpsBeginIndexes.pop(); boolean consumed = false; for (int i = pathJumpStart; i < currentPath.size(); i++) { if (!newPath.get(newPath.size() - 1).condition.isEmpty) consumed = true; newPath.remove(newPath.size() - 1); } if (consumed) { currentProxy = jumpProxies.get(newPath.get(newPath.size() - 1)); if (currentProxy == null) { GraphNode gn = new GraphNode(grammar); // this is a proxy node for the entire sub network - since we know there is no loop inside it, we can treat it as a normal node for the search if (!currentPath.isEmpty()) gn.setTokenMatchingCode( "jump to " + currentPath.get(currentPath.size() - 1).parentGraphNode .getParentGraph().getId()); currentProxy = new State(this, gn); currentProxy.condition.isEmpty = false; jumpProxies.put(newPath.get(newPath.size() - 1), currentProxy); } newPath.add(currentProxy); } } } //avoid exploring non empty loops - such loops are ok if ((currentProxy == null || !currentPath.contains(currentProxy)) && (currentState.condition.isEmpty || !currentPath.contains(currentState))) { if (currentState.parentGraphNode != currentState.parentGraphNode.getParentGraph().getEndNode()) //if exited from a jump do not retain this node in the loop, to avoid false detection when recursivity is used newPath.add(currentState); if (currentState.condition.isEmpty) {// search for this empty state in the tail of the current traveled path from root boolean found = false; for (int i = currentPath.size() - 1; i >= 0; i--) { if (!currentPath.get(i).condition.isEmpty) { break; } if (currentPath.get(i) == currentState) { found = true; break; } } if (found) { return newPath; } } for (int childStateIndex : currentState.childStatesIndexes) { List<State> foundPath = findInfiniteLoop(states.get(childStateIndex), newPath, callStack, pathJumpsBeginIndexes, jumpProxies); if (foundPath != null) return foundPath; } //this node doesn't lead to an infinite loop if (currentState.isGraphNodeEntry) { verifiedStates.add(currentState); } } if (currentState.isGraphNodeEntry && currentState.parentGraphNode == currentState.parentGraphNode.getParentGraph().getStartNode()) pathJumpsBeginIndexes.pop(); else if (currentState.isGraphNodeExit && currentState.parentGraphNode == currentState.parentGraphNode.getParentGraph().getEndNode()) //if exited from a jump, the nodes inside the jump must be ignored, to avoit false detection when recursivity is used pathJumpsBeginIndexes.push(currentPath .lastIndexOf(states.get(compNodes.get(currentPath.get(currentPath.size() - 1).parentGraphNode .getParentGraph().getStartNode()).startStateIndex))); return null; }