1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.provider;
18
19/**
20 * @hide
21 */
22class ParsedDocumentId {
23    public final String mArchiveId;
24    public final String mPath;
25
26    public ParsedDocumentId(String archiveId, String path) {
27        mArchiveId = archiveId;
28        mPath = path;
29    }
30
31    static public ParsedDocumentId fromDocumentId(String documentId, char idDelimiter) {
32        final int delimiterPosition = documentId.indexOf(idDelimiter);
33        if (delimiterPosition == -1) {
34            return new ParsedDocumentId(documentId, null);
35        } else {
36            return new ParsedDocumentId(documentId.substring(0, delimiterPosition),
37                    documentId.substring((delimiterPosition + 1)));
38        }
39    }
40
41    static public boolean hasPath(String documentId, char idDelimiter) {
42        return documentId.indexOf(idDelimiter) != -1;
43    }
44
45    public String toDocumentId(char idDelimiter) {
46        if (mPath == null) {
47            return mArchiveId;
48        } else {
49            return mArchiveId + idDelimiter + mPath;
50        }
51    }
52};
53