Example usage for java.net URI equals

List of usage examples for java.net URI equals

Introduction

In this page you can find the example usage for java.net URI equals.

Prototype

public boolean equals(Object ob) 

Source Link

Document

Tests this URI for equality with another object.

Usage

From source file:com.softinstigate.restheart.integrationtest.GetCollectionIT.java

private void testGetCollection(URI uri) throws Exception {
    LOG.info("@@@ testGetCollection URI: " + uri);

    Response resp = adminExecutor.execute(Request.Get(uri));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);//from   ww w. j  a v a  2s  .  c o m
    HttpEntity entity = httpResp.getEntity();
    assertNotNull(entity);
    StatusLine statusLine = httpResp.getStatusLine();
    assertNotNull(statusLine);

    assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode());
    assertNotNull("content type not null", entity.getContentType());
    assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue());

    String content = EntityUtils.toString(entity);

    assertNotNull(content);

    JsonObject json = null;

    try {
        json = JsonObject.readFrom(content);
    } catch (Throwable t) {
        fail("@@@ Failed parsing received json");
    }

    assertNotNull("check json not null", json);
    assertNotNull("check not null _created_on property", json.get("_type"));
    assertNotNull("check not null _created_on property", json.get("_created_on"));
    assertNotNull("check not null _etag property", json.get("_etag"));
    assertNotNull("check not null _lastupdated_on property", json.get("_lastupdated_on"));
    assertNotNull("check not null _collection-props-cached property", json.get("_collection-props-cached"));
    assertNotNull("check not null _returned property", json.get("_returned"));
    assertNull("check null _size property", json.get("_size"));
    assertNull("check null _total_pages property", json.get("_total_pages"));

    assertNotNull("check not null _embedded", json.get("_embedded"));

    assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject));

    JsonObject embedded = (JsonObject) json.get("_embedded");

    assertNotNull("check not null _embedded.rh:doc", embedded.get("rh:doc"));

    assertTrue("check _embedded.rh:doc to be a json array", (embedded.get("rh:doc") instanceof JsonArray));

    JsonArray rhdoc = (JsonArray) embedded.get("rh:doc");

    assertNotNull("check not null _embedded.rh:doc[0]", rhdoc.get(0));

    assertTrue("check _embedded.rh:coll[0] to be a json object", (rhdoc.get(0) instanceof JsonObject));

    JsonObject rhdoc0 = (JsonObject) rhdoc.get(0);

    assertNotNull("check not null _embedded.rh:doc[0]._id", rhdoc0.get("_id"));

    assertNotNull("check not null _embedded.rh:doc[0]._links", rhdoc0.get("_links"));

    assertTrue("check _embedded.rh:doc[0]._links to be a json object",
            (rhdoc0.get("_links") instanceof JsonObject));

    JsonObject rhdoc0Links = (JsonObject) rhdoc0.get("_links");

    assertNotNull("check not null _embedded.rh:doc[0]._links.self", rhdoc0Links.get("self"));

    assertTrue("check _embedded.rh:doc[0]._links.self to be a json object",
            (rhdoc0Links.get("self") instanceof JsonObject));

    JsonObject rhdb0LinksSelf = (JsonObject) rhdoc0Links.get("self");

    assertNotNull("check not null _embedded.rh:doc[0]._links.self.href", rhdb0LinksSelf.get("href"));

    assertTrue("check _embedded.rh:doc[0]._links.self.href to be a string",
            (rhdb0LinksSelf.get("href").isString()));

    try {
        URI _uri = new URI(rhdb0LinksSelf.get("href").asString());
    } catch (URISyntaxException use) {
        fail("check _embedded.rh:doc[0]._links.self.href to be a valid URI");
    }

    assertNotNull("check not null _link", json.get("_links"));
    assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject));

    JsonObject links = (JsonObject) json.get("_links");

    assertNotNull("check not null self", links.get("self"));
    if (!uri.equals(collection1UriRemappedCollection)) {
        assertNotNull("check not null rh:db", links.get("rh:db"));
    } else {
        assertNull("check null rh:db", links.get("rh:db"));
    }

    assertNotNull("check not null rh:paging", links.get("rh:paging"));
    assertNotNull("check not null curies", links.get("curies"));
}

From source file:org.wrml.runtime.schema.generator.SchemaGenerator.java

