Home | History | Annotate | Download | only in print
      1 /*
      2  * Copyright (C) 2013 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 
     17 package android.print;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.text.TextUtils;
     22 
     23 import java.util.UUID;
     24 
     25 /**
     26  * This class represents the id of a print job.
     27  */
     28 public final class PrintJobId implements Parcelable {
     29     private final String mValue;
     30 
     31     /**
     32      * Creates a new instance.
     33      *
     34      * @hide
     35      */
     36     public PrintJobId() {
     37         this(UUID.randomUUID().toString());
     38     }
     39 
     40     /**
     41      * Creates a new instance.
     42      *
     43      * @param value The internal value.
     44      *
     45      * @hide
     46      */
     47     public PrintJobId(String value) {
     48         mValue = value;
     49     }
     50 
     51     @Override
     52     public int hashCode() {
     53         final int prime = 31;
     54         int result = 1;
     55         result = prime * result + ((mValue != null) ? mValue.hashCode() : 0);
     56         return result;
     57     }
     58 
     59     @Override
     60     public boolean equals(Object obj) {
     61         if (this == obj) {
     62             return true;
     63         }
     64         if (obj == null) {
     65             return false;
     66         }
     67         if (getClass() != obj.getClass()) {
     68             return false;
     69         }
     70         PrintJobId other = (PrintJobId) obj;
     71         if (!TextUtils.equals(mValue, other.mValue)) {
     72             return false;
     73         }
     74         return true;
     75     }
     76 
     77     @Override
     78     public void writeToParcel(Parcel parcel, int flags) {
     79         parcel.writeString(mValue);
     80     }
     81 
     82     @Override
     83     public int describeContents() {
     84         return 0;
     85     }
     86 
     87     /**
     88      * Flattens this id to a string.
     89      *
     90      * @return The flattened id.
     91      *
     92      * @hide
     93      */
     94     public String flattenToString() {
     95         return mValue;
     96     }
     97 
     98     /**
     99      * Unflattens a print job id from a string.
    100      *
    101      * @string The string.
    102      * @return The unflattened id, or null if the string is malformed.
    103      *
    104      * @hide
    105      */
    106     public static PrintJobId unflattenFromString(String string) {
    107         return new PrintJobId(string);
    108     }
    109 
    110     public static final Parcelable.Creator<PrintJobId> CREATOR =
    111             new Parcelable.Creator<PrintJobId>() {
    112         @Override
    113         public PrintJobId createFromParcel(Parcel parcel) {
    114             return new PrintJobId(parcel.readString());
    115         }
    116 
    117         @Override
    118         public PrintJobId[] newArray(int size) {
    119             return new PrintJobId[size];
    120         }
    121     };
    122 }
    123