Android Open Source - android-memento Sqlite Uri Match






From Project

Back to project page android-memento.

License

The source code is released under:

Apache License

If you think the Android project android-memento listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * android-memento-lib https://github.com/twofortyfouram/android-memento
 * Copyright 2014 two forty four a.m. LLC
 */* w w w  . j  av  a  2s  .  com*/
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.twofortyfouram.memento.provider.sqlite;

import com.twofortyfouram.assertion.Assertions;
import com.twofortyfouram.spackle.util.AndroidSdkVersion;

import net.jcip.annotations.Immutable;

import android.annotation.TargetApi;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.ArrayMap;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Encapsulates details about a Uri match.
 */
@Immutable
public final class SqliteUriMatch {

    /**
     * Base Uri of the match.
     */
    @NonNull
    private final Uri mBaseUri;

    /**
     * List of Uris to notify when a change occurs.
     * <p>This has been wrapped in a call to {@link Collections#unmodifiableList(java.util.List)}.</p>
     */
    @NonNull
    private final List<Uri> mNotifyUris;

    /**
     * True if the URI matched a specific record in a table. (E.g. suffixed with
     * an ID). Otherwise false.
     */
    private final boolean mIsIdUri;

    /**
     * Mime type of the Uri.
     */
    @NonNull
    private final String mMimeType;

    /**
     * Name of the table.
     */
    @NonNull
    private final String mTableName;

    /**
     * Projection map.
     * <p>This has been wrapped in a call to {@link Collections#unmodifiableMap(java.util.Map)}.</p>
     */
    @NonNull
    private final Map<String, String> mProjectionMap;

    /**
     * @param baseUri       The base Uri of the match.
     * @param notifyUris    List of Uris to notify when a change is made for this match.
     * @param tableName     Name of the table matched.
     * @param mimeType      The mime type of the match.
     * @param isIdUri       True if the URI matched a specific record in a table.
     *                      (E.g. suffixed with an ID).
     * @param projectionMap Projection map to be used for queries.
     */
    public SqliteUriMatch(@NonNull final Uri baseUri, @NonNull final Collection<Uri> notifyUris,
            @NonNull final String tableName, @NonNull final String mimeType,
            final boolean isIdUri, @NonNull final Map<String, String> projectionMap) {
        Assertions.assertNotNull(baseUri, "baseUri"); //$NON-NLS-1$
        Assertions.assertNotNull(notifyUris, "notifyUris"); //$NON-NLS-1$
        Assertions.assertNotNull(tableName, "tableName"); //$NON-NLS-1$
        Assertions.assertNotNull(mimeType, "mimeType"); //$NON-NLS-1$
        Assertions.assertNotNull(projectionMap, "projectionMap");  //$NON-NLS-1$

        mBaseUri = baseUri;
        mNotifyUris = Collections.unmodifiableList(new ArrayList<Uri>(notifyUris));
        mIsIdUri = isIdUri;
        mMimeType = mimeType;
        mTableName = tableName;

        // Note: these implementations of Map do not have consistent iteration ordering, which means
        // that the order of columns from a query's projection may not match the order of columns
        // in the result cursor.
        final Map<String, String> projectionCopy;
        if (AndroidSdkVersion.isAtLeastSdk(Build.VERSION_CODES.KITKAT)) {
            projectionCopy = copyMapKitKat(projectionMap);
        } else {
            projectionCopy = new HashMap<String, String>(projectionMap);
        }
        mProjectionMap = Collections.unmodifiableMap(projectionCopy);
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    private static Map<String, String> copyMapKitKat(@NonNull final Map<String, String> original) {
        final Map<String, String> result = new ArrayMap<String, String>(original.size());
        for (Map.Entry<String, String> entry : original.entrySet()) {
            result.put(entry.getKey(), entry.getValue());
        }

        return result;
    }

    /**
     * @return The base Uri of the match.
     */
    @NonNull
    public Uri getBaseUri() {
        return mBaseUri;
    }

    /**
     * @return The Uris to notify when a change occurs.  A single Uri may notify multiple Uris of
     * changes, especially if the base Uri is composed of several Uris.  The collection will be
     * wrapped in a call to {@link
     * Collections#unmodifiableList(java.util.List)}}.
     */
    @NonNull
    public List<Uri> getNotifyUris() {
        //noinspection ReturnOfCollectionOrArrayField
        return mNotifyUris;
    }

    /**
     * @return True if the URI matched a specific record in a table. (E.g.
     * suffixed with an ID). Otherwise false.
     */
    public boolean isIdUri() {
        return mIsIdUri;
    }

    /**
     * @return A projection map.  The map will be wrapped in a call to {@link
     * Collections#unmodifiableMap(java.util.Map)}.
     */
    @NonNull
    public Map<String, String> getProjectionMap() {
        //noinspection ReturnOfCollectionOrArrayField
        return mProjectionMap;
    }

    /**
     * @return Mimetype of the item.
     */
    @NonNull
    public String getMimeType() {
        return mMimeType;
    }

    /**
     * @return The name of the table.
     */
    @NonNull
    public String getTableName() {
        return mTableName;
    }
}




Java Source Code List

com.twofortyfouram.memento.debug.provider.SqliteContentProviderImpl.java
com.twofortyfouram.memento.debug.provider.SqliteOpenHelperImpl.java
com.twofortyfouram.memento.debug.provider.SqliteUriMatcherImpl.java
com.twofortyfouram.memento.debug.provider.TableOneContract.java
com.twofortyfouram.memento.provider.ContentChangeNotificationQueueTest.java
com.twofortyfouram.memento.provider.ContentChangeNotificationQueue.java
com.twofortyfouram.memento.provider.ContentProviderOperationServiceTest.java
com.twofortyfouram.memento.provider.ContentProviderOperationService.java
com.twofortyfouram.memento.provider.ContentProviderUtilTest.java
com.twofortyfouram.memento.provider.ContentProviderUtil.java
com.twofortyfouram.memento.provider.ImmutableUriMatcherTest.java
com.twofortyfouram.memento.provider.ImmutableUriMatcher.java
com.twofortyfouram.memento.provider.sqlite.AbstractSqliteContentProviderIntegrationTest.java
com.twofortyfouram.memento.provider.sqlite.AbstractSqliteContentProviderTest.java
com.twofortyfouram.memento.provider.sqlite.AbstractSqliteContentProvider.java
com.twofortyfouram.memento.provider.sqlite.SqliteColumnBuilderTest.java
com.twofortyfouram.memento.provider.sqlite.SqliteColumnBuilder.java
com.twofortyfouram.memento.provider.sqlite.SqliteIndexBuilderTest.java
com.twofortyfouram.memento.provider.sqlite.SqliteIndexBuilder.java
com.twofortyfouram.memento.provider.sqlite.SqliteOpenHelperCompat.java
com.twofortyfouram.memento.provider.sqlite.SqliteStorageClass.java
com.twofortyfouram.memento.provider.sqlite.SqliteTableBuilderTest.java
com.twofortyfouram.memento.provider.sqlite.SqliteTableBuilder.java
com.twofortyfouram.memento.provider.sqlite.SqliteUriMatchTest.java
com.twofortyfouram.memento.provider.sqlite.SqliteUriMatch.java
com.twofortyfouram.memento.provider.sqlite.SqliteUriMatcher.java