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:com.subakva.formicid.converters.FileSetConverter.java

public FileSet convert(Class type, Object value) {
    if (value == null || value.equals(Undefined.instance)) {
        throw new ConversionException("No value specified");
    }//w w  w .j  a v a  2s  .  c o m
    if (value instanceof FileSet) {
        return (FileSet) value;
    } else if (value instanceof Scriptable) {
        FileSet fileSet = (FileSet) container.getProject().createDataType("fileset");
        Scriptable options = (Scriptable) value;
        Object[] ids = options.getIds();
        for (int i = 0; i < ids.length; i++) {
            String id = (String) ids[i];
            Object val = options.get(id, options);
            try {
                PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(fileSet, id);
                Class<?> propertyType = descriptor.getPropertyType();
                Converter converter = container.getConverter(propertyType);
                Object converted = converter.convert(propertyType, val);
                PropertyUtils.setProperty(fileSet, id, converted);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new RuntimeException(e);
            } catch (NoSuchMethodException e) {
                throw new RuntimeException(e);
            }
        }
        return fileSet;
    } else if (value instanceof String) {
        FileSet fileSet = (FileSet) container.getProject().createDataType("fileset");
        fileSet.setDir(new File("."));
        FilenameSelector selector = new FilenameSelector();
        selector.setName((String) value);
        fileSet.add(selector);
        return fileSet;
    } else {
        throw new ConversionException("" + value);
    }
}

From source file:jp.sourceforge.reflex.core.XML.java

/**
 * Scan the content following the named tag, attaching it to the context.
 * //from   w  ww.ja  va 2  s.c o  m
 * @param x
 *            The XMLTokener containing the source string.
 * @param context
 *            The JSONObject that will include the new material.
 * @param name
 *            The tag name.
 * @return true if the close tag is processed.
 * @throws JSONException
 */
private static boolean parse(XMLTokener x, JSONObject context, String name) throws JSONException {
    char c;
    int i;
    String n;
    JSONObject o = null;
    String s;
    Object t;

    // Test for and skip past these forms:
    // <!-- ... -->
    // <! ... >
    // <![ ... ]]>
    // <? ... ?>
    // Report errors for these forms:
    // <>
    // <=
    // <<

    t = x.nextToken();

    // <!

    if (t == BANG) {
        c = x.next();
        if (c == '-') {
            if (x.next() == '-') {
                x.skipPast("-->");
                return false;
            }
            x.back();
        } else if (c == '[') {
            t = x.nextToken();
            if (t.equals("CDATA")) {
                if (x.next() == '[') {
                    s = x.nextCDATA();
                    if (s.length() > 0) {
                        context.accumulate("content", s);
                    }
                    return false;
                }
            }
            throw x.syntaxError("Expected 'CDATA['");
        }
        i = 1;
        do {
            t = x.nextMeta();
            if (t == null) {
                throw x.syntaxError("Missing '>' after '<!'.");
            } else if (t == LT) {
                i += 1;
            } else if (t == GT) {
                i -= 1;
            }
        } while (i > 0);
        return false;
    } else if (t == QUEST) {

        // <?

        x.skipPast("?>");
        return false;
    } else if (t == SLASH) {

        // Close tag </

        t = x.nextToken();
        if (name == null) {
            throw x.syntaxError("Mismatched close tag" + t);
        }
        if (!t.equals(name)) {
            throw x.syntaxError("Mismatched " + name + " and " + t);
        }
        if (x.nextToken() != GT) {
            throw x.syntaxError("Misshaped close tag");
        }
        return true;

    } else if (t instanceof Character) {
        throw x.syntaxError("Misshaped tag");

        // Open tag <

    } else {
        n = (String) t;
        t = null;
        o = new JSONObject();
        for (;;) {
            if (t == null) {
                t = x.nextToken();
            }

            // attribute = value

            if (t instanceof String) {
                s = (String) t;
                t = x.nextToken();
                if (t == EQ) {
                    t = x.nextToken();
                    if (!(t instanceof String)) {
                        throw x.syntaxError("Missing value");
                    }
                    o.accumulate(s, t);
                    t = null;
                } else {
                    o.accumulate(s, "");
                }

                // Empty tag <.../>

            } else if (t == SLASH) {
                if (x.nextToken() != GT) {
                    throw x.syntaxError("Misshaped tag");
                }
                context.accumulate(n, o);
                return false;

                // Content, between <...> and </...>

            } else if (t == GT) {
                for (;;) {
                    t = x.nextContent();
                    if (t == null) {
                        if (n != null) {
                            throw x.syntaxError("Unclosed tag " + n);
                        }
                        return false;
                    } else if (t instanceof String) {
                        s = (String) t;
                        if (s.length() > 0) {
                            o.accumulate("content", s);
                        }

                        // Nested element

                    } else if (t == LT) {
                        if (parse(x, o, n)) {
                            if (o.length() == 0) {
                                context.accumulate(n, "");
                            } else if (o.length() == 1 && o.opt("content") != null) {
                                context.accumulate(n, o.opt("content"));
                            } else {
                                context.accumulate(n, o);
                            }
                            return false;
                        }
                    }
                }
            } else {
                throw x.syntaxError("Misshaped tag");
            }
        }
    }
}

