Example usage for java.util Vector remove

List of usage examples for java.util Vector remove

Introduction

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

Prototype

public synchronized E remove(int index) 

Source Link

Document

Removes the element at the specified position in this Vector.

Usage

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JTable createTable(final ViewState state) {
    JTable table;/*from   ww w .  jav a 2 s  . c  om*/
    final ModelGraph selected = state.getSelected();
    if (selected != null) {
        final Vector<Vector<String>> rows = new Vector<Vector<String>>();
        ConcurrentHashMap<String, String> keyToGroupMap = new ConcurrentHashMap<String, String>();
        Metadata staticMet = selected.getModel().getStaticMetadata();
        Metadata inheritedMet = selected.getInheritedStaticMetadata(state);
        Metadata completeMet = new Metadata();
        if (staticMet != null) {
            completeMet.replaceMetadata(staticMet.getSubMetadata(state.getCurrentMetGroup()));
        }
        if (selected.getModel().getExtendsConfig() != null) {
            for (String configGroup : selected.getModel().getExtendsConfig()) {
                Metadata extendsMetadata = state.getGlobalConfigGroups().get(configGroup).getMetadata()
                        .getSubMetadata(state.getCurrentMetGroup());
                for (String key : extendsMetadata.getAllKeys()) {
                    if (!completeMet.containsKey(key)) {
                        keyToGroupMap.put(key, configGroup);
                        completeMet.replaceMetadata(key, extendsMetadata.getAllMetadata(key));
                    }
                }
            }
        }
        if (inheritedMet != null) {
            Metadata inheritedMetadata = inheritedMet.getSubMetadata(state.getCurrentMetGroup());
            for (String key : inheritedMetadata.getAllKeys()) {
                if (!completeMet.containsKey(key)) {
                    keyToGroupMap.put(key, "__inherited__");
                    completeMet.replaceMetadata(key, inheritedMetadata.getAllMetadata(key));
                }
            }
        }
        List<String> keys = completeMet.getAllKeys();
        Collections.sort(keys);
        for (String key : keys) {
            if (key.endsWith("/envReplace")) {
                continue;
            }
            String values = StringUtils.join(completeMet.getAllMetadata(key), ",");
            Vector<String> row = new Vector<String>();
            row.add(keyToGroupMap.get(key));
            row.add(key);
            row.add(values);
            row.add(Boolean.toString(Boolean.parseBoolean(completeMet.getMetadata(key + "/envReplace"))));
            rows.add(row);
        }
        table = new JTable();// rows, new Vector<String>(Arrays.asList(new
                             // String[] { "key", "values", "envReplace" })));
        table.setModel(new AbstractTableModel() {
            public String getColumnName(int col) {
                switch (col) {
                case 0:
                    return "group";
                case 1:
                    return "key";
                case 2:
                    return "values";
                case 3:
                    return "envReplace";
                default:
                    return null;
                }
            }

            public int getRowCount() {
                return rows.size() + 1;
            }

            public int getColumnCount() {
                return 4;
            }

            public Object getValueAt(int row, int col) {
                if (row >= rows.size()) {
                    return null;
                }
                String value = rows.get(row).get(col);
                if (value == null && col == 3) {
                    return "false";
                }
                if (value == null && col == 0) {
                    return "__local__";
                }
                return value;
            }

            public boolean isCellEditable(int row, int col) {
                if (row >= rows.size()) {
                    return selected.getModel().getStaticMetadata().containsGroup(state.getCurrentMetGroup());
                }
                if (col == 0) {
                    return false;
                }
                String key = rows.get(row).get(1);
                return key == null || (selected.getModel().getStaticMetadata() != null
                        && selected.getModel().getStaticMetadata().containsKey(getKey(key, state)));
            }

            public void setValueAt(Object value, int row, int col) {
                if (row >= rows.size()) {
                    Vector<String> newRow = new Vector<String>(
                            Arrays.asList(new String[] { null, null, null, null }));
                    newRow.add(col, (String) value);
                    rows.add(newRow);
                } else {
                    Vector<String> rowValues = rows.get(row);
                    rowValues.add(col, (String) value);
                    rowValues.remove(col + 1);
                }
                this.fireTableCellUpdated(row, col);
            }

        });
        MyTableListener tableListener = new MyTableListener(state);
        table.getModel().addTableModelListener(tableListener);
        table.getSelectionModel().addListSelectionListener(tableListener);
    } else {
        table = new JTable(new Vector<Vector<String>>(),
                new Vector<String>(Arrays.asList(new String[] { "key", "values", "envReplace" })));
    }

    // table.setFillsViewportHeight(true);
    table.setSelectionBackground(Color.cyan);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    TableCellRenderer cellRenderer = new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel field = new JLabel((String) value);
            if (column == 0) {
                field.setForeground(Color.gray);
            } else {
                if (isSelected) {
                    field.setBorder(new EtchedBorder(1));
                }
                if (table.isCellEditable(row, 1)) {
                    field.setForeground(Color.black);
                } else {
                    field.setForeground(Color.gray);
                }
            }
            return field;
        }

    };
    TableColumn groupCol = table.getColumnModel().getColumn(0);
    groupCol.setPreferredWidth(75);
    groupCol.setCellRenderer(cellRenderer);
    TableColumn keyCol = table.getColumnModel().getColumn(1);
    keyCol.setPreferredWidth(200);
    keyCol.setCellRenderer(cellRenderer);
    TableColumn valuesCol = table.getColumnModel().getColumn(2);
    valuesCol.setPreferredWidth(300);
    valuesCol.setCellRenderer(cellRenderer);
    TableColumn envReplaceCol = table.getColumnModel().getColumn(3);
    envReplaceCol.setPreferredWidth(75);
    envReplaceCol.setCellRenderer(cellRenderer);

    table.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3 && DefaultPropView.this.table.getSelectedRow() != -1) {
                int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
                String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
                Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
                override.setVisible(staticMet == null || !staticMet.containsKey(key));
                delete.setVisible(staticMet != null && staticMet.containsKey(key));
                tableMenu.show(DefaultPropView.this.table, e.getX(), e.getY());
            }
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }
    });

    return table;
}

From source file:org.kchine.rpf.PoolUtils.java

public static Vector<Integer> getRandomOrder(int size) {
    Vector<Integer> randomIndexes = new Vector<Integer>();
    Vector<Integer> availableIndexes = new Vector<Integer>();
    for (int i = 0; i < size; ++i)
        availableIndexes.add(i);/*w  ww.  j  a v a2 s  . com*/
    for (int i = 0; i < size - 1; ++i) {
        int randomIndex = (int) Math.round((availableIndexes.size() - 1) * Math.random());
        randomIndexes.add(availableIndexes.elementAt(randomIndex));
        availableIndexes.remove(randomIndex);
    }
    randomIndexes.add(availableIndexes.elementAt(0));
    return randomIndexes;
}

From source file:org.lockss.util.Logger.java

private void writeMsg(int level, String msg) {
    Iterator iter = targets.iterator();
    while (iter.hasNext()) {
        LogTarget target = (LogTarget) iter.next();
        Vector ts = (Vector) targetStack.get();
        if (!ts.contains(target)) {
            try {
                ts.add(target);/*w  ww  .j ava2s  .  c o m*/
                target.handleMessage(this, level, msg);
            } catch (Exception e) {
                // should log this?
            } finally {
                ts.remove(target);
            }
        }
    }
}

From source file:edu.ku.brc.af.ui.forms.formatters.UIFieldFormatterMgr.java

/**
 * Deletes a formatter from the manager.
 *//*from w w  w  .j  av a 2  s  . c  om*/
public void removeFormatter(final UIFieldFormatterIFace formatter) {
    hash.remove(formatter.getName());

    Vector<UIFieldFormatterIFace> list = classToListHash.get(formatter.getDataClass());
    if (list != null) {
        list.remove(formatter);
        classToListHash.put(formatter.getDataClass(), list);
    }
    hasChanged = true;
}

From source file:edu.ku.brc.specify.utilapps.SetUpBuildDlg.java

/**
 * @return//from   www .  j a  v  a 2 s  .c o  m
 */
@SuppressWarnings("unchecked")
protected Vector<CollectionChoice> loadPersistedChoices() {
    XStream xstream = new XStream();
    CollectionChoice.config(xstream);

    File file = new File(UIRegistry.getDefaultWorkingPath() + File.separator + "bld_coll_choices.xml");
    if (file.exists()) {
        try {
            Vector<CollectionChoice> list = (Vector<CollectionChoice>) xstream
                    .fromXML(FileUtils.readFileToString(file));
            for (CollectionChoice cc : new Vector<CollectionChoice>(list)) {
                try {
                    cc.initialize();

                } catch (Exception ex) {
                    list.remove(cc);
                }
            }
            return list;

        } catch (IOException ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SetUpBuildDlg.class, ex);
            ex.printStackTrace();
        }
    }
    return new Vector<CollectionChoice>();
}

From source file:net.rim.ejde.internal.builders.PreprocessingBuilder.java

/**
 * Preprocess the specified java resource.
 *
 * @param resource//from   w  w w  .ja  v  a2  s .c  om
 * @param symbols
 * @param monitor
 * @throws CoreException
 */
