Java Code Examples for com.badlogic.gdx.utils.StringBuilder

The following examples show how to use com.badlogic.gdx.utils.StringBuilder. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: talos   Source File: ExportData.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString () {
    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append(name);
    stringBuilder.append("\n");

    for (AbstractModule module : modules) {
        stringBuilder.append("\t");
        stringBuilder.append("ModuleID: ");
        stringBuilder.append(module.getIndex());
        stringBuilder.append("\n");
    }

    stringBuilder.append("\n");
    for (ConnectionData connection : connections) {
        stringBuilder.append("\t");
        stringBuilder.append("Connection: ");
        stringBuilder.append(connection);
        stringBuilder.append("\n");
    }

    return stringBuilder.toString();
}
 
Example 2
Source Project: skin-composer   Source File: DialogSceneComposerJavaBuilder.java    License: MIT License 6 votes vote down vote up
private static String alignmentToName(int align) {
    StringBuilder buffer = new StringBuilder(13);
    if ((align & Align.top) != 0)
        buffer.append("top");
    else if ((align & Align.bottom) != 0)
        buffer.append("bottom");
    else {
        if ((align & Align.left) != 0)
            buffer.append("left");
        else if ((align & Align.right) != 0)
            buffer.append("right");
        else
            buffer.append("center");
        return buffer.toString();
    }
    if ((align & Align.left) != 0)
        buffer.append("Left");
    else if ((align & Align.right) != 0)
        buffer.append("Right");
    return buffer.toString();
}
 
