io.termd.core.term.Feature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of termd-core Show documentation
Show all versions of termd-core Show documentation
An open source terminal daemon library providing terminal handling in Java,
back ported to Alibaba by core engine team to support running on JDK 6+.
The newest version!
/*
* Copyright 2015 Julien Viet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.termd.core.term;
/**
* @author Julien Viet
*/
public class Feature {
public static Feature create(String name, T value) {
Capability cap = null;
if (value instanceof Boolean) {
cap = (Capability) Capability.getCapability(name, Boolean.class);
} else if (value instanceof Integer) {
cap = (Capability) Capability.getCapability(name, Integer.class);
} else if (value instanceof Sequence) {
cap = (Capability) Capability.getCapability(name, Sequence.class);
}
if (cap == null) {
cap = new Capability((Class) value.getClass(), null, name, null, null);
}
return new Feature(cap, value);
}
final Capability capability;
final T value;
public Feature(Capability capability, T value) {
this.capability = capability;
this.value = value;
}
public Feature(String name, T value) {
this.capability = new Capability((Class) value.getClass(), name, name, null, null);
this.value = value;
}
public T value() {
return value;
}
public Capability capability() {
return capability;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof Feature>) {
Feature> that = (Feature>) obj;
return capability.equals(that.capability) && value.equals(that.value);
}
return false;
}
@Override
public String toString() {
if (value instanceof Boolean) {
Boolean booleanValue = (Boolean) value;
return booleanValue ? capability.name : (capability.name + "@");
} else if (value instanceof Integer) {
return capability.name + "#" + value;
} else {
return capability.name + "=" + value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy