Example usage for java.util Set iterator

List of usage examples for java.util Set iterator

Introduction

In this page you can find the example usage for java.util Set iterator.

Prototype

Iterator<E> iterator();

Source Link

Document

Returns an iterator over the elements in this set.

Usage

From source file:net.bioclipse.chart.ChartUtils.java

public static void handleCellChangeEvent(CellChangedEvent e) {
    //      Iterator<CellChangeListener> iterator = listeners.iterator();
    //      while( iterator.hasNext() )
    //      {//from   ww  w. j a  va 2 s .co m
    //         CellChangeListener listener = iterator.next();
    //         listener.handleCellChangeEvent(e);
    //      }
    Set<JFreeChart> keySet = chartManager.keySet();
    Iterator<JFreeChart> iterator = keySet.iterator();
    while (iterator.hasNext()) {
        JFreeChart chart = iterator.next();

        ChartDescriptor desc = chartManager.get(chart);

        String domainLabel = desc.getXLabel();
        String rangeLabel = desc.getYLabel();
        CellData data = e.getCellData();

        if (domainLabel.equals(data.getColName()) || rangeLabel.equals(data.getColName())) {
            DefaultXYDataset dataset = (DefaultXYDataset) chart.getXYPlot().getDataset();
            int itemCount = dataset.getItemCount(0);
            double[] yValues = new double[itemCount];
            double[] xValues = new double[itemCount];
            for (int i = 0; i < itemCount; i++) {
                double x = dataset.getXValue(0, i);
                double y = dataset.getYValue(0, i);
                xValues[i] = x;
                yValues[i] = y;
            }
            int indices[] = desc.getSourceIndices();
            if (domainLabel.equals(e.getCellData().getColName())) {
                int rowIndex = data.getRowIndex();
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] == rowIndex) {
                        xValues[i] = data.getValue();
                    }
                }
            } else if (rangeLabel.equals(e.getCellData().getColName())) {
                int rowIndex = data.getRowIndex();
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] == rowIndex) {
                        yValues[i] = data.getValue();
                    }
                }
            }
            double[][] chartData = new double[2][];
            chartData[0] = xValues;
            chartData[1] = yValues;

            dataset.getSeriesKey(0);
            Comparable seriesKey = dataset.getSeriesKey(0);

            dataset.removeSeries(seriesKey);
            dataset.addSeries(seriesKey, chartData);
        }
    }
}

From source file:com.aurel.track.item.ItemActionJSON.java