private void preprocessResource(final IResource resource, IProgressMonitor monitor) throws CoreException {
    // remove the old markers and preprocessed file
    removePreprocessingMarkers(resource, IResource.DEPTH_ONE);
    deletePreprocessedFile((IFile) resource, monitor);
    //
    BlackBerryProperties properties = ContextManager.PLUGIN.getBBProperties(getProject().getName(), false);
    if (properties == null) {
        _log.error("Could not find the correspond BlackBerry properties.");
        return;
    }
    // get defined directives
    Vector<String> defines = getDefines(new BlackBerryProject(JavaCore.create(getProject()), properties), true);
    // if there is no directive defined, we do not do preprocessing
    if (defines == null || defines.size() == 0)
        return;
    // check preprocess hook
    if (!SourceMapperAccess.isHookCodeInstalled() && PreprocessorPreferences.getPopForPreprocessHookMissing()) {
        _log.error("Preprocessing hook was not installed."); //$NON-NLS-1$
        ProjectUtils.setPreprocessorHook();
        return;
    } else {
        _log.trace("Preprocessing file : " + resource.getLocation()); //$NON-NLS-1$
    }
    // remove the fake preprocess derive
    defines.remove(Workspace.getDefineOptNull());
    // get java file
    File javaFile = resource.getLocation().toFile();
    Vector<File> javaFiles = new Vector<File>();
    javaFiles.add(javaFile);
    IPreprocessingListenerDelegate listener = new PreprocessingListener(resource);
    IOutputFileCallbackDelegate callback = new OutputFileCallback();
    _javaPP.setPreprocessingListener(listener);
    _javaPP.setOutputFileCallback(callback);
    try {
        _javaPP.preProcess(javaFiles, defines, _preprocessedFolder.getLocation().toFile());
        resource.touch(monitor);
    } catch (IOException e) {
        // Is handled by PreprocessingListener
    } catch (Exception e) {
        try {
            ResourceBuilderUtils.createProblemMarker(resource, IRIMMarker.PREPROCESSING_PROBLEM_MARKER,
                    e.getMessage(), -1, IMarker.SEVERITY_ERROR);
        } catch (CoreException e1) {
            _log.error(e1);
        }
        // if we got any exception, delete the proprocessed file.
        _log.debug(e.getMessage(), e);
        deletePreprocessedFile((IFile) resource, monitor);
    }
    setShouldBuiltByJavaBuilder(resource, javaFiles.size() != 0);
}

From source file:com.xconns.peerdevicenet.core.CoreAPI.java

public void onDeviceDisconnected(Connection conn) {
    Log.d(TAG, "onDeviceDisconnected");
    DeviceInfo peer = conn.getPeerDevice();
    if (peer.addr == null) {
        return;/*from   w  ww. j a v a  2  s . com*/
    }
    mRemoteConnTable.remove(peer.addr);
    // send peer leave msgs for peer groups
    for (String groupId : conn.getPeerGroups()) {
        Log.d(TAG, "onDeviceDisconnected : removefrom group: " + groupId);
        if (groupId != null) {
            Vector<Connection> l = mGroupConnTable.get(groupId);
            if (l != null) {
                Log.d(TAG, "onDeviceDisconnected 2");
                l.remove(conn);
            }
            GroupHandler gh = mLocalGroupTable.get(groupId);
            if (gh != null) {
                gh.onPeerLeave(peer);
            }
        }
    }
    // send disconn msg
    Iterator<ConnHandler> iter = mConnHandlerTable.values().iterator();
    while (iter.hasNext())
        iter.next().onDisconnected(peer);
}

From source file:edu.ku.brc.af.ui.forms.validation.FormValidator.java

/**
 * @param comp/*from   w  ww .  j  av  a 2  s  .  c  o  m*/
 * @param type
 */