From source file:ReflectUtil.java

/**
 * <p>A better (more concise) toString method for annotation types that yields a String
 * that should look more like the actual usage of the annotation in a class. The String produced
 * is similar to that produced by calling toString() on the annotation directly, with the
 * following differences:</p>//from   w  ww . ja  v a2  s.c o m
 *
 * <ul>
 *   <li>Uses the classes simple name instead of it's fully qualified name.</li>
 *   <li>Only outputs attributes that are set to non-default values.</li>
 *
 * <p>If, for some unforseen reason, an exception is thrown within this method it will be
 * caught and the return value will be {@code ann.toString()}.
 *
 * @param ann the annotation to convert to a human readable String
 * @return a human readable String form of the annotation and it's attributes
 */
public static String toString(Annotation ann) {
    try {
        Class<? extends Annotation> type = ann.annotationType();
        StringBuilder builder = new StringBuilder(128);
        builder.append("@");
        builder.append(type.getSimpleName());

        boolean appendedAnyParameters = false;
        Method[] methods = type.getMethods();
        for (Method method : methods) {
            if (!INHERITED_ANNOTATION_METHODS.contains(method.getName())) {
                Object defaultValue = method.getDefaultValue();
                Object actualValue = method.invoke(ann);

                // If we have arrays, they have to be treated a little differently
                Object[] defaultArray = null, actualArray = null;
                if (Object[].class.isAssignableFrom(method.getReturnType())) {
                    defaultArray = (Object[]) defaultValue;
                    actualArray = (Object[]) actualValue;
                }

                // Only print an attribute if it isn't set to the default value
                if ((defaultArray != null && !Arrays.equals(defaultArray, actualArray))
                        || (defaultArray == null && !actualValue.equals(defaultValue))) {

                    if (appendedAnyParameters) {
                        builder.append(", ");
                    } else {
                        builder.append("(");
                    }

                    builder.append(method.getName());
                    builder.append("=");

                    if (actualArray != null) {
                        builder.append(Arrays.toString(actualArray));
                    } else {
                        builder.append(actualValue);
                    }

                    appendedAnyParameters = true;
                }
            }
        }

        if (appendedAnyParameters) {
            builder.append(")");
        }

        return builder.toString();
    } catch (Exception e) {
        return ann.toString();
    }
}

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

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

From source file:Main.java