public static String encodeFieldDisplayValues(Set<Integer> presentFields, WorkItemContext workItemContext,
        boolean useProjectSpecificID, boolean isMobileApplication) {
    StringBuilder sb = new StringBuilder();
    sb.append("{");

    for (Iterator<Integer> iterator = presentFields.iterator(); iterator.hasNext();) {
        Integer fieldID = iterator.next();
        IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID);

        Object value = workItemContext.getWorkItemBean().getAttribute(fieldID);
        String displayValue = null;

        if (useProjectSpecificID && fieldID.intValue() == SystemFields.ISSUENO) {
            displayValue = ItemBL.getSpecificProjectID(workItemContext);
        } else {/*  www .ja  va 2s.com*/
            if (fieldTypeRT != null) {
                displayValue = fieldTypeRT.getShowValue(value, workItemContext, fieldID);
            }
        }
        if (fieldID == SystemFields.DESCRIPTION) {
            displayValue = ItemDetailBL.formatDescription(displayValue, workItemContext.getLocale());
        }
        if (isMobileApplication) {
            try {
                if (fieldTypeRT.getValueType() == ValueType.LONGTEXT) {
                    displayValue = Html2Text.getNewInstance().convert(displayValue);
                    displayValue = displayValue.replaceAll("[\n\r]", "");
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                LOGGER.error(ExceptionUtils.getStackTrace(e));
            }
        }
        //append "," after each value. we need to remove the last one
        JSONUtility.appendStringValue(sb, "f" + fieldID, displayValue);
    }
    if (sb.length() > 1) {
        //remove last ","
        sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("}");
    return sb.toString();
}

From source file:edu.uci.ics.jung.utils.GraphUtils.java

/**
 * Adds all edges in the specified set to <code>g</code>. Syntactic
 * sugar for a loop that calls <code>g.addEdge</code> on all elements
 * of the set.//from  ww w . java 2 s  . c o  m
 * If any element of <code>edges</code> may not be legally added
 * to this graph, throws an exception: <code>ClassCastException</code> if
 * the type is inappropriate, and <code>IllegalArgumentException</code>  
 * otherwise.  If an exception is thrown, any edges that may 
 * already have been added are not guaranteed to be retained.
 */
public static void addEdges(Graph g, Set edges) {
    for (Iterator iter = edges.iterator(); iter.hasNext();)
        g.addEdge((Edge) iter.next());
}

From source file:edu.uci.ics.jung.utils.GraphUtils.java

/**
 * Adds all edges in the specified set to <code>g</code>. Syntactic
 * sugar for a loop that calls <code>g.addEdge</code> on all elements
 * of the set.//from   ww  w  . j  a  v a2 s .  c o m
 * If any element of <code>edges</code> may not be legally added
 * to this graph, throws an exception: <code>ClassCastException</code> if
 * the type is inappropriate, and <code>IllegalArgumentException</code>  
 * otherwise.  If an exception is thrown, any edges that may 
 * already have been added are not guaranteed to be retained.
 */
public static void addEdges(Hypergraph g, Set edges) {
    for (Iterator iter = edges.iterator(); iter.hasNext();)
        g.addEdge((Hyperedge) iter.next());
}

From source file:cn.usually.common.pay.union.sdk.SDKUtil.java

/**
 * HTML?,?form?(??)/*from  w  w  w.j  a v  a2 s.  c om*/
 * 
 * @param url
 * @param data
 * @return
 */
public static String createAutoSubmitForm(String url, Map<String, String> data) {
    StringBuffer sf = new StringBuffer();
    sf.append("<form id = \"sform\" action=\"" + url + "\" method=\"post\">");
    if (null != data && 0 != data.size()) {
        Set<Entry<String, String>> set = data.entrySet();
        Iterator<Entry<String, String>> it = set.iterator();
        while (it.hasNext()) {
            Entry<String, String> ey = it.next();
            String key = ey.getKey();
            String value = ey.getValue();
            sf.append(
                    "<input type=\"hidden\" name=\"" + key + "\" id=\"" + key + "\" value=\"" + value + "\"/>");
        }
    }
    sf.append("</form>");
    sf.append("</body>");
    sf.append("<script type=\"text/javascript\">");
    sf.append("document.getElementById(\"sform\").submit();\n");
    sf.append("</script>");
    return sf.toString();
}

From source file:edu.uci.ics.jung.utils.GraphUtils.java

/**
 * Adds all vertices in the specified set to <code>g</code>. Syntactic
 * sugar for a loop that calls <code>g.addVertex</code> on all elements
 * of the set.//from w ww .j av  a 2s  . co  m
 * If any element of <code>vertices</code> may not be legally added
 * to this graph, throws an exception: <code>ClassCastException</code> if
 * the type is inappropriate, and <code>IllegalArgumentException</code>  
 * otherwise.  If an exception is thrown, any vertices that may 
 * already have been added are not guaranteed to be retained.
 */
public static void addVertices(Graph g, Set vertices) {
    for (Iterator iter = vertices.iterator(); iter.hasNext();)
        g.addVertex((Vertex) iter.next());
}

From source file:edu.uci.ics.jung.utils.GraphUtils.java

/**
 * Adds all vertices in the specified set to <code>g</code>. Syntactic
 * sugar for a loop that calls <code>g.addVertex</code> on all elements
 * of the set.//from  w  ww.  j  a  va 2s .co  m
 * If any element of <code>vertices</code> may not be legally added
 * to this graph, throws an exception: <code>ClassCastException</code> if
 * the type is inappropriate, and <code>IllegalArgumentException</code>  
 * otherwise.  If an exception is thrown, any vertices that may 
 * already have been added are not guaranteed to be retained.
 */
public static void addVertices(Hypergraph g, Set vertices) {
    for (Iterator iter = vertices.iterator(); iter.hasNext();)
        g.addVertex((Hypervertex) iter.next());
}

From source file:com.aurel.track.item.ItemActionJSON.java

public static String encodeFieldValues(Set<Integer> presentFields, WorkItemContext workItemContext,
        boolean useProjectSpecificID, boolean isMobileApplication) {
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    for (Iterator<Integer> iterator = presentFields.iterator(); iterator.hasNext();) {
        Integer fieldID = iterator.next();
        Object value = workItemContext.getWorkItemBean().getAttribute(fieldID);
        String jsonValue = null;/*  w  w  w  .  j a  v  a 2 s.  c  o  m*/
        if (useProjectSpecificID && fieldID.intValue() == SystemFields.ISSUENO) {
            jsonValue = "\"" + ItemBL.getSpecificProjectID(workItemContext) + "\"";
        } else {
            FieldType fieldType = FieldTypeManager.getInstance().getType(fieldID);
            fieldType.setFieldID(fieldID);
            //set
            if (fieldType != null) {
                TypeRendererRT fieldTypeRendererRT = fieldType.getRendererRT();
                int valueType = fieldType.getFieldTypeRT().getValueType();
                switch (valueType) {
                case ValueType.DATE:
                    jsonValue = "\"" + DateTimeUtils.getInstance().formatGUIDate((Date) value,
                            workItemContext.getLocale()) + "\"";
                    break;
                case ValueType.LONGTEXT:
                    if (value != null) {
                        List<MacroDef> macroDefList = MacroBL.parseMacros(value.toString(),
                                MacroManager.MACRO_ISSUE);
                        if (macroDefList != null) {
                            IMacro macro = new MacroIssueDecorate();
                            MacroContext macroContext = new MacroContext();
                            macroContext.setUseProjectSpecificID(useProjectSpecificID);
                            value = MacroBL.replaceMacros(macroDefList, value.toString(), macroContext, macro);
                        }
                    }

                    jsonValue = value == null ? null : "\"" + JSONUtility.escape(value.toString()) + "\"";
                    //
                    break;
                default:
                    jsonValue = fieldTypeRendererRT.encodeJsonValue(value);
                    break;
                }
            }
        }

        //append "," after each value. we need to remove the last one
        JSONUtility.appendJSONValue(sb, "f" + fieldID, jsonValue);
    }
    if (sb.length() > 1) {
        //remove last ","
        sb.deleteCharAt(sb.length() - 1);
    }

    sb.append("}");
    return sb.toString();
}

From source file:com.ace.erp.common.inject.support.InjectBaseDependencyHelper.java

public static void findAndInjectGenericServiceDependency(BaseController<?, ?> baseController) {
    final Set<Object> candidates = findDependencies(baseController, BaseComponent.class);

    if (candidates.size() > 1) {
        throw new IllegalStateException(
                "expect 1 @BaseComponent anntation AbstractService subclass bean, but found "
                        + candidates.size() + ", please check class [" + baseController.getClass()
                        + "] @BaseComponent annotation.");
    }/*w ww. j  a  v  a  2s.co  m*/

    Object genericService = candidates.iterator().next();

    if (genericService.getClass().isAssignableFrom(BaseComponent.class)) {
        throw new IllegalStateException("[" + baseController.getClass() + "] @BaseComponent annotation bean "
                + "must be AbstractService subclass");
    }

    baseController.setGenericService((GenericService) genericService);
}

From source file:com.discovery.darchrow.lang.ObjectUtil.java

/**
 * ?/*from   w w  w. j  a  va2 s  .  c  o  m*/
 * <ul>
 * <li>?</li>
 * <li></li>
 * <li>{@link java.util.Map},key ?{@link java.util.Iterator}</li>
 * <li>{@link java.util.Collection}</li>
 * <li>{@link java.util.Iterator}</li>
 * <li>{@link java.util.Enumeration}</li>
 * </ul>
 * ?Iterator.
 *
 * @param <T>
 *            the generic type
 * @param object
 *            <ul>
 *            <li>?</li>
 *            <li></li>
 *            <li>map,key ?Iterator</li>
 *            <li>Collection</li>
 *            <li>Iterator</li>
 *            <li>Enumeration</li>
 *            </ul>
 * @return <ul>
 *         <li> null == object null,</li>
 *         <li>??Iterator</li>
 *         </ul>
 * @see ArrayUtil#toIterator(Object)
 * @see Collection#iterator()
 * @see Iterator
 * @see Map#keySet()
 * @see Set#iterator()
 * @see org.apache.commons.collections.iterators.EnumerationIterator#EnumerationIterator(Enumeration)
 * @since Commons Collections 1.0
 */
@SuppressWarnings("unchecked")
public static final <T> Iterator<T> toIterator(Object object) {
    if (null == object) {
        return null;
    }
    // object ?
    // 
    if (object.getClass().isArray()) {
        return ArrayUtil.toIterator(object);
    }
    // Collection
    else if (object instanceof Collection) {
        return ((Collection<T>) object).iterator();
    }
    // Iterator
    else if (object instanceof Iterator) {
        return (Iterator<T>) object;
    }
    // Enumeration
    else if (object instanceof Enumeration) {
        Enumeration<T> enumeration = (Enumeration<T>) object;
        EnumerationIterator enumerationIterator = new EnumerationIterator(enumeration);
        return enumerationIterator;
    }
    // map
    else if (object instanceof Map) {
        Set<T> keySet = ((Map<T, ?>) object).keySet();
        return keySet.iterator();
    }
    // ?
    else if (object instanceof String) {
        String[] strings = object.toString().split(",");
        return ArrayUtil.toIterator(strings);
    } else {
        throw new IllegalArgumentException("param object:[" + object + "] don't support convert to Iterator.");
    }
}