List of usage examples for java.util List remove
E remove(int index);
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.mapping.CompassMappingUtils.java
/** * Resolve aliases between mappings/* w w w. j av a 2 s. com*/ * Note this method is destructive in the sense that it modifies the passed in mappings */ public static void resolveAliases(List classMappings, Collection grailsDomainClasses) { // set defaults for those classes without explicit aliases and collect aliases Map mappingByClass = new HashMap(); Map mappingsByAlias = new HashMap(); for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); if (classMapping.getAlias() == null) { classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass())); } mappingByClass.put(classMapping.getMappedClass(), classMapping); List mappings = (List) mappingsByAlias.get(classMapping.getAlias()); if (mappings == null) { mappings = new ArrayList(); mappingsByAlias.put(classMapping.getAlias(), mappings); } mappings.add(classMapping); } // override duplicate inherited aliases for (Iterator iter = mappingsByAlias.keySet().iterator(); iter.hasNext();) { List mappings = (List) mappingsByAlias.get(iter.next()); if (mappings.size() == 1) { continue; } CompassClassMapping parentMapping = null; for (Iterator miter = mappings.iterator(); miter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) miter.next(); if (classMapping.getMappedClassSuperClass() == null) { parentMapping = classMapping; break; } } mappings.remove(parentMapping); for (Iterator miter = mappings.iterator(); miter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) miter.next(); LOG.debug("Overriding duplicated alias [" + classMapping.getAlias() + "] for class [" + classMapping.getMappedClass().getName() + "] with default alias. (Aliases must be unique - maybe this was inherited from a superclass?)"); classMapping.setAlias(getDefaultAlias(classMapping.getMappedClass())); } } // resolve property ref aliases for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); Class mappedClass = classMapping.getMappedClass(); for (Iterator piter = classMapping.getPropertyMappings().iterator(); piter.hasNext();) { CompassClassPropertyMapping propertyMapping = (CompassClassPropertyMapping) piter.next(); if ((propertyMapping.isComponent() || propertyMapping.isReference()) && !propertyMapping.hasAttribute("refAlias")) { Set aliases = new HashSet(); Class clazz = propertyMapping.getPropertyType(); aliases.add(((CompassClassMapping) mappingByClass.get(clazz)).getAlias()); GrailsDomainClassProperty domainClassProperty = GrailsDomainClassUtils .getGrailsDomainClassProperty(grailsDomainClasses, mappedClass, propertyMapping.getPropertyName()); Collection clazzes = GrailsDomainClassUtils .getClazzes(domainClassProperty.getReferencedDomainClass().getSubClasses()); for (Iterator citer = clazzes.iterator(); citer.hasNext();) { CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(citer.next()); if (mapping != null) { aliases.add(mapping.getAlias()); } } propertyMapping.setAttrbute("refAlias", DefaultGroovyMethods.join(aliases, ", ")); } } } // resolve extend aliases for (Iterator iter = classMappings.iterator(); iter.hasNext();) { CompassClassMapping classMapping = (CompassClassMapping) iter.next(); Class mappedClassSuperClass = classMapping.getMappedClassSuperClass(); if (mappedClassSuperClass != null && classMapping.getExtend() == null) { CompassClassMapping mapping = (CompassClassMapping) mappingByClass.get(mappedClassSuperClass); classMapping.setExtend(mapping.getAlias()); } } }
From source file:jmupen.MyListSelectionListener.java
private void removeLines(int removeLine, File text) throws IOException { List<String> textLines = FileUtils.readLines(text, StandardCharsets.UTF_8); textLines.remove(removeLine); StringBuilder builder = new StringBuilder(); for (String line : textLines) { builder.append(line).append(System.lineSeparator()); }//from ww w . j a va2s. c om FileUtils.writeStringToFile(text, builder.toString()); }
From source file:WebClient.java
public boolean remove(URI uri, HttpCookie cookie) { List<HttpCookie> cookies = map.get(uri); if (cookies == null) { return false; }/* w w w . j ava2 s .co m*/ return cookies.remove(cookie); }
From source file:com.google.dart.java2dart.engine.EngineSemanticProcessor.java
/** * Find code like://w w w. j a v a 2s . c om * * <pre> * Field scopeField = visitor.getClass().getSuperclass().getDeclaredField("nameScope"); * scopeField.setAccessible(true); * Scope outerScope = (Scope) scopeField.get(visitor); * </pre> * * and replaces it with direct calling of generated public accessors. */ static void rewriteReflectionFieldsWithDirect(final Context context, CompilationUnit unit) { final Map<String, String> varToField = Maps.newHashMap(); final Map<String, String> varToMethod = Maps.newHashMap(); final Set<Pair<String, String>> refClassFields = Sets.newHashSet(); final String accessorSuffix = "_J2DAccessor"; unit.accept(new RecursiveASTVisitor<Void>() { @Override public Void visitBlock(Block node) { List<Statement> statements = ImmutableList.copyOf(node.getStatements()); for (Statement statement : statements) { statement.accept(this); } return null; } @Override public Void visitExpressionStatement(ExpressionStatement node) { if (node.getExpression() instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) node.getExpression(); if (JavaUtils.isMethod(context.getNodeBinding(invocation), "java.lang.reflect.AccessibleObject", "setAccessible")) { ((Block) node.getParent()).getStatements().remove(node); return null; } } return super.visitExpressionStatement(node); } @Override public Void visitMethodInvocation(MethodInvocation node) { List<Expression> arguments = node.getArgumentList().getArguments(); if (JavaUtils.isMethod(context.getNodeBinding(node), "java.lang.reflect.Field", "get")) { Expression target = arguments.get(0); String varName = ((SimpleIdentifier) node.getTarget()).getName(); String fieldName = varToField.get(varName); String accessorName = fieldName + accessorSuffix; SemanticProcessor.replaceNode(node, propertyAccess(target, identifier(accessorName))); return null; } if (JavaUtils.isMethod(context.getNodeBinding(node), "java.lang.reflect.Field", "set")) { Expression target = arguments.get(0); String varName = ((SimpleIdentifier) node.getTarget()).getName(); String fieldName = varToField.get(varName); String accessorName = fieldName + accessorSuffix; SemanticProcessor.replaceNode(node, assignmentExpression( propertyAccess(target, identifier(accessorName)), TokenType.EQ, arguments.get(1))); return null; } if (JavaUtils.isMethod(context.getNodeBinding(node), "java.lang.reflect.Method", "invoke")) { Expression target = arguments.get(0); String varName = ((SimpleIdentifier) node.getTarget()).getName(); String methodName = varToMethod.get(varName); List<Expression> methodArgs; if (arguments.size() == 1) { methodArgs = Lists.newArrayList(); } else if (arguments.size() == 2 && arguments.get(1) instanceof ListLiteral) { methodArgs = ((ListLiteral) arguments.get(1)).getElements(); } else { methodArgs = Lists.newArrayList(arguments); methodArgs.remove(0); } if (methodName != null) { SemanticProcessor.replaceNode(node, methodInvocation(target, methodName, methodArgs)); } return null; } return super.visitMethodInvocation(node); } @Override public Void visitVariableDeclarationStatement(VariableDeclarationStatement node) { super.visitVariableDeclarationStatement(node); VariableDeclarationList variableList = node.getVariables(); ITypeBinding typeBinding = context.getNodeTypeBinding(variableList.getType()); List<VariableDeclaration> variables = variableList.getVariables(); if (JavaUtils.isTypeNamed(typeBinding, "java.lang.reflect.Field") && variables.size() == 1) { VariableDeclaration variable = variables.get(0); if (variable.getInitializer() instanceof MethodInvocation) { MethodInvocation initializer = (MethodInvocation) variable.getInitializer(); if (JavaUtils.isMethod(context.getNodeBinding(initializer), "java.lang.Class", "getDeclaredField")) { Expression getFieldArgument = initializer.getArgumentList().getArguments().get(0); String varName = variable.getName().getName(); String fieldName = ((SimpleStringLiteral) getFieldArgument).getValue(); varToField.put(varName, fieldName); ((Block) node.getParent()).getStatements().remove(node); // add (Class, Field) pair to generate accessor later addClassFieldPair(initializer.getTarget(), fieldName); } } } if (JavaUtils.isTypeNamed(typeBinding, "java.lang.reflect.Method") && variables.size() == 1) { VariableDeclaration variable = variables.get(0); if (variable.getInitializer() instanceof MethodInvocation) { MethodInvocation initializer = (MethodInvocation) variable.getInitializer(); if (JavaUtils.isMethod(context.getNodeBinding(initializer), "java.lang.Class", "getDeclaredMethod")) { Expression getMethodArgument = initializer.getArgumentList().getArguments().get(0); String varName = variable.getName().getName(); String methodName = ((SimpleStringLiteral) getMethodArgument).getValue(); varToMethod.put(varName, methodName); ((Block) node.getParent()).getStatements().remove(node); } } } return null; } private void addClassFieldPair(Expression target, String fieldName) { while (target instanceof MethodInvocation) { target = ((MethodInvocation) target).getTarget(); } // we expect: object.runtimeType if (target instanceof PropertyAccess) { Expression classTarget = ((PropertyAccess) target).getTarget(); ITypeBinding classTargetBinding = context.getNodeTypeBinding(classTarget); String className = classTargetBinding.getName(); refClassFields.add(Pair.of(className, fieldName)); } } }); // generate private field accessors unit.accept(new RecursiveASTVisitor<Void>() { @Override public Void visitClassDeclaration(ClassDeclaration node) { String className = node.getName().getName(); for (Pair<String, String> pair : refClassFields) { if (pair.getLeft().equals(className)) { String fieldName = pair.getRight(); String accessorName = fieldName + accessorSuffix; String privateFieldName = "_" + fieldName; node.getMembers() .add(methodDeclaration(null, null, Keyword.GET, null, identifier(accessorName), null, expressionFunctionBody(identifier(privateFieldName)))); node.getMembers() .add(methodDeclaration(null, null, Keyword.SET, null, identifier(accessorName), formalParameterList(simpleFormalParameter("__v")), expressionFunctionBody(assignmentExpression(identifier(privateFieldName), TokenType.EQ, identifier("__v"))))); } } return super.visitClassDeclaration(node); } }); }
From source file:com.ms.commons.test.classloader.IntlTestURLClassPath.java
private static List<URL> adjustJarIndex(List<URL> urlList) { int indexOfJ2EE = findJarIndex(urlList, ".*[\\W]j2ee[^\\\\/]*\\.jar"); int indexOfMail = findJarIndex(urlList, ".*[\\W]mail[^\\\\/]*\\.jar"); int indexOfActivation = findJarIndex(urlList, ".*[\\W]activation.*\\.jar"); int indexMaxMailOrActivation = Math.max(indexOfMail, indexOfActivation); if ((indexOfJ2EE == -1) || (indexMaxMailOrActivation == -1)) { System.err.println("Cannot find j2ee or mail|activation, do not adj. index."); } else {/*from w ww.ja v a2 s.co m*/ if (indexOfJ2EE > indexMaxMailOrActivation) { System.err.println("J2ee is after mail|activation, do not adj. index."); } else { URL j2eeUrl = urlList.remove(indexOfJ2EE); urlList.add(j2eeUrl); System.err.println("Classpath url order has been adjusted:" + urlList); } } // adjust classes and classes.test try { if (urlList.size() >= 2) { URL url1 = urlList.get(0); URL url2 = urlList.get(1); if (url1.toString().contains("/target/classes/") && url2.toString().contains("/target/classes.test/")) { urlList.add(0, urlList.remove(1)); } } } catch (Exception e) { System.err.println("Adjust classes and classes.test failed."); e.printStackTrace(); } return urlList; }
From source file:HashList.java
public boolean remove(Object key, Object value) { List l = (List) get(key); if (l == null) { return false; } else {//from w w w .j a v a2s . c om boolean r = l.remove(value); if (l.size() == 0) { remove(key); } return r; } }
From source file:org.codhaus.groovy.grails.validation.ext.ConstrainedPropertyGunn.java
public static void removeConstraint(String name, Class<?> constraintClass) { Assert.hasLength(name, "Argument [name] cannot be null"); List<Object> objects = getOrInitializeConstraint(name); objects.remove(constraintClass); List<Object> toRemove = new ArrayList<Object>(); for (Object object : objects) { if (constraintClass.isInstance(object)) { toRemove.add(object);/*from w w w . j a v a2s. c o m*/ } } objects.removeAll(toRemove); }
From source file:com.aurel.track.admin.server.dbbackup.DatabaseBackupBL.java
public static void checkBackupNumber(int backupNumber) throws DatabaseBackupBLException { //Obtain the backup list file name sorted by lastModified. //The first element is the most recent List<File> backups = getBackupFiles(); if (backups.size() > backupNumber) { LOGGER.debug("Must Remove " + (backups.size() - backupNumber) + " backup files!"); while (backups.size() > backupNumber) { File backupFile = backups.get(backups.size() - 1); try { backupFile.delete();// w w w. j ava2s.c om } catch (Exception ex) { LOGGER.error("Can't delete backup file:" + backupFile.getAbsolutePath()); if (LOGGER.isDebugEnabled()) { LOGGER.error(ExceptionUtils.getStackTrace(ex)); } } backups.remove(backups.size() - 1); } } }
From source file:com.github.cereda.arara.langchecker.LanguageUtils.java
/** * Pumps the elements to a string representation according to the provided * number of times./*from www . j a va 2 s . c om*/ * @param lines The list of pairs. * @param number The number of times for elements to be pumped. * @return A string representation. */ private static String pump(List<Pair<Integer, Character>> lines, int number) { // local counter, acting as a // safe check for elements int i = 0; // if there is nothing else to // be pumped, return an empty string if (lines.isEmpty()) { return ""; } // at first, the result is an // empty string String result = ""; // let's get the correct number of elements // or return the result as it is in case of // less elements than expected while ((i < number) && (!lines.isEmpty())) { // build the result, removing the first // element in the provided list result = result.concat(String.valueOf(lines.remove(0))).concat(" "); i++; } // return the trimmed element, so the trailing // space added in the previous loop is gone return result.trim(); }
From source file:com.hippo.ehviewer.client.EhEngine.java
public static GalleryListParser.Result getGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception { Log.d(TAG, url);/*from ww w. j av a2 s. co m*/ Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()) .build(); Call call = okHttpClient.newCall(request); // Put call if (null != task) { task.setCall(call); } String body = null; Headers headers = null; GalleryListParser.Result result; int code = -1; try { Response response = call.execute(); code = response.code(); headers = response.headers(); body = response.body().string(); result = GalleryListParser.parse(body); } catch (Exception e) { throwException(call, code, headers, body, e); throw e; } // Filter title and uploader List<GalleryInfo> list = result.galleryInfoList; for (int i = 0, n = list.size(); i < n; i++) { GalleryInfo info = list.get(i); if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) { list.remove(i); i--; n--; } } if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) { // Fill by api fillGalleryListByApi(task, okHttpClient, list); // Filter tag for (int i = 0, n = list.size(); i < n; i++) { GalleryInfo info = list.get(i); if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) { list.remove(i); i--; n--; } } } for (GalleryInfo info : list) { info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb); } return result; }