List of usage examples for java.lang Object equals
public boolean equals(Object obj)
From source file:it.txt.ens.authorisationService.test.IntegrationTest.java
@Test public void test2() throws Exception { //configure and start the ENS ServiceReference<ConfigurationAdmin> configAdminSR = context.getServiceReference(ConfigurationAdmin.class); assertNotNull("No service reference found for " + ConfigurationAdmin.class.getName(), configAdminSR); ConfigurationAdmin configAdmin = context.getService(configAdminSR); assertNotNull("No instance found for " + ConfigurationAdmin.class.getName(), configAdminSR); File file = new File(System.getProperty(CONFIG_FILE_PROPERTY)); FileInputStream stream = new FileInputStream(file); Properties p = new Properties(); try {//from w w w.ja v a2s. co m p.load(stream); } finally { if (stream != null) stream.close(); } Dictionary<String, Object> prop = new Hashtable<String, Object>(p.size()); for (Object key : p.keySet()) { if (key.equals(PropertiesKeys.CONFIGURATION_FILE_PATH_ATTRIBUTE)) prop.put((String) key, p.getProperty((String) key)); else if (key.equals(PropertiesKeys.ENS_GUI_ATTRIBUTE)) prop.put((String) key, Boolean.parseBoolean(p.getProperty((String) key))); else if (key.equals(PropertiesKeys.THREAD_POOL_SIZE_ATTRIBUTE)) prop.put((String) key, Integer.parseInt(p.getProperty((String) key))); else continue; } Configuration config = configAdmin.getConfiguration(ENSAuthorisationServiceMS.SERVICE_PID); config.update(prop); Thread.sleep(60000); //delete the configuration config.delete(); }
From source file:com.haulmont.cuba.gui.data.impl.HierarchicalPropertyDatasourceImpl.java
@Override public boolean hasChildren(K itemId) { final Entity item = getItem(itemId); if (item == null) return false; if (hierarchyPropertyName != null) { for (T currentItem : getItems()) { Object parentItem = currentItem.getValue(hierarchyPropertyName); if (parentItem != null && parentItem.equals(item)) return true; }/* w ww.j a va2s . c o m*/ } return false; }
From source file:jp.techlier.extensions.velocity.directive.DirectiveHelper.java
public boolean booleanValue(final Node node) { if (node != null) { final Object value = node.value(context_); if (value != null) { return value.equals(Boolean.TRUE) || Boolean.parseBoolean(value.toString()); }/*from w ww . j a va2s .c o m*/ } return false; }
From source file:com.bstek.dorado.core.el.ExpressionUtilsObject.java
public Object defaultValue(Object value, Object defaultValue) { if (value == null || (value instanceof String && value.equals("")) || (value instanceof Number && ((Number) value).doubleValue() == 0) || (value instanceof Boolean && !((Boolean) value).booleanValue())) { return defaultValue; }// www . j a v a 2 s. co m return value; }
From source file:com.apptentive.android.sdk.util.JsonDiffer.java
public static JSONObject getDiff(JSONObject original, JSONObject updated) { JSONObject ret = new JSONObject(); Set<String> originalKeys = getKeys(original); Set<String> updatedKeys = getKeys(updated); Iterator<String> it = originalKeys.iterator(); while (it.hasNext()) { String key = it.next();//ww w . ja v a 2 s . co m updatedKeys.remove(key); try { Object oldValue = original.opt(key); Object newValue = updated.opt(key); if (isEmpty(oldValue)) { if (!isEmpty(newValue)) { // Old is empty. New is not. Update. ret.put(key, newValue); } } else if (isEmpty(newValue)) { // Old is not empty, but new is empty. Clear value. ret.put(key, JSONObject.NULL); } else if (oldValue instanceof JSONObject && newValue instanceof JSONObject) { // Diff JSONObjects if (!areObjectsEqual(oldValue, newValue)) { ret.put(key, newValue); } } else if (oldValue instanceof JSONArray && newValue instanceof JSONArray) { // Diff JSONArrays // TODO: At least check for strict equality. Right now, we always send nested JSONArrays. ret.put(key, newValue); } else if (!oldValue.equals(newValue)) { // Diff primitives ret.put(key, newValue); } else if (oldValue.equals(newValue)) { // Do nothing. } } catch (JSONException e) { Log.w("Error diffing object with key %s", e, key); } finally { it.remove(); } } // Finally, add in the keys that were added in the new object. it = updatedKeys.iterator(); while (it.hasNext()) { String key = it.next(); try { ret.put(key, updated.get(key)); } catch (JSONException e) { // This can't happen. } } // If there is no difference, return null. if (ret.length() == 0) { ret = null; } Log.v("Generated diff: %s", ret); return ret; }
From source file:graph.module.OntologyEdgeModule.java
/** * Gets all edges but the one given by the key. * /* w w w .j ava 2 s.c o m*/ * @param node * The edges must include this node. * @param butEdgeKey * The key that is NOT added to the results. * @return A collection of edges that are indexed by node, but none from the * butEdgeKey (though they may be added if included under other * keys). */ public Collection<Edge> getAllButEdges(Node node, Object butEdgeKey) { MultiMap<Object, Edge> indexedEdges = relatedEdges_.get(node); if (indexedEdges == null) { return new ConcurrentLinkedQueue<>(); } Collection<Edge> edges = new HashSet<>(); for (Object key : indexedEdges.keySet()) { if (!key.equals(butEdgeKey)) { // Need to check same function level as butEdge if (StringUtils.countMatches((String) key, FUNC_SPLIT) == StringUtils .countMatches((String) butEdgeKey, FUNC_SPLIT)) edges.addAll(indexedEdges.get(key)); } } return edges; }
From source file:com.scf.core.ebus.GuavaEventBusTest.java
@Test public void testAsyncEvent() { EventBusRepository.regGlobalBus(true); EventListener el = new EventListener(); EventBusRepository.getGlobalBus().addEventListener(el); Object e = "abc"; EventBusRepository.getGlobalBus().dispatchEvent(e); try {/*from w w w. j a v a 2s.c om*/ Thread.sleep(500); } catch (Exception ex) { } Assert.assertTrue(e.equals(el.testEvent)); EventBusRepository.getGlobalBus().dispatchEvent(123); EventBusRepository.unRegGlobalBus(); }
From source file:com.cloudera.livy.client.common.TestHttpMessages.java
private void checkEquals(String name, Field f, Object o1, Object o2) throws Exception { Object v1 = f.get(o1); Object v2 = f.get(o2);/*from www. j a v a 2 s . com*/ boolean match; if (!f.getType().isArray()) { match = v1.equals(v2); } else if (v1 instanceof byte[]) { match = Arrays.equals((byte[]) v1, (byte[]) v2); } else { throw new IllegalArgumentException("FIX ME: " + f.getType().getSimpleName()); } assertTrue(String.format("Field %s of %s does not match after deserialization.", f.getName(), name), match); }
From source file:org.jberet.support.io.XmlFactoryObjectFactory.java
/** * Gets an instance of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory} based on the resource configuration in the * application server. The parameter {@code environment} contains XmlFactory configuration properties, and accepts * the following properties:/*from w w w. j a v a 2 s .c o m*/ * <ul> * <li>inputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.InputDecorator} * <li>outputDecorator: fully-qualified name of a class that extends {@code com.fasterxml.jackson.core.io.OutputDecorator} * <li>xmlTextElementName: * <li>defaultUseWrapper: * </ul> * * @param obj the JNDI name of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory} resource * @param name always null * @param nameCtx always null * @param environment a {@code Hashtable} of configuration properties * @return an instance of {@code com.fasterxml.jackson.dataformat.xml.XmlFactory} * @throws Exception any exception occurred */ @Override public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable<?, ?> environment) throws Exception { XmlFactory xmlFactory = xmlFactoryCached; if (xmlFactory == null) { synchronized (this) { xmlFactory = xmlFactoryCached; if (xmlFactory == null) { xmlFactoryCached = xmlFactory = new XmlFactory(); } JacksonXmlModule xmlModule = null; NoMappingJsonFactoryObjectFactory.configureInputDecoratorAndOutputDecorator(xmlFactory, environment); final Object xmlTextElementName = environment.get("xmlTextElementName"); if (xmlTextElementName != null) { xmlModule = new JacksonXmlModule(); xmlModule.setXMLTextElementName((String) xmlTextElementName); } final Object defaultUseWrapper = environment.get("defaultUseWrapper"); if (defaultUseWrapper != null) { if (defaultUseWrapper.equals("false")) { if (xmlModule == null) { xmlModule = new JacksonXmlModule(); } xmlModule.setDefaultUseWrapper(false); } else if (defaultUseWrapper.equals("true")) { //default value is already true, so nothing to do } else { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, (String) defaultUseWrapper, "defaultUseWrapper"); } } final XmlMapper xmlMapper = xmlModule == null ? new XmlMapper(xmlFactory) : new XmlMapper(xmlFactory, xmlModule); xmlFactory.setCodec(xmlMapper); } } return xmlFactory; }
From source file:constraints.FieldMatchValidator.java
@Override public boolean isValid(final Object value, final ConstraintValidatorContext context) { try {//www .j a v a 2 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 Exception ignore) { // ignore } return true; }