public void removeEnabledItem(final Component comp, final EnableType type) {
    Vector<Component> list = enableHash.get(type);
    list.remove(comp);
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.AgentCleanupIndexer.java

/**
 * @param fii// w ww  .  j ava  2s .co  m
 * @return
 */
private int chooseAgentsToMergeNew(final FindItemInfo fii) {
    if (true) {

        MultipleRecordCleanupDlg mrcDlg = null;
        try {
            MultipleRecordComparer mrc = new MultipleRecordComparer(fii, Agent.getClassTableId(),
                    Address.getClassTableId(), AgentVariant.getClassTableId(), AgentSpecialty.getClassTableId(),
                    AgentGeography.getClassTableId());
            mrc.setSingleRowIncluded(false, false, false, false);
            //mrc.addDisplayColumn("Agent's Name");
            mrc.addDisplayColumn("LastName");
            mrc.addDisplayColumn("FirstName");
            mrc.addDisplayColumn("MiddleInitial");

            mrc.loadData();

            mrcDlg = new MultipleRecordCleanupDlg(mrc, "Agent Cleanup");
            mrcDlg.createUI();
            if (!mrcDlg.isSingle()) {
                mrcDlg.pack();
                mrcDlg.setSize(800, 500);
                UIHelper.centerWindow(mrcDlg);
                mrcDlg.toFront();
                if (prgDlg != null)
                    prgDlg.toBack();
                mrcDlg.setVisible(true);
                if (prgDlg != null)
                    prgDlg.toFront();
                //isContinuing = !mrcDlg.isCancelled();
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return mrcDlg.getBtnPressed();
    }
    Vector<ModelItem> items = new Vector<AgentCleanupIndexer.ModelItem>();

    ModelItem primary = createModelItem(fii.getId(), true);
    items.add(primary);
    System.out.println("\nfii: " + fii.getId());

    for (Integer localityId : fii.getDuplicateIds()) {
        items.add(createModelItem(localityId, false));
        System.out.println("  " + localityId);
    }
    Collections.sort(items);
    items.remove(primary);
    items.insertElementAt(primary, 0);

    JTable table = new JTable(new FindItemTableModel(items));
    UIHelper.makeTableHeadersCentered(table, false);
    //UIHelper.setVisibleRowCount(table,  10);
    UIHelper.calcColumnWidths(table, 10, 300);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));
    JScrollPane sp = UIHelper.createScrollPane(table, true);

    pb.add(sp, cc.xy(1, 1));
    pb.setDefaultDialogBorder();

    dlg = new CustomDialog((Frame) getTopWindow(), getResourceString("CLNUP_LOC_CHOOSE_TITLE"), true,
            CustomDialog.OKCANCELAPPLY, pb.getPanel());
    dlg.setOkLabel(getResourceString("CLNUP_MERGE"));
    dlg.setApplyLabel(getResourceString("SKIP"));
    dlg.setCancelLabel(getResourceString("QUIT"));
    dlg.setCloseOnApplyClk(true);
    dlg.createUI();
    dlg.pack();
    UIHelper.centerAndShow(dlg, 800, dlg.getSize().height);

    return dlg.getBtnPressed();
}

From source file:edu.ku.brc.specify.dbsupport.cleanuptools.LocalityCleanupIndexer.java

/**
 * @param fii//from w  ww . ja  v  a 2  s. c  o  m
 * @return
 */
private int chooseLocalitiesToMerge(final FindItemInfo fii) {
    if (true) {

        MultipleRecordCleanupDlg mrcDlg = null;
        try {
            MultipleRecordComparer mrc = new MultipleRecordComparer(fii, Locality.getClassTableId(),
                    LocalityDetail.getClassTableId(), GeoCoordDetail.getClassTableId());
            mrc.setSingleRowIncluded(true, true);
            //mrc.addDisplayColumn("FullName", "Full Name", "CONCAT(LocalityName, '-') AS FullName");
            mrc.addDisplayColumn("LocalityName");

            mrc.loadData();

            mrcDlg = new MultipleRecordCleanupDlg(mrc, "Locality Cleanup");
            mrcDlg.createUI();
            if (!mrcDlg.isSingle()) {
                mrcDlg.pack();
                mrcDlg.setSize(800, 500);
                UIHelper.centerWindow(mrcDlg);
                mrcDlg.toFront();
                if (prgDlg != null)
                    prgDlg.toBack();
                mrcDlg.setVisible(true);
                if (prgDlg != null)
                    prgDlg.toFront();
                //isContinuing = !mrcDlg.isCancelled();
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return mrcDlg.getBtnPressed();
    }
    Vector<ModelItem> items = new Vector<LocalityCleanupIndexer.ModelItem>();

    ModelItem primary = createModelItem(fii.getId(), true);
    items.add(primary);
    System.out.println("\nfii: " + fii.getId());

    for (Integer localityId : fii.getDuplicateIds()) {
        items.add(createModelItem(localityId, false));
        System.out.println("  " + localityId);
    }
    Collections.sort(items);
    items.remove(primary);
    items.insertElementAt(primary, 0);

    JTable table = new JTable(new FindItemTableModel(items));
    UIHelper.makeTableHeadersCentered(table, false);
    //UIHelper.setVisibleRowCount(table,  10);
    UIHelper.calcColumnWidths(table, 10, 300);

    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));
    JScrollPane sp = UIHelper.createScrollPane(table, true);

    pb.add(sp, cc.xy(1, 1));
    pb.setDefaultDialogBorder();

    dlg = new CustomDialog((Frame) getTopWindow(), getResourceString("CLNUP_LOC_CHOOSE_TITLE"), true,
            CustomDialog.OKCANCELAPPLY, pb.getPanel());
    dlg.setOkLabel(getResourceString("CLNUP_MERGE"));
    dlg.setApplyLabel(getResourceString("SKIP"));
    dlg.setCancelLabel(getResourceString("QUIT"));
    dlg.setCloseOnApplyClk(true);
    dlg.createUI();
    dlg.pack();
    UIHelper.centerAndShow(dlg, 800, dlg.getSize().height);

    return dlg.getBtnPressed();
}