GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Removes 'Tag' and moves its utility methods to a 'StringSanitization' class. by sebright2 · Pull Request #16 · census-instrumentation/opencensus-java

This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Removes 'Tag' and moves its utility methods to a 'StringSanitization' class. #16

Merged
dinooliva merged 3 commits into census-instrumentation:master from sebright2:remove-tag-class
Sep 27, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

Removes 'Tag' and moves its utility methods to a 'StringSanitization' class. #16

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
da2f67c
Removes 'Tag' and moves its utility methods to a 'StringSanitization'…
sebright2 Sep 23, 2016
018bd61
Cleanup.
sebright2 Sep 27, 2016
4f56d46
Renames StringSanitization.java to StringUtil.java.
sebright2 Sep 27, 2016
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

8 changes: 4 additions & 4 deletions 8 BUILD
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ java_test(
)

java_test(
name = "TagKeyTest",
srcs = ["core/javatests/com/google/census/TagKeyTest.java"],
name = "StringUtilTest",
srcs = ["core/javatests/com/google/census/StringUtilTest.java"],
deps = [
":census-core",
":census-core_native",
Expand All @@ -176,8 +176,8 @@ java_test(
)

java_test(
name = "TagTest",
srcs = ["core/javatests/com/google/census/TagTest.java"],
name = "TagKeyTest",
srcs = ["core/javatests/com/google/census/TagKeyTest.java"],
deps = [
":census-core",
":census-core_native",
Expand Down
4 changes: 2 additions & 2 deletions 4 core/java/com/google/census/MetricName.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* MetricName's are {@link String}s with enforced restrictions.
*/
public final class MetricName {
public static final int MAX_LENGTH = Tag.MAX_LENGTH;
public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;

public MetricName(String name) {
this.name = Tag.sanitize(name);
this.name = StringUtil.sanitize(name);
}

@Override
Expand Down
52 changes: 6 additions & 46 deletions 52 core/java/com/google/census/Tag.java → core/java/com/google/census/StringUtil.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,10 @@

package com.google.census;

import java.util.Map.Entry;

/**
* Immutable representation of a Tag.
* Utility methods for working with tag keys, tag values, and metric names.
*/
public class Tag implements Entry<String, String> {

public Tag(TagKey key, TagValue value) {
this.key = key.toString();
this.value = value.toString();
}

@Override
public String getKey() {
return key;
}

@Override
public String getValue() {
return value;
}

@Override
public String setValue(String value) {
throw new UnsupportedOperationException();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Tag)) {
return false;
}
Tag that = (Tag) obj;
return key.equals(that.key) && value.equals(that.value);
}

@Override
public int hashCode() {
return key.hashCode() * 31 + value.hashCode();
}

// Assumes key and value have already been sanitized.
Tag(String key, String value) {
this.key = key;
this.value = value;
}
final class StringUtil {

static final int MAX_LENGTH = 255;
static final char UNPRINTABLE_CHAR_SUBSTITUTE = '_';
Expand Down Expand Up @@ -91,6 +49,8 @@ private static boolean isPrintableChar(char c) {
return c >= ' ' && c <= '~';
}

private final String key;
private final String value;
//Visible for testing
StringUtil() {
throw new AssertionError();
}
}
4 changes: 2 additions & 2 deletions 4 core/java/com/google/census/TagKey.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* TagKey's are {@link String}s with enforced restrictions.
*/
public final class TagKey {
public static final int MAX_LENGTH = Tag.MAX_LENGTH;
public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;

public TagKey(String key) {
this.key = Tag.sanitize(key);
this.key = StringUtil.sanitize(key);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions 4 core/java/com/google/census/TagValue.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
* TagValue's are {@link String}s with enforced restrictions.
*/
public final class TagValue {
public static final int MAX_LENGTH = Tag.MAX_LENGTH;
public static final int MAX_LENGTH = StringUtil.MAX_LENGTH;

public TagValue(String value) {
this.value = Tag.sanitize(value);
this.value = StringUtil.sanitize(value);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion 3 core/javatests/com/google/census/MetricNameTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void testNameMaxLength() {
@Test
public void testNameBadChar() {
assertThat(new MetricName("\2ab\3cd").toString())
.isEqualTo(Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "ab" + Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
.isEqualTo(StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "ab"
+ StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
}

@Test
Expand Down
47 changes: 47 additions & 0 deletions 47 core/javatests/com/google/census/StringUtilTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2016, Google Inc.
* 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 com.google.census;

import static com.google.common.truth.Truth.assertThat;

import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
* Tests for {@link StringUtil}.
*/
@RunWith(JUnit4.class)
public final class StringUtilTest {
@Test
public void testMaxLength() {
char[] string = new char[StringUtil.MAX_LENGTH];
char[] truncString = new char[StringUtil.MAX_LENGTH + 10];
Arrays.fill(string, 'v');
Arrays.fill(truncString, 'v');
assertThat(StringUtil.sanitize(new String(truncString))).isEqualTo(new String(string));
}

@Test
public void testBadChar() {
String string = "\2ab\3cd";
assertThat(StringUtil.sanitize(string).toString()).isEqualTo("_ab_cd");
}

@Test(expected=AssertionError.class)
public void testConstructor() {
new StringUtil();
}
}
3 changes: 2 additions & 1 deletion 3 core/javatests/com/google/census/TagKeyTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void testKeyMaxLength() {
public void testKeyBadChar() {
String key = "\2ab\3cd";
assertThat(new TagKey(key).toString())
.isEqualTo(Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "ab" + Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
.isEqualTo(StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "ab"
+ StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
}

@Test
Expand Down
59 changes: 0 additions & 59 deletions 59 core/javatests/com/google/census/TagTest.java
Show comments
View file
Open in desktop

This file was deleted.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

3 changes: 2 additions & 1 deletion 3 core/javatests/com/google/census/TagValueTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void testValueMaxLength() {
public void testValueBadChar() {
String value = "\2ab\3cd";
assertThat(new TagValue(value).toString())
.isEqualTo(Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "ab" + Tag.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
.isEqualTo(StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "ab"
+ StringUtil.UNPRINTABLE_CHAR_SUBSTITUTE + "cd");
}

@Test
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.