This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.runtime.hdinsight.client.yarnrest;
020
021import org.codehaus.jackson.annotate.JsonProperty;
022import org.codehaus.jackson.map.ObjectMapper;
023
024import java.io.IOException;
025import java.io.StringWriter;
026
027/**
028 * An Entry with String Key and String Value in the Environment field
029 * and the ApplicationAcls field of an ApplicationSubmission.
030 * For detail information, please refer to
031 * https://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html
032 */
033public final class StringEntry {
034
035  private static final String STRING_ENTRY = "stringEntry";
036  private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
037  private String key;
038  private String value;
039
040  public StringEntry(final String key, final String value) {
041    this.key = key;
042    this.value = value;
043  }
044
045  @JsonProperty(Constants.KEY)
046  public String getKey() {
047    return this.key;
048  }
049
050  public void setKey(final String key) {
051    this.key = key;
052  }
053
054  @JsonProperty(Constants.VALUE)
055  public String getValue() {
056    return this.value;
057  }
058
059  public void setValue(final String value) {
060    this.value = value;
061  }
062
063  @Override
064  public String toString() {
065    final StringWriter writer = new StringWriter();
066    final String objectString;
067    try {
068      OBJECT_MAPPER.writeValue(writer, this);
069      objectString = writer.toString();
070    } catch (final IOException e) {
071      throw new RuntimeException("Exception while serializing Resource: " + e);
072    }
073
074    return STRING_ENTRY + objectString;
075  }
076
077  @Override
078  public boolean equals(final Object o) {
079
080    if (this == o) {
081      return true;
082    }
083    if (o == null || getClass() != o.getClass()) {
084      return false;
085    }
086
087    final StringEntry that = (StringEntry) o;
088
089    return (this.key == null && that.key == null || this.key != null && this.key.equals(that.key))
090        && (this.value == null && that.value == null || this.value != null && this.value.equals(that.value));
091  }
092
093  @Override
094  public int hashCode() {
095    int result = this.key != null ? this.key.hashCode() : 0;
096    result = 31 * result + (this.value != null ? this.value.hashCode() : 0);
097    return result;
098  }
099}