List of usage examples for java.util LinkedHashSet clone
@HotSpotIntrinsicCandidate protected native Object clone() throws CloneNotSupportedException;
From source file:com.google.gwt.emultest.java.util.LinkedHashSetTest.java
@SuppressWarnings("unchecked") public void testClone() { LinkedHashSet<String> srcSet = new LinkedHashSet<String>(); checkEmptyLinkedHashSetAssumptions(srcSet); // Check empty clone behavior LinkedHashSet<String> dstSet = (LinkedHashSet<String>) srcSet.clone(); assertNotNull(dstSet);//from w w w.j a v a 2 s .c o m assertEquals(dstSet.size(), srcSet.size()); assertEquals(dstSet.toArray(), srcSet.toArray()); // Check non-empty clone behavior srcSet.add(VALUE_1); srcSet.add(VALUE_2); srcSet.add(VALUE_3); srcSet.add(VALUE_4); dstSet = (LinkedHashSet<String>) srcSet.clone(); assertNotNull(dstSet); assertEquals(dstSet.size(), srcSet.size()); assertEquals(dstSet.toArray(), srcSet.toArray()); }
From source file:org.pentaho.reporting.platform.plugin.ParameterXmlContentHandler.java
private Element createParameterElement(final ParameterDefinitionEntry parameter, final ParameterContext parameterContext, final Object selections) throws BeanException, ReportDataFactoryException { try {/*from w ww .j a v a2s . c o m*/ final Element parameterElement = document.createElement("parameter"); //$NON-NLS-1$ parameterElement.setAttribute("name", parameter.getName()); //$NON-NLS-1$ final Class<?> valueType = parameter.getValueType(); parameterElement.setAttribute("type", valueType.getName()); //$NON-NLS-1$ parameterElement.setAttribute("is-mandatory", String.valueOf(parameter.isMandatory())); //$NON-NLS-1$ //$NON-NLS-2$ final String[] namespaces = parameter.getParameterAttributeNamespaces(); for (int i = 0; i < namespaces.length; i++) { final String namespace = namespaces[i]; final String[] attributeNames = parameter.getParameterAttributeNames(namespace); for (final String attributeName : attributeNames) { final String attributeValue = parameter.getParameterAttribute(namespace, attributeName, parameterContext); // expecting: label, parameter-render-type, parameter-layout // but others possible as well, so we set them all final Element attributeElement = document.createElement("attribute"); // NON-NLS attributeElement.setAttribute("namespace", namespace); // NON-NLS attributeElement.setAttribute("name", attributeName); // NON-NLS attributeElement.setAttribute("value", attributeValue); // NON-NLS parameterElement.appendChild(attributeElement); } } final Class<?> elementValueType; if (valueType.isArray()) { elementValueType = valueType.getComponentType(); } else { elementValueType = valueType; } if (Date.class.isAssignableFrom(elementValueType)) { parameterElement.setAttribute("timzone-hint", computeTimeZoneHint(parameter, parameterContext));//$NON-NLS-1$ } final LinkedHashSet<Object> selectionSet = new LinkedHashSet<Object>(); if (selections != null) { if (selections.getClass().isArray()) { final int length = Array.getLength(selections); for (int i = 0; i < length; i++) { final Object value = Array.get(selections, i); selectionSet.add(resolveSelectionValue(value)); } } else { selectionSet.add(resolveSelectionValue(selections)); } } else { final String type = parameter.getParameterAttribute(ParameterAttributeNames.Core.NAMESPACE, ParameterAttributeNames.Core.TYPE, parameterContext); if (ParameterAttributeNames.Core.TYPE_DATEPICKER.equals(type) && Date.class.isAssignableFrom(valueType)) { if (isGenerateDefaultDates()) { selectionSet.add(new Date()); } } } @SuppressWarnings("rawtypes") final LinkedHashSet handledValues = (LinkedHashSet) selectionSet.clone(); if (parameter instanceof ListParameter) { final ListParameter asListParam = (ListParameter) parameter; parameterElement.setAttribute("is-multi-select", //$NON-NLS-1$ String.valueOf(asListParam.isAllowMultiSelection())); //$NON-NLS-2$ parameterElement.setAttribute("is-strict", String.valueOf(asListParam.isStrictValueCheck())); //$NON-NLS-1$ //$NON-NLS-2$ parameterElement.setAttribute("is-list", "true"); //$NON-NLS-1$ //$NON-NLS-2$ final Element valuesElement = document.createElement("values"); //$NON-NLS-1$ parameterElement.appendChild(valuesElement); final ParameterValues possibleValues = asListParam.getValues(parameterContext); for (int i = 0; i < possibleValues.getRowCount(); i++) { final Object key = possibleValues.getKeyValue(i); final Object value = possibleValues.getTextValue(i); final Element valueElement = document.createElement("value"); //$NON-NLS-1$ valuesElement.appendChild(valueElement); valueElement.setAttribute("label", String.valueOf(value)); //$NON-NLS-1$ //$NON-NLS-2$ valueElement.setAttribute("type", elementValueType.getName()); //$NON-NLS-1$ if (key instanceof Number) { final BigDecimal bd = new BigDecimal(String.valueOf(key)); valueElement.setAttribute("selected", String.valueOf(selectionSet.contains(bd)));//$NON-NLS-1$ handledValues.remove(bd); } else if (key == null) { if (selections == null || selectionSet.contains(null)) { valueElement.setAttribute("selected", "true");//$NON-NLS-1$ handledValues.remove(null); } } else { valueElement.setAttribute("selected", String.valueOf(selectionSet.contains(key)));//$NON-NLS-1$ handledValues.remove(key); } if (key == null) { valueElement.setAttribute("null", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } else { valueElement.setAttribute("null", "false"); //$NON-NLS-1$ //$NON-NLS-2$ valueElement.setAttribute("value", convertParameterValueToString(parameter, parameterContext, key, elementValueType)); //$NON-NLS-1$ //$NON-NLS-2$ } } // Only add invalid values to the selection list for non-strict parameters if (!asListParam.isStrictValueCheck()) { for (final Object key : handledValues) { final Element valueElement = document.createElement("value"); //$NON-NLS-1$ valuesElement.appendChild(valueElement); valueElement.setAttribute("label", Messages.getInstance() //$NON-NLS-1$ .getString("ReportPlugin.autoParameter", String.valueOf(key))); //$NON-NLS-1$ valueElement.setAttribute("type", elementValueType.getName()); //$NON-NLS-1$ if (key instanceof Number) { BigDecimal bd = new BigDecimal(String.valueOf(key)); valueElement.setAttribute("selected", String.valueOf(selectionSet.contains(bd)));//$NON-NLS-1$ } else { valueElement.setAttribute("selected", String.valueOf(selectionSet.contains(key)));//$NON-NLS-1$ } if (key == null) { valueElement.setAttribute("null", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } else { valueElement.setAttribute("null", "false"); //$NON-NLS-1$ //$NON-NLS-2$ valueElement.setAttribute("value", convertParameterValueToString(parameter, parameterContext, key, elementValueType)); //$NON-NLS-1$ //$NON-NLS-2$ } } } } else if (parameter instanceof PlainParameter) { // apply defaults, this is the easy case parameterElement.setAttribute("is-multi-select", "false"); //$NON-NLS-1$ //$NON-NLS-2$ parameterElement.setAttribute("is-strict", "false"); //$NON-NLS-1$ //$NON-NLS-2$ parameterElement.setAttribute("is-list", "false"); //$NON-NLS-1$ //$NON-NLS-2$ if (selections != null) { final Element valuesElement = document.createElement("values"); //$NON-NLS-1$ parameterElement.appendChild(valuesElement); final Element valueElement = document.createElement("value"); //$NON-NLS-1$ valuesElement.appendChild(valueElement); valueElement.setAttribute("type", valueType.getName()); //$NON-NLS-1$ valueElement.setAttribute("selected", "true");//$NON-NLS-1$ valueElement.setAttribute("null", "false"); //$NON-NLS-1$ //$NON-NLS-2$ final String value = convertParameterValueToString(parameter, parameterContext, selections, valueType); valueElement.setAttribute("value", value); //$NON-NLS-1$ //$NON-NLS-2$ valueElement.setAttribute("label", value); //$NON-NLS-1$ //$NON-NLS-2$ } } return parameterElement; } catch (BeanException be) { logger.error(Messages.getInstance().getString("ReportPlugin.errorFailedToGenerateParameter", parameter.getName(), String.valueOf(selections)), be); throw be; } }