Android Open Source - android-memento Table One Contract






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
 */*www. j av a2  s. 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.debug.provider;


import com.twofortyfouram.assertion.Assertions;

import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * Contract for a simple ContentProvider table.
 */
@ThreadSafe
public final class TableOneContract implements BaseColumns {

    /**
     * Name of the table.
     */
    @NonNull
    /* package */ static final String TABLE_NAME = "table_one"; //$NON-NLS-1$

    /**
     * Mimetype for the entire directory.
     */
    @NonNull
    public static final String MIMETYPE_DIR = ContentResolver.CURSOR_DIR_BASE_TYPE
            + "/vnd.com.twofortyfouram.memento.debug.blabla"; //$NON-NLS-1$

    /**
     * Mimetype for a single item.
     */
    @NonNull
    public static final String MIMETYPE_ITEM = ContentResolver.CURSOR_ITEM_BASE_TYPE
            + "/vnd.com.twofortyfouram.memento.debug.blabla"; //$NON-NLS-1$

    /**
     * Type: {@code String}.
     * <p>
     * First column in the table.
     * <p>
     * Constraints: This column cannot be null.
     */
    @NonNull
    public static final String COLUMN_STRING_COLUMN_ONE = "column_one"; //$NON-NLS-1$

    /**
     * Intrinsic lock for guarding {@link #sContentUri}.
     */
    @NonNull
    private static final Object[] INTRINSIC_LOCK = new Object[0];

    /**
     * Content URI for {@link TableOneContract}.
     *
     * @see #getContentUri(Context)
     */
    @GuardedBy("INTRINSIC_LOCK")
    @Nullable
    @SuppressWarnings("StaticNonFinalField")
    private static volatile Uri sContentUri = null;

    /**
     * @param context Application context.
     * @return The content URI for {@link TableOneContract}.
     */
    @NonNull
    public static Uri getContentUri(@NonNull final Context context) {
        Assertions.assertNotNull(context, "context"); //$NON-NLS-1$
        /*
         * Double-checked idiom for lazy initialization, Effective Java 2nd edition page 283.
         */
        Uri contentUri = sContentUri;
        if (null == contentUri) {
            synchronized (INTRINSIC_LOCK) {
                contentUri = sContentUri;
                if (null == contentUri) {
                    final String authority = SqliteContentProviderImpl.getContentAuthority(context);
                    sContentUri = contentUri = new Uri.Builder()
                            .scheme(ContentResolver.SCHEME_CONTENT).authority(authority)
                            .appendPath(TABLE_NAME).build();
                }
            }
        }

        return contentUri;
    }

    /**
     * Creates ContentValues for the table.
     *
     * @param columnOne String to associate with {@link #COLUMN_STRING_COLUMN_ONE}.
     * @return Initialized ContentValues.
     */
    @NonNull
    public static ContentValues getContentValues(@NonNull final String columnOne) {
        Assertions.assertNotNull(columnOne, "columnOne"); //$NON-NLS-1$

        final ContentValues values = new ContentValues(1);
        values.put(COLUMN_STRING_COLUMN_ONE, columnOne);

        return values;
    }

    /**
     * Private constructor prevents instantiation.
     *
     * @throws UnsupportedOperationException because this class cannot be instantiated.
     */
    private TableOneContract() {
        throw new UnsupportedOperationException("This class is non-instantiable"); //$NON-NLS-1$
    }
}




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