List of usage examples for org.apache.commons.lang ObjectUtils toString
public static String toString(Object obj)
Gets the toString
of an Object
returning an empty string ("") if null
input.
ObjectUtils.toString(null) = "" ObjectUtils.toString("") = "" ObjectUtils.toString("bat") = "bat" ObjectUtils.toString(Boolean.TRUE) = "true"
From source file:org.displaytag.render.TableWriterTemplate.java
/** * Given a table model, writes the table body content, sorting and grouping it per its configuration, while * delegating where and how it writes to subclass objects. (Background: This method refactors * TableTagData.writeTableBody method. See above.) * @param model The table model used to build the table body. * @throws Exception if an error is encountered while writing the table body. */// w ww. j a v a 2s . com private void writeTableBody(TableModel model) throws Exception { // Ok, start bouncing through our list (only the visible part) RowIterator rowIterator = model.getRowIterator(false); // iterator on rows TableDecorator tableDecorator = model.getTableDecorator(); Row previousRow = null; Row currentRow = null; Row nextRow = null; Map previousRowValues = new HashMap(10); Map currentRowValues = new HashMap(10); Map nextRowValues = new HashMap(10); while (nextRow != null || rowIterator.hasNext()) { // The first pass if (currentRow == null) { currentRow = rowIterator.next(); } else { previousRow = currentRow; currentRow = nextRow; } if (previousRow != null) { previousRowValues.putAll(currentRowValues); } if (!nextRowValues.isEmpty()) { currentRowValues.putAll(nextRowValues); } // handle the first pass else { ColumnIterator columnIterator = currentRow.getColumnIterator(model.getHeaderCellList()); // iterator on columns if (log.isDebugEnabled()) { log.debug(" creating ColumnIterator on " + model.getHeaderCellList()); } while (columnIterator.hasNext()) { Column column = columnIterator.nextColumn(); // Get the value to be displayed for the column column.initialize(); // DISPL-611 String cellvalue = MediaTypeEnum.HTML.equals(model.getMedia()) ? column.getChoppedAndLinkedValue() : ObjectUtils.toString(column.getValue(true)); CellStruct struct = new CellStruct(column, cellvalue); // end DISPL-611 currentRowValues.put(new Integer(column.getHeaderCell().getColumnNumber()), struct); } } nextRowValues.clear(); // Populate the next row values nextRow = rowIterator.hasNext() ? rowIterator.next() : null; if (nextRow != null) { ColumnIterator columnIterator = nextRow.getColumnIterator(model.getHeaderCellList()); // iterator on columns if (log.isDebugEnabled()) { log.debug(" creating ColumnIterator on " + model.getHeaderCellList()); } while (columnIterator.hasNext()) { Column column = columnIterator.nextColumn(); column.initialize(); // Get the value to be displayed for the column // DISPL-611 String cellvalue = MediaTypeEnum.HTML.equals(model.getMedia()) ? column.getChoppedAndLinkedValue() : ObjectUtils.toString(column.getValue(true)); CellStruct struct = new CellStruct(column, cellvalue); // end DISPL-611 nextRowValues.put(new Integer(column.getHeaderCell().getColumnNumber()), struct); } } // now we are going to create the current row; reset the decorator to the current row if (tableDecorator != null) { tableDecorator.initRow(currentRow.getObject(), currentRow.getRowNumber(), currentRow.getRowNumber() + rowIterator.getPageOffset()); } Iterator headerCellsIter = model.getHeaderCellList().iterator(); ArrayList structsForRow = new ArrayList(model.getHeaderCellList().size()); lowestEndedGroup = NO_RESET_GROUP; lowestStartedGroup = NO_RESET_GROUP; while (headerCellsIter.hasNext()) { HeaderCell header = (HeaderCell) headerCellsIter.next(); // Get the value to be displayed for the column CellStruct struct = (CellStruct) currentRowValues.get(new Integer(header.getColumnNumber())); struct.decoratedValue = struct.bodyValue; // Check and see if there is a grouping transition. If there is, then notify the decorator if (header.getGroup() != -1) { CellStruct prior = (CellStruct) previousRowValues.get(new Integer(header.getColumnNumber())); CellStruct next = (CellStruct) nextRowValues.get(new Integer(header.getColumnNumber())); // Why npe? String priorBodyValue = prior != null ? prior.bodyValue : null; String nextBodyValue = next != null ? next.bodyValue : null; short groupingValue = groupColumns(struct.bodyValue, priorBodyValue, nextBodyValue, header.getGroup()); if (tableDecorator != null) { switch (groupingValue) { case GROUP_START: tableDecorator.startOfGroup(struct.bodyValue, header.getGroup()); break; case GROUP_END: tableDecorator.endOfGroup(struct.bodyValue, header.getGroup()); break; case GROUP_START_AND_END: tableDecorator.startOfGroup(struct.bodyValue, header.getGroup()); tableDecorator.endOfGroup(struct.bodyValue, header.getGroup()); break; default: break; } } if (tableDecorator != null) { struct.decoratedValue = tableDecorator.displayGroupedValue(struct.bodyValue, groupingValue, header.getColumnNumber()); } else if (groupingValue == GROUP_END || groupingValue == GROUP_NO_CHANGE) { struct.decoratedValue = TagConstants.EMPTY_STRING; } } structsForRow.add(struct); } if (tableDecorator != null) { writeDecoratedRowStart(model); } // open row writeRowOpener(currentRow); for (Iterator iterator = structsForRow.iterator(); iterator.hasNext();) { CellStruct struct = (CellStruct) iterator.next(); writeColumnOpener(struct.column); writeColumnValue(struct.decoratedValue, struct.column); writeColumnCloser(struct.column); } if (model.isEmpty()) { if (log.isDebugEnabled()) { log.debug("[" + this.id + "] table has no columns"); } // render empty row writeRowWithNoColumns(currentRow.getObject().toString()); } // close row writeRowCloser(currentRow); // decorate row finish if (model.getTableDecorator() != null) { writeDecoratedRowFinish(model); } } // render empty list message if (model.getRowListPage().size() == 0) { writeEmptyListRowMessage(MessageFormat.format(model.getProperties().getEmptyListRowMessage(), new Object[] { new Integer(model.getNumberOfColumns()) })); } }
From source file:org.dspace.authority.PersonAuthorityValue.java
@Override public void setValues(SolrDocument document) { super.setValues(document); this.firstName = ObjectUtils.toString(document.getFieldValue("first_name")); this.lastName = ObjectUtils.toString(document.getFieldValue("last_name")); nameVariants = new ArrayList<String>(); Collection<Object> document_name_variant = document.getFieldValues("name_variant"); if (document_name_variant != null) { for (Object name_variants : document_name_variant) { addNameVariant(String.valueOf(name_variants)); }//w ww .j a v a 2 s. c o m } if (document.getFieldValue("institution") != null) { this.institution = String.valueOf(document.getFieldValue("institution")); } Collection<Object> emails = document.getFieldValues("email"); if (emails != null) { for (Object email : emails) { addEmail(String.valueOf(email)); } } }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.internal.collections.ListUtil.java
/** * Caseless.//w w w . j a v a 2s.co m * * @param <E> the element type * @param objects the objects * @return the list */ public static <E extends Object> List<String> caseless(final E... objects) { final Transformer<String> transformer = new Transformer<String>() { private static final long serialVersionUID = 1631027078150099602L; @Override public String transform(final Object input) { return ObjectUtils.toString(input).toLowerCase(); } }; return transformed(transformer, objects); }
From source file:org.ebayopensource.turmeric.eclipse.mavenapi.test.internal.collections.TestListUtil.java
/** * Test method for {@link org.ebayopensource.turmeric.eclipse.mavenapi.internal.collections.ListUtil#transformed(org.ebayopensource.turmeric.eclipse.mavenapi.internal.collections.Transformer, java.util.List)}. *//* w ww . j a va2 s . c o m*/ @Test public void testTransformedTransformerOfTListOfQ() { List<String> collection = new ArrayList<String>(); collection.add("S3"); collection.add("Nvidia"); collection.add("ATI"); final Transformer<String> transformer = new Transformer<String>() { private static final long serialVersionUID = 1631027078150099602L; @Override public String transform(final Object input) { return ObjectUtils.toString(input).toLowerCase(); } }; List<String> list = ListUtil.transformed(transformer, collection); for (int i = 0; i < collection.size(); i++) { String expected = collection.get(i); String actual = list.get(i); Assert.assertNotSame(expected, actual); Assert.assertTrue(expected.equalsIgnoreCase(actual)); } String item = "3dfx"; list.add(item); Assert.assertTrue(list.contains(item)); list.remove(item); Assert.assertFalse(list.contains(item)); list.add(0, item); Assert.assertTrue(list.indexOf(item) == 0); Assert.assertTrue(list.lastIndexOf(item) == 0); list.remove(0); list.set(0, item); Assert.assertTrue(list.indexOf(item) == 0); Collection<String> data = new ArrayList<String>(2); data.add("Voodoo"); data.add("Radeon"); list.addAll(data); Assert.assertTrue(list.containsAll(data)); list.removeAll(data); Assert.assertFalse(list.containsAll(data)); list.addAll(0, data); list.retainAll(data); }
From source file:org.ebayopensource.turmeric.eclipse.utils.test.collections.TestListUtil.java
/** * Test method for {@link org.ebayopensource.turmeric.maveneclipseapi.internal.collections.ListUtil#transformed(org.ebayopensource.turmeric.maveneclipseapi.internal.collections.Transformer, java.util.List)}. *//*from ww w. j a va 2 s.co m*/ @Test public void testTransformedTransformerOfTListOfQ() { List<String> collection = new ArrayList<String>(); collection.add("Arc' Terryx"); collection.add("Mountain Hardwear"); collection.add("Black Diamond"); final Transformer<String> transformer = new Transformer<String>() { private static final long serialVersionUID = 1631027078150099602L; @Override public String transform(final Object input) { return ObjectUtils.toString(input).toLowerCase(); } }; List<String> list = ListUtil.transformed(transformer, collection); for (int i = 0; i < collection.size(); i++) { String expected = collection.get(i); String actual = list.get(i); Assert.assertNotSame(expected, actual); Assert.assertTrue(expected.equalsIgnoreCase(actual)); } String item = "3dfx"; list.add(item); Assert.assertTrue(list.contains(item)); list.remove(item); Assert.assertFalse(list.contains(item)); list.add(0, item); Assert.assertTrue(list.indexOf(item) == 0); Assert.assertTrue(list.lastIndexOf(item) == 0); list.remove(0); list.set(0, item); Assert.assertTrue(list.indexOf(item) == 0); Collection<String> data = new ArrayList<String>(2); data.add("Voodoo"); data.add("Radeon"); list.addAll(data); Assert.assertTrue(list.containsAll(data)); list.removeAll(data); Assert.assertFalse(list.containsAll(data)); list.addAll(0, data); list.retainAll(data); }
From source file:org.eclipse.jubula.client.core.persistence.Persistor.java
/** * /*w w w.j a v a 2 s . co m*/ * @param factory The factory from which to retrieve the property. * @param key The key/name of the property to retrieve. * @return the string value of the retrieved property. Returns * <code>null</code> if the factory does not contain the desired * property or if the value of the property is <code>null</code> * or if the string representation of the property value is * <code>null</code>. */ private static String getFactoryProperty(EntityManagerFactory factory, String key) { if (factory != null && factory.isOpen()) { return ObjectUtils.toString(factory.getProperties().get(key)); } return null; }
From source file:org.eclipse.jubula.client.ui.rcp.provider.labelprovider.GeneralLabelProvider.java
/** * {@inheritDoc}/*from ww w . j av a 2s . c o m*/ */ public String getToolTipText(Object element) { if (element instanceof INodePO) { INodePO node = (INodePO) element; StringBuilder toolTip = new StringBuilder(); String comment = node.getComment(); if (!StringUtils.isBlank(comment)) { toolTip.append(COMMENT_PREFIX); toolTip.append(ObjectUtils.toString(comment)); return toolTip.toString(); } } return super.getToolTipText(element); }
From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.SwtAutConfigComponent.java
/** * //ww w . j ava 2 s. c o m * {@inheritDoc} */ protected void createAdvancedArea(Composite advancedAreaComposite) { super.createAdvancedArea(advancedAreaComposite); UIComponentHelper.createLabel(advancedAreaComposite, I18n.getString("SwtAutConfigComponent.KEYBOARD_LAYOUT")); //$NON-NLS-1$ m_keyboardLayoutCombo = new ComboViewer(advancedAreaComposite, SWT.READ_ONLY); m_keyboardLayoutCombo.setContentProvider(new ArrayContentProvider()); m_keyboardLayoutCombo.setLabelProvider(new KeyboardLayoutLabelProvider()); m_keyboardLayoutCombo.setSorter(new ViewerSorter()); m_keyboardLayoutCombo.setInput(Languages.getInstance().getKeyboardLayouts()); Combo keyboardLayoutCombo = m_keyboardLayoutCombo.getCombo(); GridData comboGrid = new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1); LayoutUtil.addToolTipAndMaxWidth(comboGrid, keyboardLayoutCombo); keyboardLayoutCombo.setLayoutData(comboGrid); ((GridData) keyboardLayoutCombo.getLayoutData()).widthHint = COMPOSITE_WIDTH; // if new aut config, use defaults. String keyboardLayout = getConfigValue(AutConfigConstants.KEYBOARD_LAYOUT); if (StringUtils.isEmpty(keyboardLayout)) { m_keyboardLayoutCombo.setSelection(new StructuredSelection(ObjectUtils.toString(Locale.getDefault()))); } else { m_keyboardLayoutCombo.setSelection(new StructuredSelection(keyboardLayout)); } m_keyboardLayoutCombo.addSelectionChangedListener(new KeyboardLayoutComboListener()); }
From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.SwtAutConfigComponent.java
/** * /*from ww w .jav a 2 s. c om*/ * @return <code>null</code> if the new value is valid. Otherwise, returns * a status parameter indicating the cause of the problem. */ DialogStatusParameter modifyKeyboardLayout() { final String layout = ObjectUtils .toString(((StructuredSelection) m_keyboardLayoutCombo.getSelection()).getFirstElement()); if (StringUtils.isNotEmpty(layout)) { putConfigValue(AutConfigConstants.KEYBOARD_LAYOUT, layout.toString()); } return null; }
From source file:org.eclipse.jubula.client.ui.rcp.widgets.CompNameCellValidator.java
/** * {@inheritDoc}/*from ww w . j a v a 2s. c om*/ */ public String isValid(Object value) { String checkableName = ObjectUtils.toString(value); IStatus status = ComponentNameValidator.isValidComponentNameString(checkableName); if (!status.isOK()) { return status.getMessage(); } if (m_tableViewer.getSelection() == null || m_tableViewer.getSelection().isEmpty() || !(m_tableViewer.getSelection() instanceof IStructuredSelection)) { return null; } ICompNamesPairPO compNamesPair = ((ICompNamesPairPO) ((IStructuredSelection) m_tableViewer.getSelection()) .getFirstElement()); return m_validationDelegate.isValid(compNamesPair.getType(), checkableName); }