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:CopyOnWriteArrayList.java

/**
 * Test for equality, coping with nulls.
 *///from w  w w .  ja  v a  2  s. c o m
private static boolean eq(Object o1, Object o2) {
    return (o1 == null ? o2 == null : o1.equals(o2));
}

From source file:com.blackducksoftware.integration.eclipseplugin.internal.listeners.NewJavaProjectListener.java

@Override
public void resourceChanged(final IResourceChangeEvent event) {
    if (event.getSource() != null && event.getSource().equals(ResourcesPlugin.getWorkspace())
            && event.getDelta() != null) {
        final IResourceDelta[] childrenDeltas = event.getDelta().getAffectedChildren();
        if (childrenDeltas != null) {
            for (final IResourceDelta delta : childrenDeltas) {
                if (delta.getKind() == IResourceDelta.ADDED || delta.getKind() == IResourceDelta.CHANGED) {
                    if (delta.getResource() != null) {
                        final IResource resource = delta.getResource();
                        try {
                            if (resource instanceof IProject
                                    && ((IProject) resource).hasNature(JavaCore.NATURE_ID)) {
                                final String projectName = resource.getName();
                                service.setAllProjectSpecificDefaults(projectName);
                                Job inspectionJob = null;
                                if ((delta.getFlags() | IResourceDelta.MOVED_FROM) != 0
                                        && delta.getMovedFromPath() != null) {
                                    String[] movedFromPath = delta.getMovedFromPath().toOSString()
                                            .split(StringEscapeUtils.escapeJava(File.separator));
                                    String oldProjectName = movedFromPath[movedFromPath.length - 1];
                                    inspectionJob = information.createInspection(projectName, true);
                                    if (service.isActivated(oldProjectName)) {
                                        service.activateProject(projectName);
                                    }/*  w  w w .  java 2  s .  c om*/
                                } else {
                                    inspectionJob = information.createInspection(projectName, true);
                                }
                                if (inspectionJob != null) {
                                    final Job delayedInspection = inspectionJob;
                                    Job delayer = new Job(DELAYED_INSPECTION_JOB_PREFIX + projectName) {
                                        @Override
                                        public boolean belongsTo(Object family) {
                                            return family.equals(DELAYED_INSPECTION_JOB);
                                        }

                                        @Override
                                        protected IStatus run(IProgressMonitor monitor) {
                                            IJobManager jobMan = Job.getJobManager();
                                            Job[] delayedInspections = jobMan.find(DELAYED_INSPECTION_JOB);
                                            for (Job delayedInspection : delayedInspections) {
                                                if (delayedInspection.getName().equals(this.getName())) {
                                                    // Kill stale jobs
                                                    delayedInspection.cancel();
                                                }
                                            }
                                            Job[] inspections = jobMan
                                                    .find(ProjectDependencyInformation.INSPECTION_JOB);
                                            monitor.setTaskName("Waiting for active inspection to finish");
                                            while (inspections.length > 0) {
                                                try {
                                                    inspections[0].join();
                                                } catch (InterruptedException e) {
                                                    // Do nothing, a missed scan is nbd
                                                }
                                                inspections = jobMan
                                                        .find(ProjectDependencyInformation.INSPECTION_JOB);
                                            }
                                            delayedInspection.schedule();
                                            return Status.OK_STATUS;
                                        }
                                    };
                                    delayer.schedule();
                                }
                            }
                        } catch (final CoreException e) {
                            /*
                             * If error is thrown when calling hasNature(), then assume it isn't a Java
                             * project and therefore don't do anything
                             */
                        }
                    }
                }
            }
        }
    }
}

From source file:com.ensa.form.constraints.impl.FieldMatchValidator.java

@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
    try {/*from  w  ww. j  av  a2  s . c o m*/
        final Object firstObj = BeanUtils.getProperty(value, firstFieldName);
        final Object secondObj = BeanUtils.getProperty(value, secondFieldName);

        return firstObj == null && secondObj == null || firstObj != null && firstObj.equals(secondObj);
    } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException ignore) {
        // ignore
    }
    return true;
}

From source file:net.meltdowntech.steamstats.SteamUser.java

public void fetchLevel() {
    try {//from  w  ww . j  a  v  a2 s. co m
        String url = String.format("http://steamcommunity.com/profiles/%s/badges", getCommunityId() + "");
        URL steam = new URL(url);
        URLConnection yc = steam.openConnection();
        Reader reader = new InputStreamReader(yc.getInputStream());
        HTMLEditorKit.Parser parser = new ParserDelegator();
        parser.parse(reader, new HTMLEditorKit.ParserCallback() {
            private boolean foundIt;

            @Override
            public void handleText(char[] data, int pos) {
                if (foundIt)
                    values.put("level", Integer.parseInt(new String(data)));
            }

            @Override
            public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
                if (t == HTML.Tag.SPAN) {
                    Object o = a.getAttribute(HTML.Attribute.CLASS);
                    if (o != null && o.equals("friendPlayerLevelNum"))
                        foundIt = true;
                }
            }

            @Override
            public void handleEndTag(HTML.Tag t, int pos) {
                if (t == HTML.Tag.SPAN)
                    foundIt = false;
            }
        }, true);

    } catch (IOException ex) {
        Util.printError("Invalid data");
    }
}

