List of usage examples for java.util ArrayList set
public E set(int index, E element)
From source file:org.alfresco.repo.node.MLPropertyInterceptor.java
/** * // w w w . j a v a 2 s .c o m * @param inboundValue The value that must be set * @param currentValue The current value of the property or <tt>null</tt> if not known * @return Returns a potentially converted property that conforms to the model */ private Serializable convertInboundProperty(Locale contentLocale, NodeRef nodeRef, NodeRef pivotNodeRef, QName propertyQName, Serializable inboundValue, Serializable currentValue) { Serializable ret = null; PropertyDefinition propertyDef = this.dictionaryService.getProperty(propertyQName); //if no type definition associated to the name then just proceed if (propertyDef == null) { ret = inboundValue; } else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) { // Don't mess with multivalued properties or instances already of type MLText if (inboundValue instanceof MLText) { ret = inboundValue; } else if (propertyDef.isMultiValued()) { // leave collectios of ML text alone if (isCollectionOfMLText(inboundValue)) { ret = inboundValue; } else { // Anything else we assume is localised if (currentValue == null && nodeRef != null) { currentValue = nodeService.getProperty(nodeRef, propertyQName); } ArrayList<MLText> returnMLList = new ArrayList<MLText>(); if (currentValue != null) { Collection<MLText> currentCollection = DefaultTypeConverter.INSTANCE .getCollection(MLText.class, currentValue); returnMLList.addAll(currentCollection); } Collection<String> inboundCollection = DefaultTypeConverter.INSTANCE.getCollection(String.class, inboundValue); int count = 0; for (String current : inboundCollection) { MLText newMLValue; if (count < returnMLList.size()) { MLText currentMLValue = returnMLList.get(count); newMLValue = new MLText(); if (currentMLValue != null) { newMLValue.putAll(currentMLValue); } } else { newMLValue = new MLText(); } replaceTextForLanguage(contentLocale, current, newMLValue); if (count < returnMLList.size()) { returnMLList.set(count, newMLValue); } else { returnMLList.add(newMLValue); } count++; } // remove locale settings for anything after for (int i = count; i < returnMLList.size(); i++) { MLText currentMLValue = returnMLList.get(i); MLText newMLValue = new MLText(); if (currentMLValue != null) { newMLValue.putAll(currentMLValue); } newMLValue.remove(contentLocale); returnMLList.set(i, newMLValue); } // tidy up empty locales ArrayList<MLText> tidy = new ArrayList<MLText>(); for (MLText mlText : returnMLList) { if (mlText.keySet().size() > 0) { tidy.add(mlText); } } ret = tidy; } } else { // This is a multilingual single-valued property // Get the current value from the node service, if not provided if (currentValue == null && nodeRef != null) { currentValue = nodeService.getProperty(nodeRef, propertyQName); } MLText returnMLValue = new MLText(); if (currentValue != null) { MLText currentMLValue = DefaultTypeConverter.INSTANCE.convert(MLText.class, currentValue); returnMLValue.putAll(currentMLValue); } // Force the inbound value to be a String (it isn't MLText) String inboundValueStr = DefaultTypeConverter.INSTANCE.convert(String.class, inboundValue); // Update the text for the appropriate language. replaceTextForLanguage(contentLocale, inboundValueStr, returnMLValue); // Done ret = returnMLValue; } } else if (pivotNodeRef != null && propertyQName.equals(ContentModel.PROP_CONTENT)) { // It is an empty translation. The content must not change if it matches // the content of the pivot translation ContentData pivotContentData = (ContentData) nodeService.getProperty(pivotNodeRef, ContentModel.PROP_CONTENT); ContentData emptyContentData = (ContentData) inboundValue; String pivotContentUrl = pivotContentData == null ? null : pivotContentData.getContentUrl(); String emptyContentUrl = emptyContentData == null ? null : emptyContentData.getContentUrl(); if (EqualsHelper.nullSafeEquals(pivotContentUrl, emptyContentUrl)) { // They are a match. So the empty translation must be reset to it's original value ret = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); } else { ret = inboundValue; } } else { ret = inboundValue; } // Done if (logger.isDebugEnabled() && ret != inboundValue) { logger.debug("Converted inbound property: \n" + " NodeRef: " + nodeRef + "\n" + " Property: " + propertyQName + "\n" + " Before: " + inboundValue + "\n" + " After: " + ret); } return ret; }
From source file:es.pode.catalogadorWeb.presentacion.categoriasAvanzado.relacion.detalleRelacion.DetalleRelacionControllerImpl.java
private void cambioFormulario(HttpServletRequest request, int[] longitudTextosDesc, Object formRequestSession) throws IOException { String source = AgregaPropertiesImpl.getInstance().getProperty("esquemaDeMetadatos"); lDescripciones = new DescripcionVO[longitudTextosDesc.length]; String tipoTexto = ""; ArrayList[] textoDescripciones = new ArrayList[longitudTextosDesc.length]; ArrayList[] idiomaDescripciones = new ArrayList[longitudTextosDesc.length]; for (Enumeration names = request.getParameterNames(); names.hasMoreElements();) { String name = String.valueOf(names.nextElement()); //DesFecTex DesFecIdio Des DesIdio if (name.startsWith("Des")) {//descripciones String[] namePartido = name.split("_"); int i = Integer.parseInt(namePartido[0].substring(3, namePartido[0].length())); if (namePartido[1].startsWith("Tex")) { int j = Integer.parseInt(namePartido[1].substring(3, namePartido[1].length())); ArrayList lDesc = textoDescripciones[i]; if (lDesc == null) { lDesc = new ArrayList(); for (int k = 0; k < longitudTextosDesc[i]; k++) lDesc.add(""); }//from w ww .j a v a2 s .c om lDesc.set(j, request.getParameter(name)); textoDescripciones[i] = lDesc; } else {//Idio int j = Integer.parseInt(namePartido[1].substring(4, namePartido[1].length())); ArrayList lDesc = idiomaDescripciones[i]; if (lDesc == null) { lDesc = new ArrayList(); for (int k = 0; k < longitudTextosDesc[i]; k++) lDesc.add(""); } lDesc.set(j, request.getParameter(name)); idiomaDescripciones[i] = lDesc; } } else if (name.startsWith("tip")) { tipoTexto = request.getParameter(name); } else if (name.startsWith("Cat")) { catalogo = request.getParameter(name); } else if (name.startsWith("Ent")) { entrada = request.getParameter(name); } } // tipo SourceValueVO tipoRecrusoVO = new SourceValueVO(); tipoRecrusoVO.setValor(tipoTexto); tipoRecrusoVO.setSource(source); tipo = tipoRecrusoVO; //descripcion DescripcionVO[] descVO = new DescripcionVO[textoDescripciones.length]; for (int i = 0; i < textoDescripciones.length; i++) { DescripcionVO descr = new DescripcionVO(); if (textoDescripciones[i] != null) { LangStringVO[] aLangDescripciones = new LangStringVO[textoDescripciones[i].size()]; for (int j = 0; j < textoDescripciones[i].size(); j++) { String texto = (textoDescripciones[i].get(j) != null ? textoDescripciones[i].get(j) : "") .toString(); String idioma = (String) idiomaDescripciones[i].get(j); LangStringVO langDescripciones = new LangStringVO(); langDescripciones.setTexto(texto.trim()); langDescripciones.setIdioma(idioma); aLangDescripciones[j] = langDescripciones; } descr.setTextos(aLangDescripciones); } else { LangStringVO[] aLangString = new LangStringVO[1]; LangStringVO langString = new LangStringVO(); langString.setIdioma(""); langString.setTexto(""); aLangString[0] = langString; descr.setTextos(aLangString); } lDescripciones[i] = descr; } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
private ArrayList<String> checkUpCatalogRepositoryForTreeObject(TreeObject theObj, TreeObject folder) { if (theObj.getType() == 0 || theObj.getType() == TreeObject.CATEGORY_FOLDER) { return null; }//from www .j a va 2 s .co m try { String modelName = getXPathForTreeObject(folder); String url = getURLFromTreeObject(theObj); String xpath = modelName + "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER + "' and @Url='" + url //$NON-NLS-1$//$NON-NLS-2$ + "']//child::*";//$NON-NLS-1$ Document doc = credentials.get(getURLFromTreeObject(folder)).doc; List<Element> elems = doc.selectNodes(xpath); for (Element elem : elems) { String xpathElem = getXPathForElem(elem); String xpathObj = getXPathForTreeObject(theObj); int squarebk = xpathObj.indexOf("[");//$NON-NLS-1$ if (squarebk != -1) { xpathObj = xpathObj.substring(0, squarebk); } if (elem.getName().equals(filterOutBlank(theObj.getDisplayName())) && elem.getData().toString().equals(theObj.getType() + "")) {//$NON-NLS-1$ ArrayList<String> path = new ArrayList<String>(); HashMap<Integer, String> slice = new HashMap<Integer, String>(); while (isAEXtentisObjects(elem, theObj) > XTENTIS_LEVEL) { String elemName = elem.getParent().getName(); if (elem.getParent().attributeValue(REALNAME) != null) { elemName = elem.getParent().attributeValue(REALNAME); } if (elem.getText() != null && StringUtils.trim(elem.getParent().getText()) .equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ path.add(elem.getParent().getName()); if (elem.getParent().attributeValue(REALNAME) != null) { slice.put(path.size() - 1, elem.getParent().attributeValue(REALNAME)); } } elem = elem.getParent(); } ArrayList<String> pathCpy = new ArrayList<String>(path); Collections.reverse(path); if (!isEqualString(xpathElem, xpathObj, path)) { path = null; } if (path != null) { for (int i = 0; i < pathCpy.size(); i++) { if (slice.get(i) != null) { pathCpy.set(i, slice.get(i)); } } Collections.reverse(pathCpy); path = pathCpy; } return path; } } } catch (Exception ex) { return null; } return null; }
From source file:edu.nyu.vida.data_polygamy.ctdata.TopologicalIndex.java
private void getEvents(ArrayList<byte[]> events, GraphInput tf, Feature[] features, boolean min, double eventTh, boolean print) { float[] fnVertices = tf.getFnVertices(); // nv = 1; // if (is2D) { // nv = ((TimeSeries2DFunction)tf).nv; // }//from w w w . ja v a 2 s .co m IntOpenHashSet set = new IntOpenHashSet(); for (Feature f : features) { float pt = f.exFn; if (min) { if (f.sadFn < f.exFn) { pt = f.sadFn; } if (pt > eventTh) { continue; } int exv = f.v; IntArrayList queue = new IntArrayList(); queue.add(exv); while (queue.size() > 0) { int vin = queue.remove(0); if (set.contains(vin)) { continue; } set.add(vin); pt = fnVertices[vin]; if (pt <= eventTh) { int tid = vin / nv; int time = tf.getTime(tid); int spatial = vin % nv; int index = FrameworkUtils.getTimeSteps(this.tempRes, this.stTime, time); byte[] spatialEvents = events.get(spatial); spatialEvents[index - 1] = FrameworkUtils.negativeEvent; events.set(spatial, spatialEvents); if (print) { // October 15th, 2011 to October 31st, 2011 if ((time >= 1318636800) && (time <= 1320105599)) { System.out.print(FrameworkUtils.getTemporalStr(FrameworkUtils.HOUR, time) + "\t"); System.out.print(eventTh + ", " + pt); System.out.println(""); } } int[] nEventsArray = nEvents.get(spatial); nEventsArray[1]++; nEventsArray[2]--; nEvents.set(spatial, nEventsArray); MyIntList star = tf.getStar(vin); for (int i = 0; i < star.length; i++) { if (!set.contains(star.array[i])) { queue.add(star.array[i]); } } } } } else { if (pt < eventTh) { continue; } int exv = f.v; IntArrayList queue = new IntArrayList(); queue.add(exv); while (queue.size() > 0) { int vin = queue.remove(0); if (set.contains(vin)) { continue; } set.add(vin); pt = fnVertices[vin]; if (pt >= eventTh) { int tid = vin / nv; int time = tf.getTime(tid); int spatial = vin % nv; int index = FrameworkUtils.getTimeSteps(this.tempRes, this.stTime, time); byte[] spatialEvents = events.get(spatial); spatialEvents[index - 1] = FrameworkUtils.positiveEvent; events.set(spatial, spatialEvents); if (print) { // October 15th, 2011 to October 31st, 2011 if ((time >= 1318636800) && (time <= 1320105599)) { System.out.print(FrameworkUtils.getTemporalStr(FrameworkUtils.HOUR, time) + "\t"); System.out.print(eventTh + ", " + pt); System.out.println(""); } } int[] nEventsArray = nEvents.get(spatial); nEventsArray[0]++; nEventsArray[2]--; nEvents.set(spatial, nEventsArray); MyIntList star = tf.getStar(vin); for (int i = 0; i < star.length; i++) { if (!set.contains(star.array[i])) { queue.add(star.array[i]); } } } } } } }
From source file:ca.uhn.fhir.parser.JsonParser.java
private void addToHeldIds(int theValueIdx, ArrayList<String> theListToAddTo, String theId) { theListToAddTo.ensureCapacity(theValueIdx); while (theListToAddTo.size() <= theValueIdx) { theListToAddTo.add(null);//from w ww . jav a2 s.com } if (theListToAddTo.get(theValueIdx) == null) { theListToAddTo.set(theValueIdx, theId); } }
From source file:org.hyperic.util.schedule.Schedule.java
/** * Get the next item (or items) to be executed. If more than one item * is scheduled for a specific time, they are all returned. Items * returned by this function are re-inserted into the schedule, if their * repeat flag is set to true -- otherwise they are removed. * * @return a list of items to execute// w w w. j ava2s . c om * * @throws EmptyScheduleException indicating there was no 'next item' */ public synchronized List consumeNextItems() throws EmptyScheduleException { int size = this.schedule.size(); ScheduledItem base; ArrayList res; long baseNextTime; if (size == 0) throw new EmptyScheduleException(); res = new ArrayList(1); // We always add the first item to the list of returned objects base = (ScheduledItem) this.schedule.get(0); baseNextTime = System.currentTimeMillis(); res.add(base); boolean debug = log.isDebugEnabled(); // Now add other items if they occur at the same time for (int i = 1; i < size; i++) { ScheduledItem other = (ScheduledItem) this.schedule.get(i); if (debug) { log.debug("checking " + other.getObj() + " baseNextTime: " + getDateStr(baseNextTime) + ", getNextTime: " + getDateStr(other.getNextTime())); } if (other.getNextTime() <= baseNextTime) { res.add(other); } else { break; } } // Finally, loop through the objects we are about to return, so // we can re-order our innards, and return the actual objects // stored instead of the ScheduledItem // XXX -- This could be MUCH more efficient, especially with respect // to re-inserting into the list, since all of the returned // objects are of the same size. for (int i = 0; i < res.size(); i++) { ScheduledItem other = (ScheduledItem) res.get(i); if (debug) { log.debug("removing " + other.getObj()); } this.schedule.remove(other); if (other.isRepeat()) { other.stepNextTime(); if (debug) { log.debug("adding " + other.getObj() + " getNextTime " + getDateStr(other.getNextTime())); } this.insertScheduledItem(other); } res.set(i, other.getObj()); } return res; }
From source file:ca.uhn.fhir.parser.JsonParser.java
private boolean addToHeldComments(int valueIdx, List<String> theCommentsToAdd, ArrayList<ArrayList<String>> theListToAddTo) { if (theCommentsToAdd.size() > 0) { theListToAddTo.ensureCapacity(valueIdx); while (theListToAddTo.size() <= valueIdx) { theListToAddTo.add(null);//from w w w . j av a2s. c o m } if (theListToAddTo.get(valueIdx) == null) { theListToAddTo.set(valueIdx, new ArrayList<String>()); } theListToAddTo.get(valueIdx).addAll(theCommentsToAdd); return true; } else { return false; } }
From source file:ca.uhn.fhir.parser.JsonParser.java
private boolean addToHeldExtensions(int valueIdx, List<? extends IBaseExtension<?, ?>> ext, ArrayList<ArrayList<HeldExtension>> list, boolean theIsModifier, CompositeChildElement theChildElem) { if (ext.size() > 0) { list.ensureCapacity(valueIdx);/* w w w .j a v a 2s. c o m*/ while (list.size() <= valueIdx) { list.add(null); } if (list.get(valueIdx) == null) { list.set(valueIdx, new ArrayList<JsonParser.HeldExtension>()); } for (IBaseExtension<?, ?> next : ext) { list.get(valueIdx).add(new HeldExtension(next, theIsModifier, theChildElem)); } return true; } else { return false; } }
From source file:org.ejbca.core.model.ra.raadmin.EndEntityProfile.java
private void incrementFieldnumber(final int parameter) { @SuppressWarnings("unchecked") final ArrayList<Integer> numberarray = (ArrayList<Integer>) data.get(NUMBERARRAY); numberarray.set(parameter, Integer.valueOf(numberarray.get(parameter).intValue() + 1)); }