1 /*******************************************************************************
2 * Copyright (c) 2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.common;
17 * Meta class to handle things, where a String (URI, NCName, ...) may be
20 public class StringEncodedAndDecoded implements Comparable<StringEncodedAndDecoded> {
22 private String decoded = null;
23 private String encoded = null;
27 * @param uri the URI to store
28 * @param URLencoded true iff the given URI is URLencoded
30 public StringEncodedAndDecoded(String uri, boolean URLencoded) {
38 public String getDecoded() {
39 if (this.decoded == null) {
40 this.decoded = Util.URLdecode(this.encoded);
45 public String getEncoded() {
46 if (this.encoded == null) {
47 this.encoded = Util.URLencode(this.decoded);
53 public int hashCode() {
54 return this.getDecoded().hashCode();
58 * @return the URL path fragment to be used in an URL
60 public String getPathFragment() {
61 return this.getEncoded();
65 public String toString() {
66 return this.getDecoded();
70 public int compareTo(StringEncodedAndDecoded o) {
71 return this.getDecoded().compareTo(o.getDecoded());
75 * Compares with the given object <br />
76 * Equality checking is made based on the decoded String
79 public boolean equals(Object o) {
80 if (o instanceof String) {
81 return this.getDecoded().equals(o);
82 } else if (o instanceof StringEncodedAndDecoded) {
83 return ((StringEncodedAndDecoded) o).getDecoded().equals(this.getDecoded());