public int selectionForKey(char aKey, ComboBoxModel model) {
    int selIx = 01;
    Object sel = model.getSelectedItem();
    if (sel != null) {
        for (int i = 0; i < model.getSize(); i++) {
            if (sel.equals(model.getElementAt(i))) {
                selIx = i;/*from  w w w  .j a v  a  2s.com*/
                break;
            }
        }
    }
    long curTime = System.currentTimeMillis();
    if (curTime - lastKeyTime < 300) {
        pattern += ("" + aKey).toLowerCase();
    } else {
        pattern = ("" + aKey).toLowerCase();
    }
    lastKeyTime = curTime;
    for (int i = selIx + 1; i < model.getSize(); i++) {
        String s = model.getElementAt(i).toString().toLowerCase();
        if (s.startsWith(pattern)) {
            return i;
        }
    }
    for (int i = 0; i < selIx; i++) {
        if (model.getElementAt(i) != null) {
            String s = model.getElementAt(i).toString().toLowerCase();
            if (s.startsWith(pattern)) {
                return i;
            }
        }
    }
    return -1;
}

From source file:com.seyren.api.bean.UsermanagementBean.java

@Override
public Response getUser() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    Object principal = authentication.getPrincipal();
    if (principal instanceof String && principal.equals("anonymousUser")) {
        throw new WebApplicationException(401);
    }// w  ww.  java 2s .c  o m
    UserDetails userDetails = (UserDetails) principal;

    return Response.ok(userDetails).build();
}

From source file:it.unibas.spicygui.controllo.datasource.ActionAddTargetInstanceXml.java

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

        this.setEnabled(true);
    }
}

From source file:com.brightcove.com.uploader.verifier.RetrieveJSONResponseforVideo.java

public ArrayList<Object> getCustomFields() {
    ArrayList<Object> metadata = getMetaData("customFields");
    ArrayList<Object> customFields = new ArrayList<Object>();
    for (Object customField : metadata) {
        if (!customField.equals("null")) {
            JsonNode node = (JsonNode) customField;
            RetrieveJSONNodeHelper helper = new RetrieveJSONNodeHelper(node);
            customFields.addAll(helper.retrieveAllMetaDataFromJSONResponse());
        }/*from ww  w .  ja  v  a  2 s .  co  m*/
    }
    return customFields;
}

From source file:com.evolveum.midpoint.web.util.WebMiscUtil.java

public static DropDownChoicePanel createEnumPanel(final PrismPropertyDefinition def, String id,
        final IModel model, final Component component) {
    // final Class clazz = model.getObject().getClass();
    final Object o = model.getObject();

    final IModel<List<DisplayableValue>> enumModelValues = new AbstractReadOnlyModel<List<DisplayableValue>>() {
        @Override//w ww. ja va 2s  .co m
        public List<DisplayableValue> getObject() {
            List<DisplayableValue> values = null;
            if (def.getAllowedValues() != null) {
                values = new ArrayList<>(def.getAllowedValues().size());
                for (Object v : def.getAllowedValues()) {
                    if (v instanceof DisplayableValue) {
                        values.add(((DisplayableValue) v));
                    }
                }
            }
            return values;
        }

    };

    return new DropDownChoicePanel(id, model, enumModelValues, new IChoiceRenderer() {

        @Override
        public Object getDisplayValue(Object object) {
            if (object instanceof DisplayableValue) {
                return ((DisplayableValue) object).getLabel();
            }
            for (DisplayableValue v : enumModelValues.getObject()) {
                if (object.equals(v.getValue())) {
                    return v.getLabel();
                }
            }
            return object;

        }

        @Override
        public String getIdValue(Object object, int index) {
            if (object instanceof DisplayableValue) {
                return ((DisplayableValue) object).getValue().toString();
            }
            return object.toString();
            //                  for (DisplayableValue v : enumModelValues.getObject()){
            //                     if (object.equals(v.getValue())){
            //                        return v.getLabel();
            //                     }
            //                  }
            //                  return object.getValue().toString();//Integer.toString(index);
        }

    }, true);
}