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:org.apache.streams.rss.provider.RssEventProcessor.java

@Override
public void run() {

    while (true) {
        Object item;
        try {//w w  w . j  ava  2s  .  c om
            item = inQueue.poll();
            if (item instanceof String && item.equals(TERMINATE)) {
                LOGGER.info("Terminating!");
                break;
            }

            Thread.sleep(new Random().nextInt(100));

            // if the target is string, just pass-through
            if (String.class.equals(outClass))
                outQueue.offer(new StreamsDatum(item.toString()));
            else if (SyndEntry.class.equals(outClass)) {
                outQueue.offer(new StreamsDatum(item));
            } else if (Activity.class.equals(outClass)) {
                // convert to desired format
                SyndEntry entry = (SyndEntry) item;
                if (entry != null) {
                    Activity out = syndEntryActivitySerializer
                            .deserialize(this.syndEntrySerializer.deserialize((SyndEntry) item));

                    if (out != null)
                        outQueue.offer(new StreamsDatum(out));
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:it.unibas.spicygui.controllo.spicy.ActionFindConfidenceMappings.java

@Override
public void update(Observable o, Object stato) {
    if (stato.equals(LastActionBean.CREATE_CANDIDATE)) {
        this.setEnabled(true);
    } else if (stato.equals(LastActionBean.CLOSE)) {
        this.setEnabled(false);
    }/*from   w  w w  .j  a v  a 2  s .  c  o  m*/
}

From source file:net.nullschool.grains.jackson.datatype.GrainSerializer.java

private void serializeProperty(PropertyWriter writer, Grain grain, JsonGenerator jgen,
        SerializerProvider provider) throws IOException {

    String key = writer.name;/*from w ww . j a v  a2 s .c o m*/
    Object value = grain.get(key);
    if (value != null && !value.equals(defaultValue.get(key))) {
        // This property's value is not the default value, so write it to the stream.
        jgen.writeFieldName(key);
        writer.serializer.serialize(value, jgen, provider);
    }
}

From source file:org.everit.osgi.webconsole.tests.GetConfigurationTest.java

private DisplayedAttribute buildAttributeFromJSON(final JSONObject jsonAttr) {
    DisplayedAttribute rval = new DisplayedAttribute();
    rval.setId(jsonAttr.getString("id"));
    rval.setName(jsonAttr.getString("name"));
    rval.setDescription(jsonAttr.getString("description"));
    JSONObject jsonType = jsonAttr.getJSONObject("type");
    if ("unbound".equals(jsonType.get("maxOccurences"))) {
        rval.setMaxOccurences(Integer.MAX_VALUE);
    } else {/*from www  . j a  v  a 2 s .  com*/
        rval.setMaxOccurences(jsonType.getInt("maxOccurences"));
    }
    Object jsonBaseType = jsonType.get("baseType");
    if (jsonBaseType.equals("service")) {
        rval.setToService();
    } else {
        rval.setType(typeNameToCode.get(jsonBaseType));
    }
    if (jsonType.has("options")) {
        JSONObject jsonOptions = jsonType.getJSONObject("options");
        for (Object rawOptValue : jsonOptions.keySet()) {
            String optLabel = (String) rawOptValue;
            String optValue = jsonOptions.getString(optLabel);
            rval.addOption(optLabel, optValue);
        }
    }
    JSONArray jsonValue = jsonAttr.getJSONArray("value");
    String[] values = new String[jsonValue.length()];
    for (int i = 0; i < jsonValue.length(); ++i) {
        values[i] = jsonValue.get(i).toString();
    }
    rval.setValue(values);
    return rval;
}

From source file:SimpleSet.java

public boolean add(Object element) {
    if (element == null)
        throw new NullPointerException();

    for (int i = 0; i < count; i++) {
        if (element.equals(elementObjects[i]))
            return false;
    }/*from ww w .j a va2 s . c  o m*/

    if (count == elementObjects.length) {
        Object[] newArray = new Object[(count + 1) * 3 / 2];
        System.arraycopy(elementObjects, 0, newArray, 0, count);
        elementObjects = newArray;
    }
    elementObjects[count++] = element;
    return true;
}

From source file:com.rmn.qa.AutomationCapabilityMatcher.java

@Override
public boolean matches(Map<String, Object> nodeCapability, Map<String, Object> requestedCapability) {
    // First we need to check any additional capabilities that may exist in the requested set.  We're iterating over
    // additionalConsiderations as its likely to be a smaller collection for now than the requestedCapabilities
    for (String s : additionalConsiderations) {
        Object requestedCapabilityValue = requestedCapability.get(s);
        if (requestedCapabilityValue != null) {
            if (!requestedCapabilityValue.equals(nodeCapability.get(s))) {
                return false;
            }//www.  j a  v  a  2 s  .  c om
        }
    }
    // If neither expected config value exists, go ahead and default to the default matching behavior
    // as this node is most likely not a dynamically started node
    if (!nodeCapability.containsKey(AutomationConstants.INSTANCE_ID)) {
        return super.matches(nodeCapability, requestedCapability);
    }
    String instanceId = (String) nodeCapability.get(AutomationConstants.INSTANCE_ID);
    AutomationRunContext context = AutomationContext.getContext();
    // If the run that spun up these hubs is still happening, just perform the default matching behavior
    // as that run is the one that requested these nodes.
    AutomationDynamicNode node = context.getNode(instanceId);
    if (node != null && (node.getStatus() == AutomationDynamicNode.STATUS.EXPIRED
            || node.getStatus() == AutomationDynamicNode.STATUS.TERMINATED)) {
        log.debug(String.format("Node [%s] will not be used to match a request as it is expired/terminated",
                instanceId));
        // If the run that spun these hubs up is not in progress AND this node has been flagged to shutdown,
        // do not match this node up to fulfill a test request
        return false;
    } else {
        // If the node couldn't be retrieved or was not expired/terminated, then we should just use the default matching behavior
        return super.matches(nodeCapability, requestedCapability);
    }
}

From source file:com.l2jfree.sql.L2DBEntity.java

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;

    if (obj == null)
        return false;

    if (!(obj instanceof L2DBEntity))
        return false;

    final L2DBEntity other = (L2DBEntity) obj;

    if (getClassForEqualsCheck() != other.getClassForEqualsCheck())
        return false;

    final Object pk1 = getPrimaryKey();
    final Object pk2 = other.getPrimaryKey();

    return pk1 == null ? pk2 == null : pk1.equals(pk2);
}

From source file:ListOfLists.java

public int lastIndexOf(Object o) {
    ListIterator e = listIterator(size());
    if (o == null) {
        while (e.hasPrevious()) {
            if (e.previous() == null)
                return e.nextIndex();
        }//from   w  ww . j  a v  a2  s  . c o  m
    } else {
        Object el;
        while (e.hasPrevious()) {
            el = e.previous();
            if (el != null && el.equals(o))
                return e.nextIndex();
        }
    }
    return -1;
}

From source file:io.cloudslang.lang.tools.build.tester.parallel.services.TestCaseEventDispatchServiceTest.java

@Test
public void notifyListenersAllEventTypes() throws InterruptedException {
    final MutableInt mutableInt = new MutableInt(0);
    final MutableBoolean mutableBoolean = new MutableBoolean(false);
    final String failureMessage = "message";
    final RuntimeException ex = new RuntimeException("ex");

    ISlangTestCaseEventListener listenerIncrement = new ISlangTestCaseEventListener() {
        @Override//from  ww w.jav a2  s . co m
        public synchronized void onEvent(SlangTestCaseEvent event) {
            mutableInt.increment();
            Object value = mutableInt.getValue();
            if (value.equals(1)) {
                assertEquals(BeginSlangTestCaseEvent.class, event.getClass());
            } else if (value.equals(2)) {
                assertEquals(FailedSlangTestCaseEvent.class, event.getClass());
                assertEquals(failureMessage, ((FailedSlangTestCaseEvent) event).getFailureReason());
                assertEquals(ex, ((FailedSlangTestCaseEvent) event).getFailureException());
            } else if (value.equals(3)) {
                assertEquals(PassedSlangTestCaseEvent.class, event.getClass());
            } else if (value.equals(4)) {
                assertEquals(SkippedSlangTestCaseEvent.class, event.getClass());
            } else if (value.equals(5)) {
                assertEquals(SlangTestCaseEvent.class, event.getClass());
                mutableBoolean.setValue(true);
            }
        }
    };

    TestCaseEventDispatchService localTestCaseEventDispatchService = new TestCaseEventDispatchService();
    localTestCaseEventDispatchService.initializeListeners();
    localTestCaseEventDispatchService.registerListener(listenerIncrement);

    SlangTestCase testCase = new SlangTestCase("name", null, null, null, null, null, null, null, null);
    localTestCaseEventDispatchService.notifyListeners(new BeginSlangTestCaseEvent(testCase));
    localTestCaseEventDispatchService
            .notifyListeners(new FailedSlangTestCaseEvent(testCase, failureMessage, ex));
    localTestCaseEventDispatchService.notifyListeners(new PassedSlangTestCaseEvent(testCase));
    localTestCaseEventDispatchService.notifyListeners(new SkippedSlangTestCaseEvent(testCase));
    localTestCaseEventDispatchService.notifyListeners(new SlangTestCaseEvent(testCase));

    while (mutableBoolean.isFalse()) {
        Thread.sleep(50);
    }
    // Checks that all listeners are called, order is not important
    assertEquals(5, mutableInt.getValue());
}

From source file:org.openmrs.module.mdrtb.web.controller.MdrtbHomePageController.java

@SuppressWarnings("unchecked")
@RequestMapping("/module/mdrtb/mdrtbIndex")
public void viewHomePage(ModelMap model) {

    if (Context.isAuthenticated()) {

        Map<String, String> reports = new LinkedHashMap<String, String>();

        // Load any configured BIRT reports
        if (ModuleFactory.getStartedModulesMap().containsKey("birt")) {
            String str = Context.getAdministrationService().getGlobalProperty("mdrtb.birt_report_list");
            if (StringUtils.isNotEmpty(str)) {
                String birtPrefix = "module/birt/generateReport.form?reportId=";
                try {
                    Class birtServiceClass = OpenmrsClassLoader.getInstance()
                            .loadClass("org.openmrs.module.birt.BirtReportService");
                    Object reportService = Context.getService(birtServiceClass);
                    Method getReportsMethod = birtServiceClass.getDeclaredMethod("getReports");
                    Class birtReportClass = OpenmrsClassLoader.getInstance()
                            .loadClass("org.openmrs.module.birt.BirtReport");
                    Method getNameMethod = birtReportClass.getDeclaredMethod("getName");
                    Method getIdMethod = birtReportClass.getDeclaredMethod("getReportId");

                    List allReports = (List) getReportsMethod.invoke(reportService);
                    for (StringTokenizer st = new StringTokenizer(str, "|"); st.hasMoreTokens();) {
                        String s = st.nextToken().trim();
                        for (Object br : allReports) {
                            Object id = getIdMethod.invoke(br);
                            Object name = getNameMethod.invoke(br);
                            if (name.equals(s) || id.equals(s)) {
                                reports.put(birtPrefix + id, name.toString());
                            }// w ww  .ja va  2  s  .co  m
                        }
                    }
                } catch (Exception ex) {
                    log.error("Unable to setup birt reports in reference data in MdrtbFormController.", ex);
                }
            }
        }

        // Load default reporting framework reports
        ReportSpecification[] rpts = { new WHOForm05(), new WHOForm06(), new WHOForm07(), new OutcomeReport(),
                new MOHReport() };
        for (ReportSpecification spec : rpts) {
            reports.put("module/mdrtb/reporting/reports.form?type=" + spec.getClass().getName(),
                    spec.getName());
        }

        model.addAttribute("reports", reports);

        // add the specimen and resistance profiles
        reports.put("module/mdrtb/specimen/specimenReportsOverview.form",
                Context.getMessageSourceService().getMessage("mdrtb.specimenReports"));
        reports.put("module/mdrtb/specimen/labResultsReports.form",
                Context.getMessageSourceService().getMessage("mdrtb.resistanceProfiles"));

        // Load patient lists
        List<Location> patientLocations = Context.getService(MdrtbService.class)
                .getLocationsWithAnyProgramEnrollments();
        model.addAttribute("patientLocations", patientLocations);

        Map<String, String> patientLists = new LinkedHashMap<String, String>();
        patientLists.put("mdrtb.activePatients",
                "module/mdrtb/mdrtbListPatients.form?displayMode=mdrtbShortSummary&enrollment=current");
        model.addAttribute("patientLists", patientLists);

        // Link to Cohort Builder, if reporting compatibility is installed
        boolean rcStarted = ModuleFactory.getStartedModulesMap().containsKey("reportingcompatibility");
        model.addAttribute("showCohortBuilder", rcStarted);
    }
}