@SuppressWarnings("unchecked")
public Schema generateSchema(final Prototype prototype) {

    final URI schemaUri = prototype.getSchemaUri();
    final Context context = getContext();

    final Schema schema = context.newModel(getSchemaLoader().getSchemaDimensions());
    schema.setUniqueName(prototype.getUniqueName());
    schema.setDescription(prototype.getDescription());

    final boolean isReadOnly = prototype.isReadOnly();
    if (isReadOnly) {
        schema.setReadOnly(true);/*  ww w .  ja  v  a  2  s  .c  om*/
    }

    schema.setTitle(prototype.getTitle());
    schema.setThumbnailLocation(prototype.getThumbnailLocation());
    schema.setVersion(prototype.getVersion());
    schema.setTitleSlotName(prototype.getTitleSlotName());

    schema.setUri(schemaUri);

    final Set<URI> prototypeBaseSchemaUris = prototype.getDeclaredBaseSchemaUris();
    if (prototypeBaseSchemaUris != null) {
        schema.getBaseSchemaUris().addAll(prototypeBaseSchemaUris);
    }

    final SortedSet<String> prototypeKeySlotNames = prototype.getDeclaredKeySlotNames();
    if (prototypeKeySlotNames != null) {
        schema.getKeySlotNames().addAll(prototypeKeySlotNames);
    }

    final Set<String> prototypeComparableSlotNames = prototype.getComparableSlotNames();
    if (prototypeComparableSlotNames != null) {
        schema.getComparableSlotNames().addAll(prototypeComparableSlotNames);
    }

    final SortedSet<String> prototypeTags = prototype.getTags();
    if (prototypeTags != null) {
        schema.getTags().addAll(prototypeTags);
    }

    final List<Slot> slots = schema.getSlots();
    final SortedSet<String> prototypeAllSlotNames = prototype.getAllSlotNames();
    if (prototypeAllSlotNames != null) {

        for (final String name : prototypeAllSlotNames) {
            final ProtoSlot protoSlot = prototype.getProtoSlot(name);
            final URI slotDeclaredSchemaUri = protoSlot.getDeclaringSchemaUri();
            if (!schemaUri.equals(slotDeclaredSchemaUri)) {
                continue;
            }

            final Slot slot = context.newModel(Slot.class);
            slot.setName(name);

            final SortedSet<String> aliases = protoSlot.getAliases();
            if (aliases != null) {
                slot.getAliases().addAll(aliases);
            }

            slot.setDescription(protoSlot.getDescription());
            slot.setTitle(protoSlot.getTitle());

            final Type slotHeapValueType = protoSlot.getHeapValueType();
            final Value value = generateValue(slotHeapValueType, protoSlot);

            if (value == null) {
                throw new SchemaGeneratorException("Failed to generate a Value for slot: " + protoSlot, null,
                        this);
            }

            if (protoSlot instanceof PropertyProtoSlot) {
                final PropertyProtoSlot propertyProtoSlot = (PropertyProtoSlot) protoSlot;
                final Object propertyDefaultValue = propertyProtoSlot.getDefaultValue();
                final ValueType propertyValueType = propertyProtoSlot.getValueType();
                final Object valueTypeDefaultValue = propertyValueType.getDefaultValue();
                if (propertyDefaultValue != null && !propertyDefaultValue.equals(valueTypeDefaultValue)) {
                    value.setSlotValue(Value.SLOT_NAME_DEFAULT, propertyDefaultValue);
                }

                @SuppressWarnings("rawtypes")
                final Set disallowedValues = propertyProtoSlot.getDisallowedValues();
                if (disallowedValues != null && !disallowedValues.isEmpty()) {
                    propertyProtoSlot.getDisallowedValues().addAll(disallowedValues);
                }

                final Object divisibleByValue = propertyProtoSlot.getDivisibleByValue();
                if (divisibleByValue != null) {
                    value.setSlotValue(NumericValue.SLOT_NAME_DIVISIBLE_BY, divisibleByValue);
                }

                final Integer maximumLength = propertyProtoSlot.getMaximumLength();
                if (maximumLength != null) {
                    value.setSlotValue(TextValue.SLOT_NAME_MAXIMUM_LENGTH, maximumLength);
                }

                final Integer maximumSize = propertyProtoSlot.getMaximumSize();
                if (maximumSize != null) {
                    value.setSlotValue(ListValue.SLOT_NAME_MAXIMUM_SIZE, maximumSize);
                }

                final Object maximumValue = propertyProtoSlot.getMaximumValue();
                if (maximumValue != null) {
                    value.setSlotValue(NumericValue.SLOT_NAME_MAXIMUM, maximumValue);
                }

                final Integer minimumLength = propertyProtoSlot.getMinimumLength();
                if (minimumLength != null) {
                    value.setSlotValue(TextValue.SLOT_NAME_MINIMUM_LENGTH, minimumLength);
                }

                final Integer minimumSize = propertyProtoSlot.getMinimumSize();
                if (minimumSize != null) {
                    value.setSlotValue(ListValue.SLOT_NAME_MINIMUM_SIZE, minimumSize);
                }

                final Object minimumValue = propertyProtoSlot.getMinimumValue();
                if (minimumValue != null) {
                    value.setSlotValue(NumericValue.SLOT_NAME_MINIMUM, minimumValue);
                }

                final boolean isMultiline = propertyProtoSlot.isMultiline();
                if (isMultiline) {
                    value.setSlotValue(TextValue.SLOT_NAME_MULTILINE, isMultiline);
                }

                if (slotHeapValueType instanceof Class<?>
                        && Set.class.isAssignableFrom((Class<?>) slotHeapValueType)) {
                    value.setSlotValue(ListValue.SLOT_NAME_ELEMENT_UNIQUENESS_CONSTRAINED, Boolean.TRUE);
                }

            }

            slot.setValue(value);

            slots.add(slot);

        }
    }

    return schema;
}

From source file:es.pode.publicacion.negocio.servicios.SrvPublicacionServiceImpl.java

private boolean recursoValido(String href) throws URISyntaxException {

    URI uri = new URI(href);
    if (uri != null && !uri.equals("")) {
        if (!uri.isOpaque()) {//Para quitar las URL-s de tipo mailto:java-net@java.sun.com
            if (logger.isDebugEnabled())
                logger.debug("El recurso con href [" + href + "] es valido");
            return true;
        } else {//from  w ww.jav a 2 s  . com
            if (logger.isDebugEnabled())
                logger.debug("El recurso con href [" + href + "] NO es valido");
            return false;
        }
    }
    return false;
}