Example usage for java.util List remove

List of usage examples for java.util List remove

Introduction

In this page you can find the example usage for java.util List remove.

Prototype

E remove(int index);

Source Link

Document

Removes the element at the specified position in this list (optional operation).

Usage

From source file:net.jforum.repository.GroupDao.java

@Override
public void remove(Group group) {
    List<User> users = group.getUsers();
    for (User user : users) {
        List<Group> groups = user.getGroups();
        groups.remove(group);
        session.save(user);//from w w w .  j a v a 2s.  co m
    }
    super.remove(group);
}

From source file:com.clustercontrol.infra.factory.AsyncModuleWorker.java

public static ModuleResult checkInfraModule(String sessionId, boolean verbose)
        throws HinemosUnknown, SessionNotFound, InfraManagementNotFound, InvalidRole {
    // ??//from   ww w. j a  v a2s . c om
    Session session = sessionMap.get(sessionId);
    if (session == null) {
        throw new SessionNotFound(sessionId);
    }
    List<AccessInfo> accessList = session.accessList;
    InfraManagementInfo management = session.management;
    List<InfraModuleInfo<?>> moduleList = session.moduleList;
    InfraModuleInfo<?> module = moduleList.get(0);
    List<String> skipNodeList = session.skipNodeList;

    // ???????
    new SelectInfraManagement().get(management.getManagementId(), ObjectPrivilegeMode.EXEC);

    moduleList.remove(0);

    // 
    ModuleResult ret = new ModuleResult(sessionId, module.getModuleId());
    if (moduleList.size() == 0) {
        ret.setHasNext(false);
        deleteSession(sessionId);
    } else {
        ret.setHasNext(true);
    }

    module.beforeRun(sessionId);

    try {
        // ??
        RepositoryControllerBean repository = new RepositoryControllerBean();
        List<Future<ModuleNodeResult>> futureList = new ArrayList<Future<ModuleNodeResult>>();
        List<String> runList = new ArrayList<>();
        for (AccessInfo access : accessList) {
            NodeInfo node;
            String facilityId = access.getFacilityId();
            if (skipNodeList.contains(facilityId)) {
                ModuleNodeResult result = new ModuleNodeResult(facilityId, OkNgConstant.TYPE_SKIP, -1, "");
                result.setRunCheckType(RunCheckTypeConstant.TYPE_CHECK);
                ret.getModuleNodeResultList().add(result);
                continue;
            }
            try {
                node = repository.getNode(facilityId);
                Future<ModuleNodeResult> future = executor
                        .submit(new ModuleCheckTask(management, module, node, access, sessionId, verbose));
                futureList.add(future);
                runList.add(facilityId);
            } catch (FacilityNotFound e) {
                m_log.debug(e.getMessage(), e);
            }
        }

        // ?????
        long timeout = HinemosPropertyUtil.getHinemosPropertyNum("infra.check.timeout",
                Long.valueOf(50 * 1000));
        int i = 0;
        for (Future<ModuleNodeResult> future : futureList) {
            String facilityId = runList.get(i);
            ModuleNodeResult result = null;
            String message = null;
            try {
                result = future.get(timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | ExecutionException e) {
                message = e.getCause().getMessage();
                if (message == null) {
                    message = e.getClass().getName() + ":" + e.getMessage();
                }
                m_log.warn("runInfraModule : " + e.getMessage(), e);
            } catch (Exception e) {
                message = e.getMessage();
                if (message == null) {
                    message = e.getClass().getName();
                }
            }
            if (message != null) {
                m_log.warn("checkInfraModule : " + message);
                result = new ModuleNodeResult(facilityId, OkNgConstant.TYPE_NG, -1, message);
                result.setRunCheckType(RunCheckTypeConstant.TYPE_CHECK);
            }
            ret.getModuleNodeResultList().add(result);
            i++;
        }

        UpdateInfraCheckResult.update(management.getManagementId(), module.getModuleId(),
                ret.getModuleNodeResultList());

    } finally {
        module.afterRun(sessionId);
    }

    if (module instanceof CommandModuleInfo) {
        ret.setModuleType(ModuleTypeConstant.TYPE_COMMAND);
    } else if (module instanceof FileTransferModuleInfo) {
        ret.setModuleType(ModuleTypeConstant.TYPE_FILETRANSFER);
    }
    return ret;
}

From source file:MapList.java

public void remove(K key, V value) {
    List<V> values = get(key);
    if (values != null) {
        values.remove(value);
    }
}

From source file:com.clustercontrol.infra.factory.AsyncModuleWorker.java

public static ModuleResult runInfraModule(String sessionId)
        throws HinemosUnknown, SessionNotFound, InfraManagementNotFound, InvalidRole {
    // ??/*from  ww w. j  a va  2  s  . c  o  m*/
    Session session = sessionMap.get(sessionId);
    if (session == null) {
        throw new SessionNotFound(sessionId);
    }

    List<AccessInfo> accessList = session.accessList;
    InfraManagementInfo management = session.management;
    List<InfraModuleInfo<?>> moduleList = session.moduleList;
    List<String> skipNodeList = session.skipNodeList;
    InfraModuleInfo<?> module = moduleList.get(0);

    // ???????
    new SelectInfraManagement().get(management.getManagementId(), ObjectPrivilegeMode.EXEC);

    moduleList.remove(0);

    // 
    ModuleResult ret = new ModuleResult(sessionId, module.getModuleId());
    if (moduleList.size() == 0) {
        ret.setHasNext(false);
        deleteSession(sessionId);
    } else {
        ret.setHasNext(true);
    }

    module.beforeRun(sessionId);

    try {
        // 
        RepositoryControllerBean repository = new RepositoryControllerBean();
        List<Future<ModuleNodeResult>> futureList = new ArrayList<Future<ModuleNodeResult>>();
        List<String> runList = new ArrayList<>();
        for (AccessInfo access : accessList) {
            String facilityId = access.getFacilityId();
            if (skipNodeList.contains(facilityId)) {
                ModuleNodeResult result = new ModuleNodeResult(facilityId, OkNgConstant.TYPE_SKIP, -1, "");
                result.setRunCheckType(RunCheckTypeConstant.TYPE_RUN);
                ret.getModuleNodeResultList().add(result);
                continue;
            }
            NodeInfo node;
            try {
                node = repository.getNode(facilityId);
                Future<ModuleNodeResult> future = executor
                        .submit(new ModuleRunTask(management, module, node, access, sessionId));
                futureList.add(future);
                runList.add(facilityId);
            } catch (FacilityNotFound e) {
                m_log.debug(e.getMessage(), e);
            }
        }

        // ???
        long timeout = HinemosPropertyUtil.getHinemosPropertyNum("infra.run.timeout",
                Long.valueOf(5 * 60 * 1000));
        int i = 0;
        for (Future<ModuleNodeResult> future : futureList) {
            String facilityId = runList.get(i);
            ModuleNodeResult result = null;
            String message = null;
            try {
                result = future.get(timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | ExecutionException e) {
                message = e.getCause().getMessage();
                if (message == null) {
                    message = e.getClass().getName() + ":" + e.getMessage();
                }
                m_log.warn("runInfraModule : " + e.getMessage(), e);
            } catch (Exception e) {
                message = e.getMessage();
                if (message == null) {
                    message = e.getClass().getName();
                }
            }
            if (message != null) {
                m_log.warn("runInfraModule : " + message);
                result = new ModuleNodeResult(facilityId, OkNgConstant.TYPE_NG, -1, message);
                result.setRunCheckType(RunCheckTypeConstant.TYPE_RUN);
            }
            if (result == null) {
                result = new ModuleNodeResult(facilityId, OkNgConstant.TYPE_NG, -1, "unknownException 523"); // ???????
                result.setRunCheckType(RunCheckTypeConstant.TYPE_RUN);
            }
            // ?????
            if (module.getStopIfFailFlg()) {
                if (result.getResult() == OkNgConstant.TYPE_NG) {
                    skipNodeList.add(facilityId);
                }
            }
            ret.getModuleNodeResultList().add(result);
            i++;
        }
    } finally {
        module.afterRun(sessionId);
    }

    if (module instanceof CommandModuleInfo) {
        ret.setModuleType(ModuleTypeConstant.TYPE_COMMAND);
    } else if (module instanceof FileTransferModuleInfo) {
        ret.setModuleType(ModuleTypeConstant.TYPE_FILETRANSFER);
    }
    return ret;
}

From source file:com.github.xbn.list.ListUtil.java

/**
   <p>YYY</p>/*from  w  ww .  ja  v  a 2  s. c  o  m*/
        
 * @exception  XbnIndexOutOfBoundsException  If any {@code list_ofUniqueAscIdxsToDelete} are invalid for {@code list}, or if its elements are not unique or ascending, causing subsequent indexes (that <i>were</i> valid) to not be valid.
 */
public static final void deleteElementsNotInAscUnqIndexList(List<?> list,
        List<Integer> list_ofUniqueAscIdxsToDelete) {
    int iOrigSz = -1;
    //      int iLXSz = -1;
    try {
        iOrigSz = list.size();
        //         iLXSz = list_ofUniqueAscIdxsToDelete.size();
    } catch (RuntimeException rx) {
        Objects.requireNonNull(list, "list");
        throw CrashIfObject.nullOrReturnCause(list_ofUniqueAscIdxsToDelete, "list_ofUniqueAscIdxsToDelete",
                null, rx);
    }

    //Going backwards, so indexes in list_ofUniqueAscIdxsToDelete don't have to be decremented.
    for (int i = (list_ofUniqueAscIdxsToDelete.size() - 1); i >= 0; i--) {
        int ix = list_ofUniqueAscIdxsToDelete.get(i);
        try {
            list.remove(ix);
        } catch (IndexOutOfBoundsException ibx) {
            String sInfo = "Attempting list.remove(list_ofUniqueAscIdxsToDelete.get(" + i
                    + "). list_ofUniqueAscIdxsToDelete.get(" + i + ")=[" + ix
                    + "]. It is assumed-but-not-verified that list_ofUniqueAscIdxsToDelete contains only unique elements and is ordered ascending: ["
                    + StringUtils.join(list_ofUniqueAscIdxsToDelete, ", ")
                    + "]. Also note that list is as it exists after some deletions -- Its original size was "
                    + iOrigSz + ".";
            throw new XbnIndexOutOfBoundsException_Cfg()
                    .badIndex(ix, "list_ofUniqueAscIdxsToDelete.get(" + i + ")").absCollectionSize(list, "list")
                    .buildWithCauseInfo(ibx, sInfo);
        }
    }
}

From source file:com.example.app.support.service.AppUtil.java

/**
 * Add the given object into the given list only if the object is not already within the list.
 *
 * @param <V> the type of the list
 * @param list the List to add the object to
 * @param object the object to add to the list
 * @param index optional index to add the object at within the list.  If the object is already added in the list, ensures
 * that the object is placed at the given index, if one is specified.
 *
 * @return the list.//from  www  .  jav  a  2 s . c om
 */
public static <V> List<V> addIfNotContains(List<V> list, V object, @Nullable Integer index) {
    if (!list.contains(object)) {
        list.add(object);
    }
    if (index != null) {
        list.remove(object);
        list.add(index, object);
    }
    return list;
}

From source file:name.abhijitsarkar.javaee.coffeehouse.spring.WeekdayMenu.java

@PostConstruct
public void postConstruct() {
    LOGGER.debug("Creating a weekday menu.");

    final List<Coffee.Blend> blendsOnTheMenu = super.getBlends();
    blendsOnTheMenu.remove(Coffee.Blend.DECAF);

    this.setBlends(blendsOnTheMenu);
}

From source file:com.act.lcms.db.analysis.FeedingAnalysis.java

private static void performFeedingAnalysis(DB db, String lcmsDir, String searchIon, String searchMassStr,
        String plateBarcode, String strainOrConstruct, String extract, String feedingCondition,
        String outPrefix, String fmt) throws SQLException, Exception {
    Plate p = Plate.getPlateByBarcode(db, plateBarcode);
    if (p == null) {
        throw new RuntimeException(String.format("Unable to find plate with barcode %s", plateBarcode));
    }/*from  ww w.ja  v  a  2s. co m*/
    if (p.getContentType() != Plate.CONTENT_TYPE.FEEDING_LCMS) {
        throw new RuntimeException(String.format("Plate with barcode %s is not a feeding plate (%s)",
                plateBarcode, p.getContentType()));
    }
    List<FeedingLCMSWell> allPlateWells = FeedingLCMSWell.getInstance().getFeedingLCMSWellByPlateId(db,
            p.getId());
    if (allPlateWells == null || allPlateWells.size() == 0) {
        throw new RuntimeException(
                String.format("No feeding LCMS wells available for plate %s", p.getBarcode()));
    }

    List<FeedingLCMSWell> relevantWells = new ArrayList<>();
    for (FeedingLCMSWell well : allPlateWells) {
        if (!well.getMsid().equals(strainOrConstruct) && !well.getComposition().equals(strainOrConstruct)) {
            // Ignore wells that don't have the right strain/construct (though we assume the whole plate shares one).
            continue;
        }

        if (!well.getExtract().equals(extract)) {
            // Filter by extract.
            continue;
        }

        if (!well.getChemical().equals(feedingCondition)) {
            // Filter by fed chemical.
            continue;
        }

        relevantWells.add(well);
    }

    Collections.sort(relevantWells, new Comparator<FeedingLCMSWell>() {
        @Override
        public int compare(FeedingLCMSWell o1, FeedingLCMSWell o2) {
            // Assume concentration is never null.
            return o1.getConcentration().compareTo(o2.getConcentration());
        }
    });

    Map<FeedingLCMSWell, ScanFile> wellsToScanFiles = new HashMap<>();
    Set<String> constructs = new HashSet<>(1);
    for (FeedingLCMSWell well : relevantWells) {
        List<ScanFile> scanFiles = ScanFile.getScanFileByPlateIDRowAndColumn(db, well.getPlateId(),
                well.getPlateRow(), well.getPlateColumn());
        if (scanFiles == null || scanFiles.size() == 0) {
            System.err.format("WARNING: no scan files for well at %s %s\n", p.getBarcode(),
                    well.getCoordinatesString());
            continue;
        }
        if (scanFiles.size() > 1) {
            System.err.format("WARNING: found multiple scan files for %s %s, using first\n", p.getBarcode(),
                    well.getCoordinatesString());
        }
        while (scanFiles.size() > 0 && scanFiles.get(0).getFileType() != ScanFile.SCAN_FILE_TYPE.NC) {
            scanFiles.remove(0);
        }
        if (scanFiles.size() == 0) {
            System.err.format("WARNING: no scan files with valid format for %s %s\n", p.getBarcode(),
                    well.getCoordinatesString());
            continue;
        }
        // All of the extracted wells should be unique, so there should be no collisions here.
        wellsToScanFiles.put(well, scanFiles.get(0));
        constructs.add(well.getComposition());
    }

    Pair<String, Double> searchMass = null;
    if (searchMassStr != null) {
        searchMass = Utils.extractMassFromString(db, searchMassStr);
    }
    if (searchMass == null) {
        if (constructs.size() != 1) {
            throw new RuntimeException(String.format(
                    "Found multiple growth targets for feeding analysis when no mass specified: %s",
                    StringUtils.join(constructs, ", ")));
        }
        String constructName = constructs.iterator().next();
        CuratedChemical cc = Utils.extractTargetForConstruct(db, constructName);
        if (cc == null) {
            throw new RuntimeException(
                    String.format("Unable to find curated chemical for construct %s", constructName));
        }
        System.out.format("Using target %s of construct %s as search mass (%f)\n", cc.getName(), constructName,
                cc.getMass());
        searchMass = Pair.of(cc.getName(), cc.getMass());
    }

    MS1 c = new MS1();
    // TODO: use configurable or scan-file derived ion mode. Do it the way its done in:
    // https://github.com/20n/act/blob/d997e84f0f44a5c88a94ef935829cb47e0ca8d1a/reachables/src/main/java/com/act/lcms/db/analysis/AnalysisHelper.java#L79
    MS1.IonMode mode = MS1.IonMode.valueOf("POS");
    Map<String, Double> metlinMasses = c.getIonMasses(searchMass.getValue(), mode);

    if (searchIon == null || searchIon.isEmpty()) {
        System.err.format("No search ion defined, defaulting to M+H\n");
        searchIon = DEFAULT_ION;
    }

    List<Pair<Double, MS1ScanForWellAndMassCharge>> rampUp = new ArrayList<>();
    for (FeedingLCMSWell well : relevantWells) {
        ScanFile scanFile = wellsToScanFiles.get(well);
        if (scanFile == null) {
            System.err.format("WARNING: no scan file available for %s %s", p.getBarcode(),
                    well.getCoordinatesString());
            continue;
        }
        File localScanFile = new File(lcmsDir, scanFile.getFilename());
        if (!localScanFile.exists() && localScanFile.isFile()) {
            System.err.format("WARNING: could not find regular file at expected path: %s\n",
                    localScanFile.getAbsolutePath());
            continue;
        }
        System.out.format("Processing scan data at %s\n", localScanFile.getAbsolutePath());

        MS1ScanForWellAndMassCharge ms1ScanCache = new MS1ScanForWellAndMassCharge();
        MS1ScanForWellAndMassCharge ms1ScanResults = ms1ScanCache
                .getByPlateIdPlateRowPlateColUseSnrScanFileChemical(db, p, well, true, scanFile,
                        searchMass.getKey(), metlinMasses, localScanFile);

        Double concentration = well.getConcentration();
        rampUp.add(Pair.of(concentration, ms1ScanResults));
    }

    WriteAndPlotMS1Results plotFeedingsResults = new WriteAndPlotMS1Results();
    plotFeedingsResults.plotFeedings(rampUp, searchIon, outPrefix, fmt, outPrefix + ".gnuplot");
}

From source file:com.baidu.rigel.biplatform.ac.util.DataModelUtils.java

/**
 * ?//from w w  w. j  a v  a  2  s .  c  o  m
 * 
 * @param field 
 * @param rowHeadFields datamodel
 */
public static void removeField(HeadField field, List<HeadField> rowHeadFields) {
    HeadField parentField = field.getParentLevelField();
    if (field.getParentLevelField() != null) {
        parentField.getNodeList().remove(field);
        if (parentField.getChildren().isEmpty() && parentField.getNodeList().isEmpty()) {
            removeField(parentField, rowHeadFields);
        }
    } else {
        rowHeadFields.remove(field);
    }
    if (field.getParent() != null) {
        field.getParent().getChildren().remove(field);
    }
}

From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java

public static void removeHook(List<String> optionList, ExecutionContext sessionContext) {

    // hook?command??optioncontext
    if (optionList.contains("--enablehook")) {

        if (optionList.indexOf("--enablehook") + 1 < optionList.size()) {

            int index = optionList.indexOf("--enablehook");
            // command
            String hook = optionList.get(index + 1);

            // --enablehook ??
            optionList.remove(optionList.indexOf("--enablehook"));
            optionList.remove(optionList.indexOf(hook));

            if (!Boolean.valueOf(hook)) {
                sessionContext.setOdpsHooks(null);
            }/*from w w w.j  a  v a 2  s .c o m*/
        }
    }

}