1 /* 2 * Copyright (C) 2020 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 com.android.build.config; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** 23 * A String and a Position, where it came from in source code. 24 */ 25 public class Str implements Comparable<Str> { 26 private String mValue; 27 private Position mPosition; 28 Str(String s)29 public Str(String s) { 30 mValue = s; 31 mPosition = new Position(); 32 } 33 Str(Position pos, String s)34 public Str(Position pos, String s) { 35 mValue = s; 36 mPosition = pos; 37 } 38 length()39 public int length() { 40 return mValue.length(); 41 } 42 43 @Override toString()44 public String toString() { 45 return mValue; 46 } 47 getPosition()48 public Position getPosition() { 49 return mPosition; 50 } 51 52 /** 53 * Str is equal if the string value is equal, regardless of whether the position 54 * is the same. 55 */ 56 @Override equals(Object o)57 public boolean equals(Object o) { 58 if (!(o instanceof Str)) { 59 return false; 60 } 61 final Str that = (Str)o; 62 return mValue.equals(that.mValue); 63 } 64 65 @Override hashCode()66 public int hashCode() { 67 return mValue.hashCode(); 68 } 69 70 @Override compareTo(Str that)71 public int compareTo(Str that) { 72 return this.mValue.compareTo(that.mValue); 73 } 74 toList(Position pos, List<String> list)75 public static ArrayList<Str> toList(Position pos, List<String> list) { 76 final ArrayList<Str> result = new ArrayList(list.size()); 77 for (String s: list) { 78 result.add(new Str(pos, s)); 79 } 80 return result; 81 } 82 } 83