From source file:ch.puzzle.itc.mobiliar.presentation.deploy.LogView.java

private boolean isParameterSet(String key, Object value) {
    Object existing = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
    return existing != null && existing.equals(value);
}

From source file:com.couchbase.lite.store.SQLiteViewStore.java

/**
 * Are key1 and key2 grouped together at this groupLevel?
 *///from   w ww. j a  v a  2 s .c o  m
private static boolean groupTogether(Object key1, Object key2, int groupLevel) {
    if (groupLevel == 0 || !(key1 instanceof List) || !(key2 instanceof List)) {
        return key1.equals(key2);
    }
    @SuppressWarnings("unchecked")
    List<Object> key1List = (List<Object>) key1;
    @SuppressWarnings("unchecked")
    List<Object> key2List = (List<Object>) key2;

    // if either key list is smaller than groupLevel and the key lists are different
    // sizes, they cannot be equal.
    if ((key1List.size() < groupLevel || key2List.size() < groupLevel) && key1List.size() != key2List.size()) {
        return false;
    }

    int end = Math.min(groupLevel, Math.min(key1List.size(), key2List.size()));
    for (int i = 0; i < end; ++i) {
        if (!key1List.get(i).equals(key2List.get(i))) {
            return false;
        }
    }
    return true;
}

From source file:com.tonbeller.wcf.convert.SelectConverterBase.java

/**
 * @see com.tonbeller.wcf.convert.NodeConverter#convert(Formatter, Object, Element)
 */// w w  w.j  a  v  a2 s. co m
public void convert(Formatter fmt, Object bean, Element elem)
        throws ConvertException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    // no model reference? nothing to do
    String modelReference = Select.getModelReference(elem);
    if (modelReference.length() == 0)
        return;

    // get a formatter
    String type = Select.getType(elem);
    String formatString = Select.getFormatString(elem);
    FormatHandler handler = fmt.getHandler(type);
    if (handler == null)
        throw new FormatException("no handler found for type: " + type);

    // retrieve values from the bean property
    Object o = PropertyUtils.getProperty(bean, modelReference);
    Object[] values = handler.toObjectArray(o);
    if (values == null)
        values = new Object[0];

    // deselect all items
    List items = Select.getItems(elem);
    for (Iterator it = items.iterator(); it.hasNext();)
        Item.setSelected((Element) it.next(), false);

    // for each value, find the corresponding item and select it
    for (int i = 0; i < values.length; i++) {
        Object beanValue = values[i];
        boolean found = false;
        search: for (Iterator it = items.iterator(); it.hasNext();) {
            Element item = (Element) it.next();
            Object itemValue = handler.parse(Item.getValue(item), formatString);
            if (itemValue.equals(beanValue)) {
                Item.setSelected(item, true);
                found = true;
                break search;
            }
        }
        if (!found) {
            String mesg = "No item has a value of \"" + beanValue + "\".";
            showMissing(elem, mesg);
        }
    }
}

From source file:it.unibas.spicygui.controllo.mapping.ActionGenerateAndTranslate.java

public void update(Observable o, Object stato) {
    if (stato.equals(LastActionBean.CLOSE) || (stato.equals(LastActionBean.SOLVE))
            || (stato.equals(LastActionBean.NO_SCENARIO_SELECTED))) {
        this.setEnabled(false);
    } else {//  w  w  w  .j  a v a 2  s . co  m
        this.setEnabled(true);
    }
}

From source file:es.tunelator.log.Logger.java

/**
 * @see es.tunelator.vo.DataListener#dataChanged(java.lang.Object)
 *//*from  ww w  .  ja v  a 2  s  . c o  m*/
public void dataChanged(Object source, Object data) {
    if (data.equals(AppParameters.getParams())) {
        setLogThreshold();
    }
}

From source file:com.archive.spring.form.constraint.FieldMatchValidator.java

@Override
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
    try {/*ww w.j  a v a 2  s . c  om*/
        final Object firstObj = BeanUtils.getProperty(value, firstFieldName);
        final Object secondObj = BeanUtils.getProperty(value, secondFieldName);

        return firstObj == null && secondObj == null || firstObj != null && firstObj.equals(secondObj);
    } catch (final IllegalAccessException e) {
        Logger.getLogger(FieldMatchValidator.class.getName()).log(Level.SEVERE, null, e);
    } catch (InvocationTargetException ex) {
        Logger.getLogger(FieldMatchValidator.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchMethodException ex) {
        Logger.getLogger(FieldMatchValidator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return true;
}