All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scribe.model.Parameter Maven / Gradle / Ivy

There is a newer version: 2024.11.18751.20241128T090041Z-241100
Show newest version
package org.scribe.model;

import org.scribe.utils.*;

/**
 * @author: Pablo Fernandez
 */
public class Parameter implements Comparable
{
  private static final String UTF = "UTF8";

  private final String key;
  private final String value;

  public Parameter(String key, String value)
  {
    this.key = key;
    this.value = value;
  }

  public String asUrlEncodedPair()
  {
    return OAuthEncoder.encode(key).concat("=").concat(OAuthEncoder.encode(value));
  }
  
  public boolean equals(Object other)
  {
    if(other == null) return false;
    if(other == this) return true;
    if(!(other instanceof Parameter)) return false;
    
    Parameter otherParam = (Parameter) other;
    return otherParam.key.equals(key) && otherParam.value.equals(value);
  }

  public int hashCode()
  {
    return key.hashCode() + value.hashCode();
  }

  public int compareTo(Parameter parameter)
  {
    int keyDiff = key.compareTo(parameter.key);

    return keyDiff != 0 ? keyDiff : value.compareTo(parameter.value);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy