eu.hansolo.jdktools.FPU Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jdktools Show documentation
Show all versions of jdktools Show documentation
'JDKTools is a library that contains tools related to system info and versioning'
The newest version!
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2022 Gerrit Grunwald.
*
* 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
*
* https://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 eu.hansolo.jdktools;
import eu.hansolo.jdktools.util.OutputFormat;
import java.util.Arrays;
import java.util.List;
import static eu.hansolo.jdktools.Constants.COLON;
import static eu.hansolo.jdktools.Constants.COMMA;
import static eu.hansolo.jdktools.Constants.COMMA_NEW_LINE;
import static eu.hansolo.jdktools.Constants.CURLY_BRACKET_CLOSE;
import static eu.hansolo.jdktools.Constants.CURLY_BRACKET_OPEN;
import static eu.hansolo.jdktools.Constants.INDENTED_QUOTES;
import static eu.hansolo.jdktools.Constants.NEW_LINE;
import static eu.hansolo.jdktools.Constants.QUOTES;
public enum FPU implements Api {
HARD_FLOAT("hardfloat", "hard_float"),
SOFT_FLOAT("softfloat", "soft_float"),
UNKNOWN("unknown", "unknown"),
NONE("-", ""),
NOT_FOUND("", "");
private final String uiString;
private final String apiString;
FPU(final String uiString, final String apiString) {
this.uiString = uiString;
this.apiString = apiString;
}
@Override public String getUiString() { return uiString; }
@Override public String getApiString() { return apiString; }
@Override public FPU getDefault() { return FPU.UNKNOWN; }
@Override public FPU getNotFound() { return FPU.NOT_FOUND; }
@Override public FPU[] getAll() { return values(); }
@Override public String toString(final OutputFormat outputFormat) {
StringBuilder msgBuilder = new StringBuilder();
switch(outputFormat) {
case FULL, REDUCED, REDUCED_ENRICHED ->
msgBuilder.append(CURLY_BRACKET_OPEN).append(NEW_LINE)
.append(INDENTED_QUOTES).append("name").append(QUOTES).append(COLON).append(QUOTES).append(name()).append(QUOTES).append(COMMA_NEW_LINE)
.append(INDENTED_QUOTES).append("ui_string").append(QUOTES).append(COLON).append(QUOTES).append(uiString).append(QUOTES).append(COMMA_NEW_LINE)
.append(INDENTED_QUOTES).append("api_string").append(QUOTES).append(COLON).append(QUOTES).append(apiString).append(QUOTES).append(NEW_LINE)
.append(CURLY_BRACKET_CLOSE);
default ->
msgBuilder.append(CURLY_BRACKET_OPEN)
.append(QUOTES).append("name").append(QUOTES).append(COLON).append(QUOTES).append(name()).append(QUOTES).append(COMMA)
.append(QUOTES).append("ui_string").append(QUOTES).append(COLON).append(QUOTES).append(uiString).append(QUOTES).append(COMMA)
.append(QUOTES).append("api_string").append(QUOTES).append(COLON).append(QUOTES).append(apiString).append(QUOTES)
.append(CURLY_BRACKET_CLOSE);
}
return msgBuilder.toString();
}
@Override public String toString() { return toString(OutputFormat.FULL_COMPRESSED); }
/**
* Returns FPU parsed from a given text
* @param text Name of the fpu to parse usually the api_string of a fpu e.g. 'hard_float'
* @return FPU parsed from a given text
*/
public static FPU fromText(final String text) {
if (null == text) { return NOT_FOUND; }
switch (text) {
case "hard_float", "HARD_FLOAT", "hard-float", "HARD-FLOAT", "hardfloat", "HARDFLOAT", "hfl", "hflt", "HFLT" -> { return HARD_FLOAT; }
case "soft_float", "SOFT_FLOAT", "soft-float", "SOFT-FLOAT", "softfloat", "SOFTFLOAT", "sfl", "sflt", "SFLT" -> { return SOFT_FLOAT; }
case "unknown", "UNKNOWN" -> { return UNKNOWN; }
default -> { return NOT_FOUND; }
}
}
/**
* Returns the values of the enum as list
* @return the values of the enum as list
*/
public static List getAsList() { return Arrays.asList(values()); }
}