Example usage for java.lang Object equals

List of usage examples for java.lang Object equals

Introduction

In this page you can find the example usage for java.lang Object equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:AssociativeArray.java

public Object get(Object key) {
    for (int i = 0; i < index; i++)
        if (key.equals(pairs[i][0]))
            return pairs[i][1];
    throw new RuntimeException("Failed to find key");
}

From source file:com.ebay.jetstream.epl.EPLUtilities.java

/**
 * Removes element from an array. It's faster that turning array into stream and then using WHERE clause.
 * //from  w ww . j  a  v a2 s. c o m
 * @param array
 * @param value
 * @return
 */
public static Object[] removeElement(Object[] array, Object entryToRemove) {
    if (array != null && entryToRemove != null) {
        List<Object> list = new ArrayList<Object>();
        for (Object entry : array) {
            if (entry == null || !entry.equals(entryToRemove)) {
                list.add(entry);
            }
        }
        return list.toArray();
    }
    return array;
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

private static TableModel createTableModel(final IVisualizationCallback callback) {
    TableModel multicastDemandTableModel = new ClassAwareTableModel(
            new Object[1][netPlanViewTableHeader.length], netPlanViewTableHeader) {
        private static final long serialVersionUID = 1L;

        @Override/* www. j  a va 2 s.  c o m*/
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            if (!callback.getVisualizationState().isNetPlanEditable())
                return false;
            if (columnIndex >= netPlanViewTableHeader.length)
                return true;
            if (getValueAt(rowIndex, columnIndex) == null)
                return false;

            return columnIndex == COLUMN_OFFEREDTRAFFIC || columnIndex >= netPlanViewTableHeader.length;
        }

        @Override
        public void setValueAt(Object newValue, int row, int column) {
            Object oldValue = getValueAt(row, column);

            /* If value doesn't change, exit from function */
            if (newValue.equals(oldValue))
                return;

            NetPlan netPlan = callback.getDesign();

            if (getValueAt(row, 0) == null)
                row = row - 1;
            final long demandId = (Long) getValueAt(row, 0);
            final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId);

            /* Perform checks, if needed */
            try {
                switch (column) {
                case COLUMN_OFFEREDTRAFFIC:
                    final double newOfferedTraffic = Double.parseDouble(newValue.toString());
                    if (newOfferedTraffic < 0)
                        throw new Net2PlanException("The demand offered traffic cannot be negative");
                    if (callback.getVisualizationState().isWhatIfAnalysisActive()) {
                        final WhatIfAnalysisPane whatIfPane = callback.getWhatIfAnalysisPane();
                        synchronized (whatIfPane) {
                            whatIfPane.whatIfDemandOfferedTrafficModified(demand, newOfferedTraffic);
                            if (whatIfPane.getLastWhatIfExecutionException() != null)
                                throw whatIfPane.getLastWhatIfExecutionException();
                            whatIfPane.wait(); // wait until the simulation ends
                            if (whatIfPane.getLastWhatIfExecutionException() != null)
                                throw whatIfPane.getLastWhatIfExecutionException();

                            final VisualizationState vs = callback.getVisualizationState();
                            Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = vs
                                    .suggestCanvasUpdatedVisualizationLayerInfoForNewDesign(
                                            new HashSet<>(callback.getDesign().getNetworkLayers()));
                            vs.setCanvasLayerVisibilityAndOrder(callback.getDesign(), res.getFirst(),
                                    res.getSecond());
                            callback.updateVisualizationAfterNewTopology();
                        }
                    } else {
                        demand.setOfferedTraffic(newOfferedTraffic);
                        callback.updateVisualizationAfterChanges(
                                Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                        callback.getVisualizationState().pickMulticastDemand(demand);
                        callback.updateVisualizationAfterPick();
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    }
                    break;

                default:
                    break;
                }
            } catch (Throwable ex) {
                ErrorHandling.showErrorDialog(ex.getMessage(), "Error modifying multicast demand");
                return;
            }

            /* Set new value */
            super.setValueAt(newValue, row, column);
        }
    };
    return multicastDemandTableModel;
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Locates the name of a property for the given value on the target object using Groovy's meta APIs.
 * Note that this method uses the reference so the incorrect result could be returned for two properties
 * that refer to the same reference. Use with caution.
 *
 * @param target The target/*from  www.  ja va2 s.  co m*/
 * @param obj The property value
 * @return The property name or null
 */
public static String findPropertyNameForValue(Object target, Object obj) {
    MetaClass mc = GroovySystem.getMetaClassRegistry().getMetaClass(target.getClass());
    List<MetaProperty> metaProperties = mc.getProperties();
    for (MetaProperty metaProperty : metaProperties) {
        if (isAssignableOrConvertibleFrom(metaProperty.getType(), obj.getClass())) {
            Object val = metaProperty.getProperty(target);
            if (val != null && val.equals(obj)) {
                return metaProperty.getName();
            }
        }
    }
    return null;
}

From source file:org.codehaus.groovy.grails.scaffolding.SimpleDomainClassPropertyComparator.java

public int compare(Object o1, Object o2) {
    if (o1.equals(domainClass.getIdentifier())) {
        return -1;
    }//from  www.  j a v  a 2  s.c  o m
    if (o2.equals(domainClass.getIdentifier())) {
        return 1;
    }
    return 0;
}

From source file:org.businessmanager.web.converter.CountryConverterInput.java

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value == null || value.equals("")) {
        return "";
    }/*from  w w w . j  av a 2  s.c  o  m*/
    return value.toString();
}

From source file:com.inkubator.hrm.web.converter.PaySalaryComponentPickListConverter.java

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value == null || value.equals("")) {
        return null;
    }/*from   ww w  .j  a  v a2  s  .c o  m*/
    return String.valueOf(((PaySalaryComponent) value).getId());
}

From source file:egovframework.oe1.utl.fcc.service.EgovStringUtil.java

License:asdf

/**
 *<pre>//  w  w  w.  ja va  2s  .  co m
 * ?? ? String? null?  &quot;0&quot; .
 * &#064;param src null? ?  String .
 * &#064;return  String? null ?  &quot;0&quot;  String .
 *</pre>
 */
public static int zeroConvert(Object src) {

    if (src == null || src.equals("null"))
        return 0;
    else
        return Integer.parseInt(((String) src).trim());
}

From source file:com.inkubator.hrm.web.converter.CityConverter.java

@Override
public String getAsString(FacesContext contet, UIComponent component, Object value) {
    if (value == null || value.equals("")) {
        return null;
    }/*from  w  ww  . ja  v  a  2 s.c  o m*/
    return String.valueOf(((City) value).getId());
}

From source file:net.sf.dynamicreports.report.builder.condition.EqualExpression.java

@Override
public Boolean evaluate(ReportParameters reportParameters) {
    Object actualValue = reportParameters.getValue(value);
    for (Object value : values) {
        if (value.equals(actualValue)) {
            return true;
        }/*www . j a v  a2  s . c o  m*/
    }
    return false;
}