List of usage examples for java.util LinkedHashSet contains
boolean contains(Object o);
From source file:org.dozer.MappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<Object>(); LinkedHashSet<Object> result = new LinkedHashSet<Object>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }/*from w w w. j a v a2 s.c om*/ Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<Object>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, null); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped from the src collection // so we'll clear result and replace all entries with the ones in mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:com.github.dozermapper.core.MappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<>(); LinkedHashSet<Object> result = new LinkedHashSet<>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }/*from w w w . j ava 2 s . co m*/ Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped from the src collection // so we'll clear result and replace all entries with the ones in mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:org.pshdl.model.simulation.codegenerator.CCodeGenerator.java
private String generateSimEncapsuation(final Unit unit, final Iterable<Row> rows) { final Set<String> varNames = new LinkedHashSet<String>(); final Procedure1<Row> _function = new Procedure1<Row>() { public void apply(final Row it) { List<Definition> _allDefs = CCodeGenerator.this.ba.allDefs(it); final Function1<Definition, Boolean> _function = new Function1<Definition, Boolean>() { public Boolean apply(final Definition it) { return Boolean.valueOf((it.type != Definition.Type.UNUSED)); }//from w ww. j ava 2 s. c om }; Iterable<Definition> _filter = IterableExtensions.<Definition>filter(_allDefs, _function); final Procedure1<Definition> _function_1 = new Procedure1<Definition>() { public void apply(final Definition it) { String _name = it.getName(); varNames.add(_name); } }; IterableExtensions.<Definition>forEach(_filter, _function_1); } }; IterableExtensions.<Row>forEach(rows, _function); StringConcatenation _builder = new StringConcatenation(); _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* @file"); _builder.newLine(); _builder.append(" "); _builder.append("* @brief Provides methods for simulating accessing to the memory registers"); _builder.newLine(); _builder.append(" "); _builder.append("*"); _builder.newLine(); _builder.append(" "); _builder.append("* This file is a substitue for the BusAccess.c file that is used to access real memory."); _builder.newLine(); _builder.append(" "); _builder.append("* For each type of row there are methods for setting/getting the values"); _builder.newLine(); _builder.append(" "); _builder.append("* either directly, or as a struct. A memory map overview has been"); _builder.newLine(); _builder.append(" "); _builder.append("* generated into BusMap.html."); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.newLine(); _builder.append("#include <stdint.h>"); _builder.newLine(); _builder.append("#include <stdbool.h>"); _builder.newLine(); _builder.append("#include \"BusAccess.h\""); _builder.newLine(); _builder.append("#include \"BusStdDefinitions.h\""); _builder.newLine(); _builder.append("#include \""); String _headerName = this.headerName(); _builder.append(_headerName, ""); _builder.append(".h\""); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* This method provides a null implementation of the warning functionality. You"); _builder.newLine(); _builder.append(" "); _builder.append("* can use it to provide your own error handling, or you can use the implementation"); _builder.newLine(); _builder.append(" "); _builder.append("* provided in BusPrint.h"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append( "static void defaultWarn(warningType_t t, uint64_t value, char *def, char *row, char *msg){"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("warnFunc_p warn=defaultWarn;"); _builder.newLine(); _builder.newLine(); _builder.append("/**"); _builder.newLine(); _builder.append(" "); _builder.append("* This methods allows the user to set a custom warning function. Usually this is used"); _builder.newLine(); _builder.append(" "); _builder.append("* in conjunction with the implementation provided in BusPrint.h."); _builder.newLine(); _builder.append(" "); _builder.append("*"); _builder.newLine(); _builder.append(" "); _builder.append("* @param warnFunction the new function to use for error reporting"); _builder.newLine(); _builder.append(" "); _builder.append("*"); _builder.newLine(); _builder.append(" "); _builder.append("* Example Usage:"); _builder.newLine(); _builder.append(" "); _builder.append("* @code"); _builder.newLine(); _builder.append(" "); _builder.append("* #include \"BusPrint.h\""); _builder.newLine(); _builder.append(" "); _builder.append("* setWarn(defaultPrintfWarn);"); _builder.newLine(); _builder.append(" "); _builder.append("* @endcode"); _builder.newLine(); _builder.append(" "); _builder.append("*/"); _builder.newLine(); _builder.append("void setWarn(warnFunc_p warnFunction){"); _builder.newLine(); _builder.append(" "); _builder.append("warn=warnFunction;"); _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append("///The index of the Clock that is toggled for each setting"); _builder.newLine(); _builder.append("#define "); _builder.append("busclk_idx", ""); _builder.append(" "); int _busIndex = this.getBusIndex(); _builder.append(_busIndex, ""); _builder.newLineIfNotEmpty(); _builder.newLine(); String res = _builder.toString(); final LinkedHashSet<String> checkedRows = new LinkedHashSet<String>(); final LinkedHashMap<String, Integer> rowCounts = new LinkedHashMap<String, Integer>(); for (final Row row : rows) { { final Integer idx = rowCounts.get(row.name); boolean _tripleEquals = (idx == null); if (_tripleEquals) { rowCounts.put(row.name, Integer.valueOf(1)); } else { rowCounts.put(row.name, Integer.valueOf(((idx).intValue() + 1))); } } } for (final Row row_1 : rows) { boolean _contains = checkedRows.contains(row_1.name); boolean _not = (!_contains); if (_not) { boolean _hasWriteDefs = this.ba.hasWriteDefs(row_1); if (_hasWriteDefs) { Integer _get = rowCounts.get(row_1.name); CharSequence _simSetter = this.simSetter(row_1, (_get).intValue()); String _plus = (res + _simSetter); res = _plus; } Integer _get_1 = rowCounts.get(row_1.name); CharSequence _simGetter = this.simGetter(row_1, (_get_1).intValue()); String _plus_1 = (res + _simGetter); res = _plus_1; checkedRows.add(row_1.name); } } return res; }
From source file:restaurant.dozer.custom.mapper.CustomMappingProcessor.java
private Set<?> addToSet(Object srcObj, FieldMap fieldMap, Collection<?> srcCollectionValue, Object destObj) { // create a list here so we can keep track of which elements we have // mapped, and remove all others if removeOrphans = true Set<Object> mappedElements = new HashSet<Object>(); LinkedHashSet<Object> result = new LinkedHashSet<Object>(); // don't want to create the set if it already exists. Object field = fieldMap.getDestValue(destObj); if (field != null) { result.addAll((Collection<?>) field); }//from w w w .j av a2 s .co m Object destValue; Class<?> destEntryType = null; Class<?> prevDestEntryType = null; for (Object srcValue : srcCollectionValue) { if (destEntryType == null || (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().hasMoreThanOneHint())) { destEntryType = determineCollectionItemType(fieldMap, destObj, srcValue, prevDestEntryType); } CopyByReferenceContainer copyByReferences = globalConfiguration.getCopyByReferences(); if (srcValue != null && copyByReferences.contains(srcValue.getClass())) { destValue = srcValue; } else { destValue = mapOrRecurseObject(srcObj, srcValue, destEntryType, fieldMap, destObj); } prevDestEntryType = destEntryType; if (RelationshipType.NON_CUMULATIVE.equals(fieldMap.getRelationshipType()) && result.contains(destValue)) { List<Object> resultAsList = new ArrayList<Object>(result); int index = resultAsList.indexOf(destValue); // perform an update if complex type - can't map strings Object obj = resultAsList.get(index); // make sure it is not a String if (!obj.getClass().isAssignableFrom(String.class)) { mapToDestObject(null, srcValue, obj, false, fieldMap.getMapId()); mappedElements.add(obj); } } else { if (destValue != null || fieldMap.isDestMapNull()) { result.add(destValue); } mappedElements.add(destValue); } } // If remove orphans - we only want to keep the objects we've mapped // from the src collection // so we'll clear result and replace all entries with the ones in // mappedElements if (fieldMap.isRemoveOrphans()) { result.clear(); result.addAll(mappedElements); } if (field == null) { Class<? extends Set<?>> destSetType = (Class<? extends Set<?>>) fieldMap .getDestFieldType(destObj.getClass()); return CollectionUtils.createNewSet(destSetType, result); } else { // Bug #1822421 - Clear first so we don't end up with the removed // orphans again ((Set) field).clear(); ((Set) field).addAll(result); return (Set<?>) field; } }
From source file:annis.visualizers.iframe.partitur.PartiturVisualizer.java
@Override public void writeOutput(VisualizerInput input, Writer writer) { try {//from w ww .java 2 s . c o m nodes = input.getResult().getGraph().getNodes(); token = input.getResult().getGraph().getTokens(); // get partitur PartiturParser partitur = new PartiturParser(input.getResult().getGraph(), input.getNamespace()); // check right to left boolean isRTL = checkRTL(input.getResult().getTokenList()); List<String> tierNames = new LinkedList<String>(partitur.getKnownTiers()); Collections.sort(tierNames); // get keys that are allowed to select LinkedHashSet<String> keys = new LinkedHashSet<String>(); String mapping = input.getMappings().getProperty("annos"); if (mapping == null) { // default to the alphabetical order keys.addAll(partitur.getNameslist()); } else { String[] splitted = mapping.split(","); for (int k = 0; k < splitted.length; k++) { String s = splitted[k].trim(); if (partitur.getNameslist().contains(s)) { keys.add(s); } } } writer.append( "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"); writer.append("<link href=\"" + input.getResourcePath("jbar.css") + "\" rel=\"stylesheet\" type=\"text/css\" >"); writer.append("<link href=\"" + input.getResourcePath("jquery.tooltip.css") + "\" rel=\"stylesheet\" type=\"text/css\" >"); writer.append("<link href=\"" + input.getResourcePath("jquery.noty.css") + "\" rel=\"stylesheet\" type=\"text/css\" >"); writer.append("<link href=\"" + input.getResourcePath("partitur.css") + "\" rel=\"stylesheet\" type=\"text/css\" >"); writer.append("<script src=\"" + input.getResourcePath("jquery-1.7.1.min.js") + "\"></script>"); writer.append("<script src=\"" + input.getResourcePath("jquery.jbar.js") + "\"></script>"); writer.append("<script src=\"" + input.getResourcePath("jquery.tooltip.min.js") + "\"></script>"); writer.append("<script src=\"" + input.getResourcePath("jquery.noty.js") + "\"></script>"); writer.append("<script>"); writer.append(convertToJavacSriptArray(new LinkedList<String>())); writer.append("\nvar levelNames = ["); int i = 0; for (String levelName : tierNames) { if (keys.contains(levelName)) { writer.append((i++ > 0 ? ", " : "") + "\"" + levelName + "\""); } } writer.append("];\n</script>"); writer.append("<script type=\"text/javascript\" src=\"" + input.getResourcePath("PartiturVisualizer.js") + "\"></script>"); writer.append("</head>"); writer.append("<body>\n"); writer.append("<ul id=\"toolbar\"></ul>"); writer.append("<div id=\"partiture\">"); if (isRTL) { writer.append("<table class=\"partitur_table\" dir=\"rtl\">\n"); } else { writer.append("<table class=\"partitur_table\")\">\n"); } for (String tier : keys) { List<String> indexlist = new ArrayList<String>(); for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) { for (PartiturParser.ResultElement strr : span) { if (strr.getName().equals(tier) && !indexlist.contains(strr.getId())) { indexlist.add(strr.getId()); } } } String[] currentarray; //Saves annotation-ids of the current row while (!indexlist.isEmpty()) { //Create Rows until all Annotations fit in List<String> currentdontuselist = new LinkedList<String>(); //Lists all Annotations that should not be added to the current row writer.append("<tr class=\"level_" + tier + "\"><th>" + tier + "</th>"); //new row currentarray = new String[partitur.getResultlist().size()]; for (int iterator3 = 0; iterator3 < partitur.getResultlist().size(); iterator3++) { currentarray[iterator3] = null; } int spanCounter = 0; for (List<PartiturParser.ResultElement> span : partitur.getResultlist()) { //for each Token for (PartiturParser.ResultElement annotationelement : span) { // for each Annotation annotationelement of that Token if (indexlist.contains(annotationelement.getId()) && !currentdontuselist.contains(annotationelement.getId())) { boolean neu = false; //Should the Annotation be added? if (currentarray[spanCounter] == null) { indexlist.remove(annotationelement.getId()); currentarray[spanCounter] = annotationelement.getId(); neu = true; } //get all other annotationelement.id (earlier Ids => dontuselist) int span2Counter = 0; for (List<PartiturParser.ResultElement> span2 : partitur.getResultlist()) { for (PartiturParser.ResultElement strr2 : span2) { if (strr2.getId().equals(annotationelement.getId()) && neu) //{ { if (currentarray[span2Counter] == null) { currentarray[span2Counter] = annotationelement.getId(); } } if (span2Counter <= spanCounter && !currentdontuselist.contains(strr2.getId())) { currentdontuselist.add(strr2.getId()); } } span2Counter++; } //break; //Not needed? } } spanCounter++; } //Write Row int length = 1; for (int iterator5 = 0; iterator5 < currentarray.length; iterator5 += length) { StringBuffer tokenIdsArray = new StringBuffer(); StringBuffer eventIdsArray = new StringBuffer(); boolean unused = true; length = 1; if (currentarray[iterator5] == null) { //empty entry writer.append("<td></td>"); } else { PartiturParser.ResultElement element = null; HashSet<Integer> common = new HashSet<Integer>(); boolean found = false; int outputSpanCounter = 0; for (List<PartiturParser.ResultElement> outputSpan : partitur.getResultlist()) { for (PartiturParser.ResultElement strr : outputSpan) { if (strr.getId().equals(currentarray[iterator5])) { if (!found) { element = strr; } if (!common.contains(outputSpanCounter)) { common.add(outputSpanCounter); } found = true; if (unused) { tokenIdsArray.append("" + strr.getId() + "_" + outputSpanCounter); eventIdsArray .append(tier + "_" + strr.getId() + "_" + outputSpanCounter); unused = false; } else { tokenIdsArray.append("," + strr.getId() + "_" + outputSpanCounter); eventIdsArray.append( "," + tier + "_" + strr.getId() + "_" + outputSpanCounter); } } } outputSpanCounter++; } for (int iterator7 = iterator5 + 1; iterator7 < currentarray.length; iterator7++) { if (common.contains(iterator7)) { length++; } else { break; } } for (int iterator8 = 0; iterator8 < currentarray.length; iterator8++) { if (common.contains(iterator8)) { Long id = ((PartiturParser.Token) partitur.getToken().toArray()[iterator8]) .getId(); if (unused) { tokenIdsArray.append("" + id); eventIdsArray.append(tier + "_" + id); unused = false; } else { tokenIdsArray.append("," + id); eventIdsArray.append("," + tier + "_" + id); } } } String color = "black"; if (input.getMarkableExactMap().containsKey("" + element.getNodeId())) { color = input.getMarkableExactMap().get("" + element.getNodeId()); } if (found) { writer.append("<td class=\"single_event\" " + "id=\"event_" + tier + "_" + element.getId() + "_" + iterator5 + "\" " + "style=\"color:" + color + ";\" " + "colspan=" + length + " " + "annis:tokenIds=\"" + tokenIdsArray + "\" " + "annis:eventIds=\"" + eventIdsArray + "\" " + "title=\"" + partitur.namespaceForTier(tier) + ":" + tier + " = " + StringEscapeUtils.escapeXml(element.getValue()) + "\" " //tier =tier, event.getValue()= element.name + "onMouseOver=\"toggleAnnotation(this, true);\" " + "onMouseOut=\"toggleAnnotation(this, false);\" " + addTimeAttribute(element.getNodeId()) + ">" + element.getValue() + "</td>"); } else { writer.append("<td class=\"single_event\" >error</td>"); } } } writer.append("</tr>"); //finish row } } // add token itself writer.append("<tr><th>tok</th>"); for (PartiturParser.Token token : partitur.getToken()) { String color = "black"; if (input.getMarkableExactMap().containsKey("" + token.getId())) { color = input.getMarkableExactMap().get("" + token.getId()); } writer.append("<td class=\"tok\" style=\"color:" + color + ";\" " + "id=\"token_" + token.getId() + "\" " + ">" + token.getValue() + "</td>"); } writer.append("</tr>"); writer.append("</table>\n"); writer.append("</div>\n"); writer.append("</body></html>"); } catch (Exception ex) { log.error(null, ex); try { String annisLine = ""; for (int i = 0; i < ex.getStackTrace().length; i++) { if (ex.getStackTrace()[i].getClassName().startsWith("annis.")) { annisLine = ex.getStackTrace()[i].toString(); } } writer.append("<html><body>Error occured (" + ex.getClass().getName() + "): " + ex.getLocalizedMessage() + "<br/>" + annisLine + "</body></html>"); } catch (IOException ex1) { log.error(null, ex1); } } }
From source file:org.alfresco.solr.SolrInformationServer.java
private void updateDescendantDocs(NodeMetaData parentNodeMetaData, boolean overwrite, SolrQueryRequest request, UpdateRequestProcessor processor, LinkedHashSet<Long> stack) throws AuthenticationException, IOException, JSONException { if (stack.contains(parentNodeMetaData.getId())) { log.warn("Found descendant data loop for node id " + parentNodeMetaData.getId()); log.warn("... stack to node =" + stack); return;/*from w ww .j av a 2s . c om*/ } else { try { stack.add(parentNodeMetaData.getId()); doUpdateDescendantDocs(parentNodeMetaData, overwrite, request, processor, stack); } finally { stack.remove(parentNodeMetaData.getId()); } } }
From source file:ca.uhn.fhir.jpa.dao.SearchBuilder.java
private void processSort(final SearchParameterMap theParams) { // Set<Long> loadPids = theLoadPids; if (theParams.getSort() != null && isNotBlank(theParams.getSort().getParamName())) { List<Order> orders = new ArrayList<Order>(); List<Predicate> predicates = new ArrayList<Predicate>(); CriteriaBuilder builder = myEntityManager.getCriteriaBuilder(); CriteriaQuery<Tuple> cq = builder.createTupleQuery(); Root<ResourceTable> from = cq.from(ResourceTable.class); createPredicateResourceId(builder, cq, predicates, from.get("myId").as(Long.class)); createSort(builder, from, theParams.getSort(), orders, predicates); if (orders.size() > 0) { // TODO: why do we need the existing list for this join to work? Collection<Long> originalPids = doGetPids(); LinkedHashSet<Long> loadPids = new LinkedHashSet<Long>(); cq.multiselect(from.get("myId").as(Long.class)); cq.where(toArray(predicates)); cq.orderBy(orders);// ww w.ja v a2 s. com TypedQuery<Tuple> query = myEntityManager.createQuery(cq); for (Tuple next : query.getResultList()) { loadPids.add(next.get(0, Long.class)); } ourLog.debug("Sort PID order is now: {}", loadPids); ArrayList<Long> pids = new ArrayList<Long>(loadPids); // Any ressources which weren't matched by the sort get added to the bottom for (Long next : originalPids) { if (loadPids.contains(next) == false) { pids.add(next); } } doSetPids(pids); } } }
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 {/*w w w . ja v a 2s .com*/ 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; } }
From source file:mrcg.MRCGInstance.java
private JavaField buildField(JavaClass jclass, String fieldName, String def, Visibility visibility) { String[] parts = splitFieldDef(def); LinkedHashSet<String> set = new LinkedHashSet<String>(Arrays.asList(parts)); JavaField field = null;/*from www . j ava 2s . com*/ if ("references".equals(parts[0])) { field = addReferenceProperty(fieldName, jclass, getType(parts[1]), parts); // field.setLabel(StringUtils.toSpacedCamelCase(field.getReferences().getName())); field.setLabel(Utils.toSpacedCamelCase(StringUtils.capitalize(fieldName))); } else { String type = parts[0]; int i = type.indexOf("("); Integer[] scale = null; if (i > 0) { scale = getScale(type.substring(i)); type = type.substring(0, i); } field = new JavaField(); field.setName(fieldName); if (scale != null) { field.setMinLength(scale[0]); field.setMaxLength(scale[1]); } // string, text, numeric, long, date if ("string".equals(type)) { if (scale == null) { throw new IllegalArgumentException("Type [string] requires scale"); } field.setType(JavaType.STRING); field.setDbType(DBType.Varchar); } else if ("text".equals(type)) { field.setType(JavaType.STRING); field.setDbType(DBType.Text); } else if ("double".equals(type)) { field.setType(JavaType.DOUBLE); field.setDbType(DBType.DoublePrecision); } else if ("numeric".equals(type)) { if (scale == null) { throw new IllegalArgumentException("Type [numeric] requires scale"); } field.setType(JavaType.DOUBLE); field.setDbType(DBType.Double); } else if ("money".equals(type)) { scale = new Integer[] { 8, 2 }; field.setMinLength(8); field.setMaxLength(2); field.setType(JavaType.DOUBLE); field.setDbType(DBType.Double); } else if ("int".equals(type) || "integer".equals(type)) { field.setType(JavaType.INTEGER); field.setDbType(DBType.Integer); } else if ("long".equals(type)) { field.setType(JavaType.LONG); field.setDbType(DBType.Long); } else if ("date".equals(type)) { field.setType(getDateType()); field.setDbType(DBType.Date); } else if ("justdate".equals(type)) { field.setType(getDateType()); field.setDbType(DBType.JustDate); } else if ("boolean".equals(type)) { field.setType(JavaType.BOOLEAN); field.setDbType(DBType.Boolean); } else if ("time".equals(type)) { field.setType(getDateType()); field.setDbType(DBType.Time); } else if ("email".equals(type)) { field.setType(JavaType.EMAIL); field.setDbType(DBType.Varchar); if (scale == null) { throw new IllegalArgumentException("Type [email] requires scale"); } } else if ("binary".equals(type)) { field.setType(JavaType.BINARY); field.setDbType(DBType.Binary); } else { throw new IllegalArgumentException("Type [" + type + "] is not currently supported [" + jclass.getName() + "." + fieldName + ": " + def + "]"); } Utils.createBeanProperty(jclass, field, true); } field.setVisibility(visibility); if (set.contains("label")) { field.setLabel(getItemAfter(set, "label")); } if (set.contains("default")) { field.setDefaultValue(getItemAfter(set, "default")); } field.setEncrypted(set.contains("encrypted")); if (field != null) { field.setOnList(set.contains("list")); field.setOnView(!set.contains("noview")); field.setRequired(!set.contains("null")); field.setUnique(set.contains("unique")); field.setIdentifier(set.contains("identifier")); field.setOrder(set.contains("order")); } if (set.contains("index") || set.contains("indexed")) { field.setIndexed(true); } return field; }
From source file:com.sonicle.webtop.calendar.CalendarManager.java
@Override public void updateEventObject(int calendarId, String href, net.fortuna.ical4j.model.Calendar iCalendar) throws WTException { final UserProfile.Data udata = WT.getUserData(getTargetProfileId()); int eventId = getEventIdByCategoryHref(calendarId, href, true); ICalendarInput in = new ICalendarInput(udata.getTimeZone()).withDefaultAttendeeNotify(true) .withIncludeVEventSourceInOutput(true); ArrayList<EventInput> eis = in.fromICalendarFile(iCalendar, null); if (eis.isEmpty()) throw new WTException("iCalendar object does not contain any events"); EventInput refInput = eis.remove(0); if (refInput.exRefersToPublicUid != null) throw new WTException("First iCalendar event should not have a RECURRENCE-ID set"); // Collect dates exceptions and prepare broken event to be inserted ArrayList<EventInput> eiExs = new ArrayList<>(); LinkedHashSet<LocalDate> exDates = new LinkedHashSet<>(); for (EventInput ei : eis) { if (!StringUtils.equals(ei.exRefersToPublicUid, refInput.event.getPublicUid())) continue; if (exDates.contains(ei.addsExOnMaster)) continue; exDates.add(ei.addsExOnMaster);//w w w .java 2 s. c o m if (!ei.isSourceEventCancelled()) eiExs.add(ei); } // Adds new collected exceptions and then updates master event if (!exDates.isEmpty()) { if (refInput.event.hasExcludedDates()) { refInput.event.getExcludedDates().addAll(exDates); } else { refInput.event.setExcludedDates(exDates); } } refInput.event.setEventId(eventId); refInput.event.setCalendarId(calendarId); refInput.event.setExcludedDates(exDates); updateEvent(refInput.event, true); // Here we do not support creating broken events related to the // main event series (re-attach unavailable). Instance exceptions // should have been created above as date exception into the main // event; so simply create exceptions as new events. if (!eiExs.isEmpty()) { for (EventInput eiEx : eiExs) { eiEx.event.setCalendarId(calendarId); eiEx.event.setPublicUid(null); // reset uid //TODO: handle raw value to persist custom properties try { addEvent(eiEx.event, null, true); } catch (Throwable t) { logger.error("Unable to insert exception on {} as new event", eiEx.addsExOnMaster, t); } } } }