Example 3
Source Project: beatoraja   Source File: PlayDataAccessor.java    License: GNU General Public License v3.0 6 votes vote down vote up
private String getScoreHash(ScoreData score) {
	byte[] cipher_byte;
	try {
		MessageDigest md = MessageDigest.getInstance("SHA-256");
		md.update((hashkey + score.getSha256() + "," + score.getExscore() + "," + score.getEpg() + ","
				+ score.getLpg() + "," + score.getEgr() + "," + score.getLgr() + "," + score.getEgd() + ","
				+ score.getLgd() + "," + score.getEbd() + "," + score.getLbd() + "," + score.getEpr() + ","
				+ score.getLpr() + "," + score.getEms() + "," + score.getLms() + "," + score.getClear() + ","
				+ score.getMinbp() + "," + score.getCombo() + "," + score.getMode() + "," + score.getClearcount()
				+ "," + score.getPlaycount() + "," + score.getOption() + "," + score.getRandom() + ","
				+ score.getTrophy() + "," + score.getDate()).getBytes());
		cipher_byte = md.digest();
		StringBuilder sb = new StringBuilder(2 * cipher_byte.length);
		for (byte b : cipher_byte) {
			sb.append(String.format("%02x", b & 0xff));
		}
		return "035" + sb.toString();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source Project: beatoraja   Source File: PlayDataAccessor.java    License: GNU General Public License v3.0 6 votes vote down vote up
private String getReplayDataFilePath(String[] hashes, boolean ln, int lnmode, int index,
		CourseData.CourseDataConstraint[] constraint) {
	StringBuilder hash = new StringBuilder();
	for (String s : hashes) {
		hash.append(s.substring(0, 10));
	}
	StringBuilder sb = new StringBuilder();
	for (CourseData.CourseDataConstraint c : constraint) {
		if (c != CLASS && c != MIRROR && c != RANDOM) {
			for(int i = 0;i < CourseDataConstraint.values().length;i++) {
				if(c == CourseDataConstraint.values()[i]) {
					sb.append(String.format("%02d", i + 1));
					break;
				}
			}
		}
	}
	return this.getReplayDataFolder() + File.separatorChar
			+ (ln ? replay[lnmode] : "") + hash + (sb.length() > 0 ? "_" + sb.toString() : "")
			+ (index > 0 ? "_" + index : "");
}
 
Example 5
Source Project: riiablo   Source File: TXT.java    License: Apache License 2.0 6 votes vote down vote up
private static String[] split(int len, String str, char token) {
  StringBuilder builder = new StringBuilder(32);
  String[] tokens = new String[len];
  char c;
  int numTokens = 0;
  final int strLen = str.length();
  for (int i = 0; i < strLen; i++) {
    c = str.charAt(i);
    if (c == token) {
      tokens[numTokens++] = builder.toString();
      builder.setLength(0);
    } else {
      builder.append(c);
    }
  }
  if (numTokens < len) Arrays.fill(tokens, numTokens, len, StringUtils.EMPTY);
  return tokens;
}
 
Example 6
Source Project: libgdx-snippets   Source File: TextFileUtils.java    License: MIT License 6 votes vote down vote up
public static void writeString(FileHandle file, String text) throws IOException {

		StringBuilder builder = new StringBuilder(text.length());
		String newLine = Host.os != Host.OS.Windows ? "\n" : "\r\n";

		try (BufferedReader reader = new BufferedReader(new StringReader(text))) {

			String line;
			while ((line = reader.readLine()) != null) {

				if (builder.length() > 0) {
					builder.append(newLine);
				}

				builder.append(line);
			}
		}

		file.writeString(builder.toString(), false);
	}
 
Example 7
Source Project: libgdx-snippets   Source File: SHA1.java    License: MIT License 6 votes vote down vote up
@Override
public String toString() {

	StringBuilder builder = algorithm.stringBuilder.get();
	builder.setLength(0);

	int v;
	char c;

	for (byte b : value) {
		v = (b & 0xf0) >> 4;
		c = (v < 10) ? (char) ('0' + v) : (char) ('a' + v - 10);
		builder.append(c);
		v = b & 0x0f;
		c = (v < 10) ? (char) ('0' + v) : (char) ('a' + v - 10);
		builder.append(c);
	}

	return builder.toString();
}
 
Example 8
Source Project: vis-ui   Source File: Dialogs.java    License: Apache License 2.0 6 votes vote down vote up
private static void getStackTrace (Throwable throwable, StringBuilder builder) {
	String msg = throwable.getMessage();
	if (msg != null) {
		builder.append(msg);
		builder.append("\n\n");
	}

	for (StackTraceElement element : throwable.getStackTrace()) {
		builder.append(element);
		builder.append("\n");
	}

	if (throwable.getCause() != null) {
		builder.append("\nCaused by: ");
		getStackTrace(throwable.getCause(), builder);
	}
}
 
Example 9
Source Project: gdx-proto   Source File: HUD.java    License: Apache License 2.0 6 votes vote down vote up
public void showChatMessages(StringBuilder sb) {
	for (ChatMessage chat : chatMessages) {
		long elapsed = TimeUtils.timeSinceMillis(chat.createTime);
		if (elapsed >= chatMessageLifeTime) {
			chatMessages.removeValue(chat, true);
		} else {
			sb.append("\n[");
			if (chat.playerId == -1) {
				sb.append("Server");
			} else {
				sb.append("Player ").append(chat.playerId);
			}
			sb.append("]: ").append(chat.text);
		}
	}
}
 
Example 10
Source Project: gdx-ai   Source File: DungeonUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String mapToString (int[][] map) {
	StringBuilder sb = new StringBuilder(map.length * (map[0].length + 1)); // +1 is due to the new line char
	for (int x = 0; x < map.length; x++) {
		for (int y = 0; y < map[0].length; y++) {
			switch (map[x][y]) {
			case TILE_EMPTY:
				sb.append(' ');
				break;
			case TILE_FLOOR:
				sb.append('.');
				break;
			case TILE_WALL:
				sb.append('#');
				break;
			default:
				sb.append('?');
				break;
			}
		}
		sb.append('\n');
	}
	return sb.toString();
}
 
Example 11
Source Project: gdx-ai   Source File: BehaviorTreeViewer.java    License: Apache License 2.0 6 votes vote down vote up
private static void appendFieldString (StringBuilder sb, Task<?> task, TaskAttribute ann, Field field) {
	// prefer name from annotation if there is one
	String name = ann.name();
	if (name == null || name.length() == 0) name = field.getName();
	Object value;
	try {
		field.setAccessible(true);
		value = field.get(task);
	} catch (ReflectionException e) {
		Gdx.app.error("", "Failed to get field", e);
		return;
	}
	sb.append(name).append(":");
	Class<?> fieldType = field.getType();
	if (fieldType.isEnum() || fieldType == String.class) {
		sb.append('\"').append(value).append('\"');
	} else if (Distribution.class.isAssignableFrom(fieldType)) {
		sb.append('\"').append(DAs.toString((Distribution)value)).append('\"');
	} else
		sb.append(value);
}
 
Example 12
Source Project: GdxDemo3D   Source File: IntValueLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	int newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 13
Source Project: GdxDemo3D   Source File: FloatValueLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	float newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 14
Source Project: GdxDemo3D   Source File: ObjectValueLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	T newValue = getValue();
	if (!oldValue.equals(newValue)) {
		copyValue(newValue, oldValue);
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 15
Source Project: libgdx-snippets   Source File: JsonFloatSerializer.java    License: MIT License 5 votes vote down vote up
public static String encodeFloatBits(float value) {

		StringBuilder builder = stringBuilder.get();

		builder.setLength(0);
		builder.append("0x");
		builder.append(String.format("%08X", Float.floatToRawIntBits(value)));
		builder.append("|");
		builder.append(value);

		return builder.toString();
	}
 
Example 16
Source Project: libgdx-snippets   Source File: JsonFloatSerializer.java    License: MIT License 5 votes vote down vote up
public static String encodeDoubleBits(double value) {

		StringBuilder builder = stringBuilder.get();

		builder.setLength(0);
		builder.append("0x");
		builder.append(String.format("%016X", Double.doubleToRawLongBits(value)));
		builder.append("|");
		builder.append(value);

		return builder.toString();
	}
 
Example 17
Source Project: box2dlights   Source File: Spinor.java    License: Apache License 2.0 5 votes vote down vote up
@Override public String toString() {
  StringBuilder result = new StringBuilder();
  float radians = angle();
  result.append("radians: ");
  result.append(radians);
  result.append(", degrees: ");
  result.append(radians * MathUtils.radiansToDegrees);
  return result.toString();
}
 
Example 18
Source Project: gdx-proto   Source File: HeightMapModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
	com.badlogic.gdx.utils.StringBuilder sb = new StringBuilder();
	sb.append(String.format("Triangle[Z:%d, X:%d]\n", zidx, xidx));
	sb.append(Tools.fmt(a.position, "a")).append("\n");
	sb.append(Tools.fmt(b.position, "b")).append("\n");
	sb.append(Tools.fmt(c.position, "c")).append("\n");
	sb.append(Tools.fmt(getCenter(tmp), "center")).append("\n");
	return sb.toString();
}
 
Example 19
Source Project: gdx-proto   Source File: Tools.java    License: Apache License 2.0 5 votes vote down vote up
public static String fmt(MeshPartBuilder.VertexInfo vi, String name) {
	if (name == null) name = "";
	StringBuilder sb = new StringBuilder();
	sb.append("VertexInfo: ").append(name).append("\n");
	sb.append("\t").append(fmt(vi.position, "position")).append("\n");
	sb.append("\t").append(fmt(vi.color)).append("\n");
	sb.append("\t").append(fmt(vi.normal, "normal"));
	return sb.toString();
}
 
Example 20
Source Project: gdx-ai   Source File: IntValueLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	int newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 21
Source Project: gdx-ai   Source File: FloatValueLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void act (float delta) {
	float newValue = getValue();
	if (oldValue != newValue) {
		oldValue = newValue;
		StringBuilder sb = getText();
		sb.setLength(appendIndex);
		sb.append(oldValue);
		invalidateHierarchy();
	}
	super.act(delta);
}
 
Example 22
Source Project: gdx-ai   Source File: BehaviorTreeViewer.java    License: Apache License 2.0 5 votes vote down vote up
public View (Task<?> task, Skin skin) {
	super(skin);
	this.name = new Label(task.getClass().getSimpleName(), skin);
	this.status = new Label("", skin);
	add(name);
	add(status).padLeft(10);
	StringBuilder attrs = new StringBuilder(task.getClass().getSimpleName()).append('\n');
	addListener(new TextTooltip(appendTaskAttributes(attrs, task).toString(), skin));
}
 
Example 23
Source Project: gdx-ai   Source File: BehaviorTreeViewer.java    License: Apache License 2.0 5 votes vote down vote up
private static StringBuilder appendTaskAttributes (StringBuilder attrs, Task<?> task) {
	Class<?> aClass = task.getClass();
	Field[] fields = ClassReflection.getFields(aClass);
	for (Field f : fields) {
		Annotation a = f.getDeclaredAnnotation(TaskAttribute.class);
		if (a == null) continue;
		TaskAttribute annotation = a.getAnnotation(TaskAttribute.class);
		attrs.append('\n');
		appendFieldString(attrs, task, annotation, f);
	}
	return attrs;
}
 
Example 24
Source Project: typing-label   Source File: TypingLabel.java    License: MIT License 4 votes vote down vote up
/** Similar to {@link #getText()}, but returns the original text with all the tokens unchanged. */
public StringBuilder getOriginalText() {
    return originalText;
}
 
Example 25
public StringBuilder getText() {
    return label.getText();
}
 
Example 26
public LmlTag(LmlParser parser, com.github.czyzby.lml.parser.tag.LmlTag parentTag, java.lang.StringBuilder rawTagData) {
    super(parser, parentTag, rawTagData);
}
 
Example 27
Source Project: libgdx-snippets   Source File: SHA1.java    License: MIT License 4 votes vote down vote up
@Override
protected StringBuilder initialValue() {
	return new StringBuilder(40);
}
 
Example 28
Source Project: vis-ui   Source File: Dialogs.java    License: Apache License 2.0 4 votes vote down vote up
private static String getStackTrace (Throwable throwable) {
	StringBuilder builder = new StringBuilder();
	getStackTrace(throwable, builder);
	return builder.toString();
}
 
Example 29
Source Project: gdx-ai   Source File: BehaviorTreeViewer.java    License: Apache License 2.0 4 votes vote down vote up
private void updateStepLabel () {
	StringBuilder sb = stepLabel.getText();
	sb.setLength(LABEL_STEP.length());
	sb.append(step);
	stepLabel.invalidateHierarchy();
}
 
Example 30
Source Project: libgdx-snippets   Source File: TextFileUtils.java    License: MIT License 3 votes vote down vote up
public static String readString(FileHandle file) throws IOException {

		StringBuilder builder = new StringBuilder((int) file.length());

		readLines(file, line -> {

			if (builder.length() > 0) {
				builder.append('\n');
			}

			builder.append(line);
		});

		return builder.toString();
	}