List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:edu.cmu.tetrad.search.TestIndTestConditionalCorrelation.java
public void test14c10c() { String graphDir = "/Users/josephramsey/Documents/LAB_NOTEBOOK.2012.04.20/2013.11.23/test14/"; String tag = "images1"; double penalty = 1.0; List<Edge> previousIntersection = new ArrayList<Edge>(); List<Edge> intersection2Back = new ArrayList<Edge>(); Set<Edge> unionIntersection = new HashSet<Edge>(); List<Edge> intersectionIntersection = new ArrayList<Edge>(); for (int i = 0; i < 67; i++) { File file1 = new File(graphDir, "graph." + tag + "." + penalty + "." + (i + 1) + ".txt"); final Graph graph1 = GraphUtils.loadGraphTxt(file1); // File file2 = new File(graphDir, "graph.concurrent.67." + penalty + ".clip" + 0.0 + ".txt"); File file2 = new File(graphDir, "images.67.1.0.clip0.5.txt"); // File file2 = new File(graphDir, "graph." + tag + "." + penalty + "." + (i + 2) + ".txt"); final Graph graph2 = GraphUtils.loadGraphTxt(file2); // List<Edge> edges1 = graph1.getEdges(); // List<Edge> edges2 = graph2.getEdges(); List<Edge> edges1 = new ArrayList<Edge>(); for (Edge edge : graph1.getEdges()) { edges1.add(Edges.undirectedEdge(edge.getNode1(), edge.getNode2())); }//from w ww. j av a 2 s .c om List<Edge> edges2 = new ArrayList<Edge>(); for (Edge edge : graph2.getEdges()) { edges2.add(Edges.undirectedEdge(edge.getNode1(), edge.getNode2())); } List<Edge> newEdges = new ArrayList<Edge>(edges2); newEdges.removeAll(edges1); List<Edge> oldEdges = new ArrayList<Edge>(edges1); oldEdges.removeAll(edges2); List<Edge> intersection = new ArrayList<Edge>(edges1); intersection.retainAll(edges2); unionIntersection.addAll(intersection); if (intersectionIntersection.isEmpty()) { intersectionIntersection.addAll(intersection); } else { intersectionIntersection.retainAll(intersection); } int delta = intersection.size() - previousIntersection.size(); List<Edge> gained = new ArrayList<Edge>(intersection); gained.removeAll(previousIntersection); List<Edge> lost = new ArrayList<Edge>(previousIntersection); lost.removeAll(intersection); System.out .println("Graph " + (i + 2) + " # new in images 67 = " + newEdges.size() + " # intersection = " + intersection.size() + " Gained = " + gained.size() + " Lost = " + lost.size() /* + " " + (intersection.size() - intersection2Back.size())*/ + " Interesection intersection # = " + intersectionIntersection.size()); // intersection2Back = new ArrayList<Edge>(previousIntersection); previousIntersection = new ArrayList<Edge>(intersection); } System.out.println("Union intersection # = " + unionIntersection.size()); System.out.println("Intersection intersection # = " + intersectionIntersection.size()); for (Edge edge : unionIntersection) { int count = 0; for (int i = 0; i < 67; i++) { File file1 = new File(graphDir, "graph." + tag + "." + penalty + "." + (i + 1) + ".txt"); Graph graph1 = GraphUtils.loadGraphTxt(file1); Node node1 = edge.getNode1(); Node node2 = edge.getNode2(); node1 = graph1.getNode(node1.getName()); node2 = graph1.getNode(node2.getName()); if (graph1.isAdjacentTo(node1, node2)) { count++; } } System.out.println("Edge " + edge + " count = " + count); } }
From source file:org.jenkins.plugins.lockableresources.LockableResourcesManager.java
public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLock, @Nullable Run<?, ?> build, String requiredVar, boolean inversePrecedence) { // make sure there is a list of resource names to unlock if (resourceNamesToUnLock == null || (resourceNamesToUnLock.size() == 0)) { return;//w ww . java 2 s. com } // process as many contexts as possible List<String> remainingResourceNamesToUnLock = new ArrayList<>(resourceNamesToUnLock); QueuedContextStruct nextContext = null; while (!remainingResourceNamesToUnLock.isEmpty()) { // check if there are resources which can be unlocked (and shall not be unlocked) Set<LockableResource> requiredResourceForNextContext = null; nextContext = this.getNextQueuedContext(remainingResourceNamesToUnLock, inversePrecedence, nextContext); // no context is queued which can be started once these resources are free'd. if (nextContext == null) { this.freeResources(remainingResourceNamesToUnLock, build); save(); return; } requiredResourceForNextContext = checkResourcesAvailability(nextContext.getResources(), null, remainingResourceNamesToUnLock); // resourceNamesToUnlock contains the names of the previous resources. // requiredResourceForNextContext contains the resource objects which are required for the next context. // It is guaranteed that there is an overlap between the two - the resources which are to be reused. boolean needToWait = false; for (LockableResource requiredResource : requiredResourceForNextContext) { if (!remainingResourceNamesToUnLock.contains(requiredResource.getName())) { if (requiredResource.isReserved() || requiredResource.isLocked()) { needToWait = true; break; } } } if (!needToWait) { // remove context from queue and process it unqueueContext(nextContext.getContext()); List<String> resourceNamesToLock = new ArrayList<String>(); // lock all (old and new resources) for (LockableResource requiredResource : requiredResourceForNextContext) { try { requiredResource.setBuild(nextContext.getContext().get(Run.class)); resourceNamesToLock.add(requiredResource.getName()); } catch (Exception e) { // skip this context, as the build cannot be retrieved (maybe it was deleted while running?) LOGGER.log(Level.WARNING, "Skipping queued context for lock. Can not get the Run object from the context to proceed with lock, " + "this could be a legitimate status if the build waiting for the lock was deleted or" + " hard killed. More information at Level.FINE if debug is needed."); LOGGER.log(Level.FINE, "Can not get the Run object from the context to proceed with lock", e); unlockNames(remainingResourceNamesToUnLock, build, requiredVar, inversePrecedence); return; } } // determine old resources no longer needed List<String> freeResources = new ArrayList<String>(); for (String resourceNameToUnlock : remainingResourceNamesToUnLock) { boolean resourceStillNeeded = false; for (LockableResource requiredResource : requiredResourceForNextContext) { if (resourceNameToUnlock != null && resourceNameToUnlock.equals(requiredResource.getName())) { resourceStillNeeded = true; break; } } if (!resourceStillNeeded) { freeResources.add(resourceNameToUnlock); } } // keep unused resources remainingResourceNamesToUnLock.retainAll(freeResources); // continue with next context LockStepExecution.proceed(resourceNamesToLock, nextContext.getContext(), nextContext.getResourceDescription(), requiredVar, inversePrecedence); } } save(); }
From source file:edu.cmu.tetrad.search.TestIndTestConditionalCorrelation.java
public void test14b() { try {//ww w. j ava2 s . com String graphDir = "/Users/josephramsey/Documents/LAB_NOTEBOOK.2012.04.20/2013.11.23/test14/"; // String graphDir = "/home/jdramsey/test14/"; File _graphDir = new File(graphDir); if (!_graphDir.exists()) _graphDir.mkdir(); String _dir = "/Users/josephramsey/Documents/LAB_NOTEBOOK.2012.04.20/2013.11.23/roidata/"; // String _dir = "/home/jdramsey/roidata/"; File dir = new File(_dir); File[] files = dir.listFiles(); int numDataSets = 67; List<Graph> graphs = new ArrayList<Graph>(); for (int k = 1; k <= 60; k++) { List<DataSet> _dataSets = new ArrayList<DataSet>(); double penaltyDiscount = 2.0; File file = new File(graphDir, "test" + penaltyDiscount + ".c.graph.images." + k + ".txt"); System.out.println(file.getAbsolutePath()); Graph graph = GraphUtils.loadGraphTxt(file); graphs.add(graph); } List<Node> nodes = graphs.get(0).getNodes(); List<Graph> graphs2 = new ArrayList<Graph>(); int c = -1; for (Graph graph : graphs) { if (++c >= 0) { Graph e = GraphUtils.replaceNodes(graph, nodes); e = GraphUtils.undirectedGraph(e); graphs2.add(e); } } graphs = graphs2; Map<Edge, Integer> edges = new HashMap<Edge, Integer>(); // Map<Edge, Integer> edgesReversed = new HashMap<Edge, Integer>(); int count = 0; for (Graph graph : graphs2) { // graph = GraphUtils.replaceNodes(graph, graphs.get(0).getNodes()); System.out.println("# Edges in graph #" + (++count) + " = " + graph.getNumEdges()); for (Edge edge : graph.getEdges()) { // edge = Edges.undirectedEdge(edge.getNode1(), edge.getNode2()); increment(edges, edge); } } // System.out.println("# Edges in the union of all graphs = " + edges.size()); // // int[] counts = new int[dataSets.size() + 1]; // Map<Integer, List<Edge>> edgesAtCount = new HashMap<Integer, List<Edge>>(); // // for (int i = 1; i <= dataSets.size(); i++) { // edgesAtCount.put(i, new ArrayList<Edge>()); // } // // for (Edge edge : edges.keySet()) { // int _count = edges.get(edge); // counts[_count]++; // edgesAtCount.get(_count).add(edge); // } // // for (int i = 1; i <= dataSets.size(); i++) { // System.out.println(i + " " + counts[i]); // } // Graph topEdges = new EdgeListGraph(graphs.get(0).getNodes()); // // for (int i = 1; i <= 46; i++) { // List<Edge> _edges = edgesAtCount.get(i); // for (Edge edge : _edges) { // topEdges.addEdge(edge); // } // } Graph topEdges = new EdgeListGraph(graphs.get(0).getNodes()); for (Edge edge : edges.keySet()) { int _count = 0; for (int i = graphs2.size() - 1; i >= 0; i--) { // for (int i = 0; i < graphs2.size(); i++) { Graph graph = graphs2.get(i); if (graph.containsEdge(edge)) { _count++; if (_count == 10) { topEdges.addEdge(edge); } } else { break; } } if (_count > 0) { System.out.println("Edge " + edge + " count = " + _count); } } for (Node node : topEdges.getNodes()) { if (topEdges.getAdjacentNodes(node).isEmpty()) { topEdges.removeNode(node); } } for (int i = 1; i < graphs2.size(); i++) { Graph lastGraph = graphs2.get(i - 1); Graph thisGraph = graphs2.get(i); List<Edge> lastEdges = lastGraph.getEdges(); List<Edge> thisEdges = thisGraph.getEdges(); List<Edge> gained = new ArrayList<Edge>(thisEdges); gained.removeAll(lastEdges); List<Edge> lost = new ArrayList<Edge>(lastEdges); lost.removeAll(thisEdges); List<Edge> retained = new ArrayList<Edge>(thisEdges); retained.retainAll(lastEdges); // System.out.println("Graph #" + i); // System.out.println("GAINED:"); // // for (int j = 0; j < gained.size(); j++) { // System.out.println(j + ". " + gained.get(j)); // } // // System.out.println("LOST:"); // // for (int j = 0; j < lost.size(); j++) { // System.out.println(j + ". " + lost.get(j)); // } // // System.out.println("RETAINED:"); // // for (int j = 0; j < retained.size(); j++) { // System.out.println(j + ". " + retained.get(j)); // } // // System.out.println(); System.out.println(i + " -> " + (i + 1) + ": " + retained.size() + " out of " + thisEdges.size()); } writeGraph(new File(graphDir, "graph.top.edges.txt"), topEdges); // } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jahia.ajax.gwt.content.server.JahiaContentManagementServiceImpl.java
@Override public GWTJahiaEditEngineInitBean initializeEditEngine(List<String> paths, boolean tryToLockNode) throws GWTJahiaServiceException { try {//from ww w . j a v a2 s . c om JCRSessionWrapper sessionWrapper = retrieveCurrentSession(); List<GWTJahiaNodeType> nodeTypes = null; List<GWTJahiaNodeType> gwtMixin = null; List<ExtendedNodeType> allTypes = new ArrayList<ExtendedNodeType>(); JCRNodeWrapper nodeWrapper = null; for (String path : paths) { nodeWrapper = sessionWrapper.getNode(path); addEngineLock(tryToLockNode && !JCRContentUtils.isLockedAndCannotBeEdited(nodeWrapper), nodeWrapper); // get node type if (nodeTypes == null) { final List<GWTJahiaNodeType> theseTypes = contentDefinition .getNodeTypes(nodeWrapper.getNodeTypes(), getUILocale()); nodeTypes = theseTypes; } else { List<GWTJahiaNodeType> previousTypes = new ArrayList<GWTJahiaNodeType>(nodeTypes); nodeTypes.clear(); for (GWTJahiaNodeType p : previousTypes) { if (!nodeWrapper.isNodeType(p.getName())) { List<String> superTypes = p.getSuperTypes(); for (String s : superTypes) { if (nodeWrapper.isNodeType(s)) { nodeTypes.add(0, contentDefinition.getNodeType(s, getUILocale())); break; } } } else { nodeTypes.add(p); } } } final List<ExtendedNodeType> availableMixins = contentDefinition .getAvailableMixin(nodeWrapper.getPrimaryNodeTypeName(), nodeWrapper.getResolveSite()); List<GWTJahiaNodeType> theseMixin = contentDefinition.getGWTNodeTypes(availableMixins, getUILocale()); if (gwtMixin == null) { gwtMixin = theseMixin; } else { gwtMixin.retainAll(theseMixin); } allTypes.add(nodeWrapper.getPrimaryNodeType()); allTypes.addAll(Arrays.asList(nodeWrapper.getMixinNodeTypes())); allTypes.addAll(availableMixins); } final GWTJahiaEditEngineInitBean result = new GWTJahiaEditEngineInitBean(nodeTypes, new HashMap<String, GWTJahiaNodeProperty>()); result.setAvailabledLanguages(languages.getLanguages(getSite(), getLocale())); result.setCurrentLocale(languages.getCurrentLang(getLocale())); result.setMixin(gwtMixin); result.setInitializersValues(contentDefinition.getAllChoiceListInitializersValues(allTypes, NodeTypeRegistry.getInstance().getNodeType("nt:base"), nodeWrapper, nodeWrapper.getParent(), getUILocale())); result.setDefaultValues(new HashMap<String, Map<String, List<GWTJahiaNodePropertyValue>>>()); return result; } catch (PathNotFoundException e) { // the node no longer exists throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.cannot.get.node", getUILocale(), getLocalizedMessage(e))); } catch (RepositoryException e) { logger.error("Cannot get node", e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments("label.gwt.error.cannot.get.node", getUILocale(), getLocalizedMessage(e))); } }
From source file:edu.cmu.tetrad.search.TestIndTestConditionalCorrelation.java
public void test14e() { try {// w ww .ja v a2 s .c o m int numGraphs = 67; String graphDir = "/Users/josephramsey/Documents/LAB_NOTEBOOK.2012.04.20/2013.11.23/test14/"; double penalty = 1.0; List<Graph> graphs = new ArrayList<Graph>(); for (int i = 0; i < numGraphs; i++) { String tag = "images1"; // File file = new File(graphDir, "graph.ges." + penalty + "." + (i + 1) + ".txt"); File file = new File(graphDir, "graph." + tag + "." + penalty + "." + (i + 1) + ".txt"); Graph _graph = GraphUtils.loadGraphTxt(file); if (!graphs.isEmpty()) { _graph = GraphUtils.replaceNodes(_graph, graphs.get(0).getNodes()); } graphs.add(GraphUtils.undirectedGraph(_graph)); } Graph union = new EdgeListGraph(graphs.get(0).getNodes()); final Map<Edge, Integer> counts = new HashMap<Edge, Integer>(); List<Edge> intersectionEdges = new ArrayList<Edge>(graphs.get(0).getEdges()); Set<Edge> unionEdges = new HashSet<Edge>(); for (int i = 0; i < numGraphs; i++) { List<Edge> _edges = graphs.get(i).getEdges(); intersectionEdges.retainAll(_edges); unionEdges.addAll(_edges); // System.out.println(graphs.get(i).getEdges()); for (Edge edge : _edges) { increment(counts, edge); } // writeGraph(new File(graphDir, "graph.ges." + penalty + "." + "union.txt"), union); } List<Edge> _edges = new ArrayList<Edge>(counts.keySet()); Collections.sort(_edges, new Comparator<Edge>() { @Override public int compare(Edge o1, Edge o2) { return counts.get(o2) - counts.get(o1); } }); Graph topEdges = new EdgeListGraph(graphs.get(0).getNodes()); double percent = 0; for (Edge edge : _edges) { if (counts.get(edge) >= percent * graphs.size()) { // union.addEdge(edge); System.out.println(edge + " " + counts.get(edge)); topEdges.addEdge(edge); } } writeFiveGraphFormats(graphDir, topEdges, "topEdgesGes" + graphs.size() + "." + penalty + "." + percent + ".txt"); // System.out.println("INTERSECTION" + union); // for (Edge edge : counts.keySet()) { // System.out.println("Count for " + edge + " = " + counts.get(edge)); // } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jsweet.transpiler.Java2TypeScriptTranslator.java
@Override public void visitTopLevel(JCCompilationUnit topLevel) { if (context.isPackageErased(topLevel.packge)) { return;//from w w w. ja v a 2 s .com } boolean noDefs = true; for (JCTree def : topLevel.defs) { if (def instanceof JCClassDecl) { if (!context.isIgnored(((JCClassDecl) def))) { noDefs = false; } } } // do not print the compilation unit at all if no defs are to be printed if (!context.bundleMode && noDefs) { return; } isDefinitionScope = topLevel.packge.getQualifiedName().toString() .startsWith(JSweetConfig.LIBS_PACKAGE + "."); if (context.hasAnnotationType(topLevel.packge, JSweetConfig.ANNOTATION_MODULE)) { context.addExportedElement( context.getAnnotationValue(topLevel.packge, JSweetConfig.ANNOTATION_MODULE, null), topLevel.packge, getCompilationUnit()); } PackageSymbol rootPackage = context.getFirstEnclosingRootPackage(topLevel.packge); if (rootPackage != null) { if (!checkRootPackageParent(topLevel, rootPackage, (PackageSymbol) rootPackage.owner)) { return; } } context.importedTopPackages.clear(); context.rootPackages.add(rootPackage); // TODO: check relaxing @Root // if (context.useModules && context.rootPackages.size() > 1) { // if (!context.reportedMultipleRootPackages) { // report(topLevel.getPackageName(), // JSweetProblem.MULTIPLE_ROOT_PACKAGES_NOT_ALLOWED_WITH_MODULES, // context.rootPackages.toString()); // context.reportedMultipleRootPackages = true; // } // return; // } topLevelPackage = context.getTopLevelPackage(topLevel.packge); if (topLevelPackage != null) { context.topLevelPackageNames.add(topLevelPackage.getQualifiedName().toString()); } footer.delete(0, footer.length()); setCompilationUnit(topLevel); String packge = topLevel.packge.toString(); boolean globalModule = JSweetConfig.GLOBALS_PACKAGE_NAME.equals(packge) || packge.endsWith("." + JSweetConfig.GLOBALS_PACKAGE_NAME); String rootRelativePackageName = ""; if (!globalModule) { rootRelativePackageName = getRootRelativeName(topLevel.packge); if (rootRelativePackageName.length() == 0) { globalModule = true; } } List<String> packageSegments = new ArrayList<String>(Arrays.asList(rootRelativePackageName.split("\\."))); packageSegments.retainAll(JSweetConfig.TS_TOP_LEVEL_KEYWORDS); if (!packageSegments.isEmpty()) { report(topLevel.getPackageName(), JSweetProblem.PACKAGE_NAME_CONTAINS_KEYWORD, packageSegments); } // generate requires by looking up imported external modules for (JCImport importDecl : topLevel.getImports()) { TreeScanner importedModulesScanner = new TreeScanner() { @Override public void scan(JCTree tree) { if (tree instanceof JCFieldAccess) { JCFieldAccess qualified = (JCFieldAccess) tree; if (qualified.sym != null) { // regular import case (qualified.sym is a package) if (context.hasAnnotationType(qualified.sym, JSweetConfig.ANNOTATION_MODULE)) { String actualName = context.getAnnotationValue(qualified.sym, JSweetConfig.ANNOTATION_MODULE, null); useModule(true, null, importDecl, qualified.name.toString(), actualName, ((PackageSymbol) qualified.sym)); } } else { // static import case (imported fields and methods) if (qualified.selected instanceof JCFieldAccess) { JCFieldAccess qualifier = (JCFieldAccess) qualified.selected; if (qualifier.sym != null) { try { for (Symbol importedMember : qualifier.sym.getEnclosedElements()) { if (qualified.name.equals(importedMember.getSimpleName())) { if (context.hasAnnotationType(importedMember, JSweetConfig.ANNOTATION_MODULE)) { String actualName = context.getAnnotationValue(importedMember, JSweetConfig.ANNOTATION_MODULE, null); useModule(true, null, importDecl, importedMember.getSimpleName().toString(), actualName, importedMember); break; } } } } catch (Exception e) { // TODO: sometimes, // getEnclosedElement // fails because of string types // (find // out why if possible) e.printStackTrace(); } } } } } super.scan(tree); } }; importedModulesScanner.scan(importDecl.qualid); } for (JCImport importDecl : topLevel.getImports()) { if (importDecl.qualid instanceof JCFieldAccess) { JCFieldAccess qualified = (JCFieldAccess) importDecl.qualid; String importedName = qualified.name.toString(); if (importDecl.isStatic() && (qualified.selected instanceof JCFieldAccess)) { qualified = (JCFieldAccess) qualified.selected; } if (qualified.sym instanceof ClassSymbol) { ClassSymbol importedClass = (ClassSymbol) qualified.sym; if (Util.isSourceElement(importedClass) && !importedClass.getQualifiedName().toString() .startsWith(JSweetConfig.LIBS_PACKAGE + ".")) { String importedModule = importedClass.sourcefile.getName(); if (importedModule.equals(compilationUnit.sourcefile.getName())) { continue; } String pathToImportedClass = Util.getRelativePath( new File(compilationUnit.sourcefile.getName()).getParent(), importedModule); pathToImportedClass = pathToImportedClass.substring(0, pathToImportedClass.length() - 5); if (!pathToImportedClass.startsWith(".")) { pathToImportedClass = "./" + pathToImportedClass; } Symbol symbol = qualified.sym.getEnclosingElement(); while (!(symbol instanceof PackageSymbol)) { importedName = symbol.getSimpleName().toString(); symbol = symbol.getEnclosingElement(); } if (symbol != null) { useModule(false, (PackageSymbol) symbol, importDecl, importedName, pathToImportedClass.replace('\\', '/'), null); } } } } } if (context.useModules) { TreeScanner usedTypesScanner = new TreeScanner() { private void checkType(TypeSymbol type) { if (type instanceof ClassSymbol) { if (type.getEnclosingElement().equals(compilationUnit.packge)) { String importedModule = ((ClassSymbol) type).sourcefile.getName(); if (!importedModule.equals(compilationUnit.sourcefile.getName())) { importedModule = "./" + new File(importedModule).getName(); importedModule = importedModule.substring(0, importedModule.length() - 5); useModule(false, (PackageSymbol) type.getEnclosingElement(), null, type.getSimpleName().toString(), importedModule, null); } } } } @Override public void scan(JCTree t) { if (t != null && t.type != null && t.type.tsym instanceof ClassSymbol) { if (!(t instanceof JCTypeApply)) { checkType(t.type.tsym); } } super.scan(t); } }; usedTypesScanner.scan(compilationUnit); } // require root modules when using fully qualified names or reserved // keywords TreeScanner inlinedModuleScanner = new TreeScanner() { Stack<JCTree> stack = new Stack<>(); public void scan(JCTree t) { if (t != null) { stack.push(t); try { super.scan(t); } finally { stack.pop(); } } } @SuppressWarnings("unchecked") public <T extends JCTree> T getParent(Class<T> type) { for (int i = this.stack.size() - 2; i >= 0; i--) { if (type.isAssignableFrom(this.stack.get(i).getClass())) { return (T) this.stack.get(i); } } return null; } public void visitIdent(JCIdent identifier) { if (identifier.sym instanceof PackageSymbol) { // ignore packages in imports if (getParent(JCImport.class) != null) { return; } boolean isSourceType = false; for (int i = stack.size() - 2; i >= 0; i--) { JCTree tree = stack.get(i); if (!(tree instanceof JCFieldAccess)) { break; } else { JCFieldAccess fa = (JCFieldAccess) tree; if ((fa.sym instanceof ClassSymbol) && Util.isSourceElement(fa.sym)) { isSourceType = true; break; } } } if (!isSourceType) { return; } PackageSymbol identifierPackage = (PackageSymbol) identifier.sym; String pathToModulePackage = Util.getRelativePath(compilationUnit.packge, identifierPackage); if (pathToModulePackage == null) { return; } File moduleFile = new File(new File(pathToModulePackage), JSweetConfig.MODULE_FILE_NAME); if (!identifierPackage.getSimpleName().toString() .equals(compilationUnit.packge.getSimpleName().toString())) { useModule(false, identifierPackage, identifier, identifierPackage.getSimpleName().toString(), moduleFile.getPath().replace('\\', '/'), null); } } else if (identifier.sym instanceof ClassSymbol) { if (JSweetConfig.GLOBALS_PACKAGE_NAME .equals(identifier.sym.getEnclosingElement().getSimpleName().toString())) { String pathToModulePackage = Util.getRelativePath(compilationUnit.packge, identifier.sym.getEnclosingElement()); if (pathToModulePackage == null) { return; } File moduleFile = new File(new File(pathToModulePackage), JSweetConfig.MODULE_FILE_NAME); if (!identifier.sym.getEnclosingElement() .equals(compilationUnit.packge.getSimpleName().toString())) { useModule(false, (PackageSymbol) identifier.sym.getEnclosingElement(), identifier, JSweetConfig.GLOBALS_PACKAGE_NAME, moduleFile.getPath().replace('\\', '/'), null); } } } } @Override public void visitApply(JCMethodInvocation invocation) { // TODO: same for static variables if (invocation.meth instanceof JCIdent && JSweetConfig.TS_STRICT_MODE_KEYWORDS .contains(invocation.meth.toString().toLowerCase())) { PackageSymbol invocationPackage = (PackageSymbol) ((JCIdent) invocation.meth).sym .getEnclosingElement().getEnclosingElement(); String rootRelativeInvocationPackageName = getRootRelativeName(invocationPackage); if (rootRelativeInvocationPackageName.indexOf('.') == -1) { super.visitApply(invocation); return; } String targetRootPackageName = rootRelativeInvocationPackageName.substring(0, rootRelativeInvocationPackageName.indexOf('.')); String pathToReachRootPackage = Util.getRelativePath( "/" + compilationUnit.packge.getQualifiedName().toString().replace('.', '/'), "/" + targetRootPackageName); if (pathToReachRootPackage == null) { super.visitApply(invocation); return; } File moduleFile = new File(new File(pathToReachRootPackage), JSweetConfig.MODULE_FILE_NAME); if (!invocationPackage.toString().equals(compilationUnit.packge.getSimpleName().toString())) { useModule(false, invocationPackage, invocation, targetRootPackageName, moduleFile.getPath().replace('\\', '/'), null); } } super.visitApply(invocation); } }; // TODO: change the way qualified names are handled (because of new // module organization) // inlinedModuleScanner.scan(compilationUnit); if (!globalModule && !context.useModules) { printIndent(); if (isDefinitionScope) { print("declare "); } print("namespace ").print(rootRelativePackageName).print(" {").startIndent().println(); } for (JCTree def : topLevel.defs) { mainMethod = null; printIndent(); int pos = getCurrentPosition(); print(def); if (getCurrentPosition() == pos) { removeLastIndent(); continue; } println().println(); } if (!globalModule && !context.useModules) { removeLastChar().endIndent().printIndent().print("}").println(); } if (footer.length() > 0) { println().print(footer.toString()); } globalModule = false; }
From source file:com.belle.yitiansystem.merchant.service.impl.MerchantsService.java
/** * ??/*ww w . j a v a 2 s . c o m*/ * * @author wang.m * @date 2012-05-11 */ public PageFinder<MerchantRejectedAddress> getMerchantRejectedAddressList(Query query, MerchantRejectedAddress merchantRejectedAddress, String brand) { CritMap critMap = new CritMap(); if (null != merchantRejectedAddress) { // ?? if (StringUtils.isNotBlank(merchantRejectedAddress.getSupplierName())) { critMap.addLike("supplierName", merchantRejectedAddress.getSupplierName()); } // ? if (StringUtils.isNotBlank(merchantRejectedAddress.getSupplierCode())) { critMap.addLike("supplierCode", merchantRejectedAddress.getSupplierCode()); } // ?? if (StringUtils.isNotBlank(merchantRejectedAddress.getConsigneeName())) { critMap.addLike("consigneeName", merchantRejectedAddress.getConsigneeName()); } // if (StringUtils.isNotBlank(merchantRejectedAddress.getConsigneePhone())) { critMap.addLike("consigneePhone", merchantRejectedAddress.getConsigneePhone()); } // ? if (StringUtils.isNotBlank(merchantRejectedAddress.getConsigneeTell())) { critMap.addLike("consigneeTell", merchantRejectedAddress.getConsigneeTell()); } // List<String> merchantCodes = new ArrayList<String>(); if (StringUtils.isNotBlank(merchantRejectedAddress.getSupplierYgContacts())) { merchantCodes = supplierYgContactService .getSupplierList(merchantRejectedAddress.getSupplierYgContacts()); } // ? List<String> merchantCodes_brand = new ArrayList<String>(); if (StringUtils.isNotBlank(brand)) { List<Brand> brandList = commodityBaseApiService.getBrandListLikeBrandName("%" + brand, (short) 1); StringBuffer brand_in = new StringBuffer(); if (CollectionUtils.isNotEmpty(brandList)) { for (Brand brandVo : brandList) { brand_in.append("\"" + brandVo.getBrandNo() + "\","); } if (brand_in.length() > 0) { brand_in.setLength(brand_in.length() - 1); } Map<String, String> map = new HashMap<String, String>(); map.put("brands", brand_in.toString()); merchantCodes_brand = merchantBrandMapper.queryMerchantByBrands(map); } } // ??merchantCodelist if (CollectionUtils.isNotEmpty(merchantCodes) && CollectionUtils.isNotEmpty(merchantCodes_brand)) { merchantCodes.retainAll(merchantCodes_brand); if (null != merchantCodes && merchantCodes.size() > 0) { critMap.addIN("supplierCode", merchantCodes.toArray()); } } else if (CollectionUtils.isNotEmpty(merchantCodes)) { critMap.addIN("supplierCode", merchantCodes.toArray()); } else if (CollectionUtils.isNotEmpty(merchantCodes_brand)) { critMap.addIN("supplierCode", merchantCodes_brand.toArray()); } critMap.addDesc("createrTime"); } PageFinder<MerchantRejectedAddress> pageFinder = merchantRejectedAddressDaoImpl.pagedByCritMap(critMap, query.getPage(), query.getPageSize()); // PageFinder<MerchantRejectedAddress> pageFinder = // merchantRejectedAddressDaoImpl.pagedByHQL(hql, toPage, pageSize, // values) return pageFinder; }
From source file:com.xpn.xwiki.XWiki.java
/** * First try to find the current language in use from the XWiki context. If none is used and if the wiki is not * multilingual use the default language defined in the XWiki preferences. If the wiki is multilingual try to get * the language passed in the request. If none was passed try to get it from a cookie. If no language cookie exists * then use the user default language and barring that use the browser's "Accept-Language" header sent in HTTP * request. If none is defined use the default language. * //from w w w. j a v a 2 s .c om * @return the language to use */ public String getLanguagePreference(XWikiContext context) { // First we try to get the language from the XWiki Context. This is the current language // being used. String language = context.getLanguage(); if (language != null) { return language; } String defaultLanguage = getDefaultLanguage(context); // If the wiki is non multilingual then the language is the default language. if (!context.getWiki().isMultiLingual(context)) { language = defaultLanguage; context.setLanguage(language); return language; } // As the wiki is multilingual try to find the language to use from the request by looking // for a language parameter. If the language value is "default" use the default language // from the XWiki preferences settings. Otherwise set a cookie to remember the language // in use. try { language = Util.normalizeLanguage(context.getRequest().getParameter("language")); if ((language != null) && (!language.equals(""))) { if (language.equals("default")) { // forgetting language cookie Cookie cookie = new Cookie("language", ""); cookie.setMaxAge(0); cookie.setPath("/"); context.getResponse().addCookie(cookie); language = defaultLanguage; } else { // setting language cookie Cookie cookie = new Cookie("language", language); cookie.setMaxAge(60 * 60 * 24 * 365 * 10); cookie.setPath("/"); context.getResponse().addCookie(cookie); } context.setLanguage(language); return language; } } catch (Exception e) { } // As no language parameter was passed in the request, try to get the language to use // from a cookie. try { // First we get the language from the cookie language = Util.normalizeLanguage(getUserPreferenceFromCookie("language", context)); if ((language != null) && (!language.equals(""))) { context.setLanguage(language); return language; } } catch (Exception e) { } // Next from the default user preference try { String user = context.getUser(); XWikiDocument userdoc = null; userdoc = getDocument(user, context); if (userdoc != null) { language = Util.normalizeLanguage(userdoc.getStringValue("XWiki.XWikiUsers", "default_language")); if (!language.equals("")) { context.setLanguage(language); return language; } } } catch (XWikiException e) { } // If the default language is preferred, and since the user didn't explicitly ask for a // language already, then use the default wiki language. if (Param("xwiki.language.preferDefault", "0").equals("1") || getSpacePreference("preferDefaultLanguage", "0", context).equals("1")) { language = defaultLanguage; context.setLanguage(language); return language; } // Then from the navigator language setting if (context.getRequest() != null) { String acceptHeader = context.getRequest().getHeader("Accept-Language"); // If the client didn't specify some languages, skip this phase if ((acceptHeader != null) && (!acceptHeader.equals(""))) { List<String> acceptedLanguages = getAcceptedLanguages(context.getRequest()); // We can force one of the configured languages to be accepted if (Param("xwiki.language.forceSupported", "0").equals("1")) { List<String> available = Arrays.asList(getXWikiPreference("languages", context).split("[, |]")); // Filter only configured languages acceptedLanguages.retainAll(available); } if (acceptedLanguages.size() > 0) { // Use the "most-preferred" language, as requested by the client. context.setLanguage(acceptedLanguages.get(0)); return acceptedLanguages.get(0); } // If none of the languages requested by the client is acceptable, skip to next // phase (use default language). } } // Finally, use the default language from the global preferences. context.setLanguage(defaultLanguage); return defaultLanguage; }
From source file:org.sakaiproject.assignment.impl.BaseAssignmentService.java
/** * send notification to instructor type of users if necessary * @param s//from www. jav a2s . c om * @param a */ private void notificationToInstructors(AssignmentSubmission s, Assignment a) { String notiOption = a.getProperties().getProperty(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_VALUE); if (notiOption != null && !notiOption.equals(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_NONE)) { // need to send notification email String context = s.getContext(); // compare the list of users with the receive.notifications and list of users who can actually grade this assignment List receivers = allowReceiveSubmissionNotificationUsers(context); List allowGradeAssignmentUsers = allowGradeAssignmentUsers(a.getReference()); receivers.retainAll(allowGradeAssignmentUsers); String messageBody = getNotificationMessage(s, "submission"); if (notiOption.equals(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_EACH)) { // send the message immediately EmailService.sendToUsers(receivers, getHeaders(null, "submission"), messageBody); } else if (notiOption.equals(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_DIGEST)) { // just send plain/text version for now String digestMsgBody = getPlainTextNotificationMessage(s, "submission"); // digest the message to each user for (Iterator iReceivers = receivers.iterator(); iReceivers.hasNext();) { User user = (User) iReceivers.next(); DigestService.digest(user.getId(), getSubject("submission"), digestMsgBody); } } } }