List of usage examples for java.lang Object equals
public boolean equals(Object obj)
From source file:com.xidu.framework.common.util.ObjectUtils.java
/** * Determine if the given objects are equal, returning <code>true</code> * if both are <code>null</code> or <code>false</code> if only one is * <code>null</code>.// w w w .j a v a 2 s . co m * <p> * Compares arrays with <code>Arrays.equals</code>, performing an * equality check based on the array elements rather than the array * reference. * * @param o1 * first Object to compare * @param o2 * second Object to compare * @return whether the given objects are equal * @see java.util.Arrays#equals */ public static boolean nullSafeEquals(Object o1, Object o2) { if (o1 == null || o2 == null) { return false; } if (o1.equals(o2)) { return true; } if (o1 instanceof Object[] && o2 instanceof Object[]) { return Arrays.equals((Object[]) o1, (Object[]) o2); } if (o1 instanceof boolean[] && o2 instanceof boolean[]) { return Arrays.equals((boolean[]) o1, (boolean[]) o2); } if (o1 instanceof byte[] && o2 instanceof byte[]) { return Arrays.equals((byte[]) o1, (byte[]) o2); } if (o1 instanceof char[] && o2 instanceof char[]) { return Arrays.equals((char[]) o1, (char[]) o2); } if (o1 instanceof double[] && o2 instanceof double[]) { return Arrays.equals((double[]) o1, (double[]) o2); } if (o1 instanceof float[] && o2 instanceof float[]) { return Arrays.equals((float[]) o1, (float[]) o2); } if (o1 instanceof int[] && o2 instanceof int[]) { return Arrays.equals((int[]) o1, (int[]) o2); } if (o1 instanceof long[] && o2 instanceof long[]) { return Arrays.equals((long[]) o1, (long[]) o2); } if (o1 instanceof short[] && o2 instanceof short[]) { return Arrays.equals((short[]) o1, (short[]) o2); } return false; }
From source file:com.hazelcast.config.ConfigCompatibilityChecker.java
private static boolean nullSafeEqual(Object a, Object b) { return (a == b) || (a != null && a.equals(b)); }
From source file:org.opentides.util.CrudUtil.java
/** * Returns the list of fields that have difference values or updated. * //w w w. ja v a2s .com * @param oldObject * @param newObject * @return */ public static List<String> getUpdatedFields(BaseEntity oldObject, BaseEntity newObject) { List<String> fields = CacheUtil.getPersistentFields(oldObject); List<String> updatedFields = new ArrayList<String>(); for (String field : fields) { Object oldValue = retrieveNullableObjectValue(oldObject, field); Object newValue = retrieveNullableObjectValue(newObject, field); oldValue = normalizeValue(oldValue); newValue = normalizeValue(newValue); if (!oldValue.equals(newValue)) { updatedFields.add(field); } } return updatedFields; }
From source file:org.springsource.ide.eclipse.commons.core.SpringCoreUtils.java
private static void scheduleBuildInBackground(final IProject project, ISchedulingRule rule, final Object[] jobFamilies, final String builderID) { Job job = new Job("Building workspace") { @Override//www . j a v a 2 s . c o m public boolean belongsTo(Object family) { if (jobFamilies == null || family == null) { return false; } for (Object jobFamilie : jobFamilies) { if (family.equals(jobFamilie)) { return true; } } return false; } @Override public IStatus run(IProgressMonitor monitor) { try { if (builderID != null) { project.build(IncrementalProjectBuilder.FULL_BUILD, builderID, null, monitor); } else { project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); } return Status.OK_STATUS; } catch (CoreException e) { return new Status(Status.ERROR, CorePlugin.PLUGIN_ID, 1, "Error during build of project [" + project.getName() + "]", e); } } }; if (rule != null) { job.setRule(rule); } job.setPriority(Job.BUILD); job.schedule(); }
From source file:cn.remex.core.util.ObjectUtils.java
/** * Determine if the given objects are equal, returning <code>true</code> * if both are <code>null</code> or <code>false</code> if only one is * <code>null</code>.// w w w . j av a 2 s .c o m * <p>Compares arrays with <code>Arrays.equals</code>, performing an equality * check based on the array elements rather than the array reference. * @param o1 first Object to compare * @param o2 second Object to compare * @return whether the given objects are equal * @see java.util.Arrays#equals */ public static boolean nullSafeEquals(final Object o1, final Object o2) { if (o1 == o2) { return true; } if (o1 == null || o2 == null) { return false; } if (o1.equals(o2)) { return true; } if (o1.getClass().isArray() && o2.getClass().isArray()) { if (o1 instanceof Object[] && o2 instanceof Object[]) { return Arrays.equals((Object[]) o1, (Object[]) o2); } if (o1 instanceof boolean[] && o2 instanceof boolean[]) { return Arrays.equals((boolean[]) o1, (boolean[]) o2); } if (o1 instanceof byte[] && o2 instanceof byte[]) { return Arrays.equals((byte[]) o1, (byte[]) o2); } if (o1 instanceof char[] && o2 instanceof char[]) { return Arrays.equals((char[]) o1, (char[]) o2); } if (o1 instanceof double[] && o2 instanceof double[]) { return Arrays.equals((double[]) o1, (double[]) o2); } if (o1 instanceof float[] && o2 instanceof float[]) { return Arrays.equals((float[]) o1, (float[]) o2); } if (o1 instanceof int[] && o2 instanceof int[]) { return Arrays.equals((int[]) o1, (int[]) o2); } if (o1 instanceof long[] && o2 instanceof long[]) { return Arrays.equals((long[]) o1, (long[]) o2); } if (o1 instanceof short[] && o2 instanceof short[]) { return Arrays.equals((short[]) o1, (short[]) o2); } } return false; }
From source file:Main.java
/** * Checks if both the Object arguments are equal (including if they are null) *//* w w w .j a v a 2s.c om*/ public static boolean areNullorEqual(Object obj1, Object obj2, boolean ignoreWhitespace, boolean ignoreCase) { // if both are null, they are equal if ((obj1 == null) && (obj2 == null)) return true; // if either one of them is null, they are not equal if ((obj1 == null) || (obj2 == null)) return false; // if they are String type if ((obj1 instanceof String) && (obj2 instanceof String)) { if (ignoreWhitespace) { if (ignoreCase) return ((String) obj1).trim().equalsIgnoreCase(((String) obj2).trim()); else return ((String) obj1).trim().equals(((String) obj2).trim()); } else { if (ignoreCase) return ((String) obj1).equalsIgnoreCase((String) obj2); else return obj1.equals(obj2); } } return (obj1.equals(obj2)); }
From source file:com.aw.support.collection.ListUtils.java
public static <E> List<E> getSubList(Collection<E> list, final String propertyName, final Object propertyValue) { return getSubList(list, new UnaryPredicate() { @Override/*from w ww . j a va 2 s . c o m*/ public boolean test(Object o) { BeanWrapper wrapper = new BeanWrapperImpl(o); return propertyValue.equals(wrapper.getPropertyValue(propertyName)); } }); }
From source file:simulation.AureoZauleckAnsLab2.java
public static ArrayList<ArrayList> Stratified(ArrayList ungrouped) { ArrayList<ArrayList> grouped = new ArrayList<>(); boolean[] isVisited = new boolean[ungrouped.size()]; for (int i = 0; i < ungrouped.size(); i++) { if (!(isVisited[i])) { Object current = ungrouped.get(i); grouped.add(new ArrayList()); ArrayList currList = grouped.get(grouped.size() - 1); currList.add(current);//from w ww .ja va2 s . c o m for (int j = i + 1; j < ungrouped.size(); j++) { Object next = ungrouped.get(j); if (next.equals(current)) { isVisited[j] = true; currList.add(next); } } } } return grouped; }
From source file:Main.java
public void actionPerformed(ActionEvent evt) { JComboBox cb = (JComboBox) evt.getSource(); Object newItem = cb.getSelectedItem(); boolean same = newItem.equals(oldItem); oldItem = newItem;//from ww w .j a va2s .c o m if ("comboBoxEdited".equals(evt.getActionCommand())) { // User has typed in a string; only possible with an editable combobox } else if ("comboBoxChanged".equals(evt.getActionCommand())) { // User has selected an item; it may be the same item } }
From source file:com.qmetry.qaf.automation.ui.selenium.AssertionService.java
/** * Compares two objects, but handles "regexp:" strings like HTML Selenese * //from w ww. j av a 2s . c om * @see #seleniumEquals(String, String) * @return true if actual matches the expectedPattern, or false otherwise */ public static boolean seleniumEquals(Object expected, Object actual) { if ((expected instanceof String) && (actual instanceof String)) { return seleniumEquals((String) expected, (String) actual); } return expected.equals(actual); }