Skip to content

Commit

Permalink
Merge pull request #375 from gdgib/G2-1645-DraftBasicAPIs
Browse files Browse the repository at this point in the history
G2-1645 Draft basic API and tests
  • Loading branch information
gdgib authored Sep 24, 2024
2 parents a9c8c21 + 2874966 commit 3b4023d
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.g2forge.alexandria.adt.trie;

import com.g2forge.alexandria.adt.graph.v2.member.ASingleGraphMember;

public class Node extends ASingleGraphMember {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.g2forge.alexandria.path.file;

import com.g2forge.alexandria.path.directory.IDirectorySystem;
import com.g2forge.alexandria.path.file.system.IFileSystem;

public interface IFile<T> {
public IDirectorySystem<T> getDirectorySystem();
public IFileSystem<T> getDirectorySystem();

public IFile<T> getParent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.nio.file.Files;
import java.nio.file.Path;

import com.g2forge.alexandria.path.directory.DirectorySystem;
import com.g2forge.alexandria.path.directory.IDirectorySystem;
import com.g2forge.alexandria.path.file.system.OSFileSystem;
import com.g2forge.alexandria.path.file.system.IFileSystem;

import lombok.Builder;
import lombok.Data;
Expand All @@ -26,8 +26,8 @@ public IFile<String> get(String filename) {
}

@Override
public IDirectorySystem<String> getDirectorySystem() {
return DirectorySystem.getDirectorySystem();
public IFileSystem<String> getDirectorySystem() {
return OSFileSystem.getDirectorySystem();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.g2forge.alexandria.path.file.system;

import com.g2forge.alexandria.path.path.IPath;

public interface IFileSystem<T> {
public IPath<T> normalize(IPath<T> path);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.g2forge.alexandria.path.directory;
package com.g2forge.alexandria.path.file.system;

import java.util.ArrayList;
import java.util.List;

import com.g2forge.alexandria.path.IPath;
import com.g2forge.alexandria.path.Path;

public interface IStandardDirectorySystem extends IDirectorySystem<String> {
public default String getSelf() {
return ".";
}
import com.g2forge.alexandria.path.path.IPath;
import com.g2forge.alexandria.path.path.Path;

public interface IStandardFileSystem extends IFileSystem<String> {
public default String getParent() {
return "..";
}

public default String getSelf() {
return ".";
}

@Override
public default IPath<String> normalize(IPath<String> path) {
if (path.isEmpty()) return path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.g2forge.alexandria.path.directory;
package com.g2forge.alexandria.path.file.system;

import com.g2forge.alexandria.java.core.enums.EnumException;
import com.g2forge.alexandria.java.platform.HPlatform;
import com.g2forge.alexandria.java.platform.PlatformCategory;

public enum DirectorySystem implements IStandardDirectorySystem {
public enum OSFileSystem implements IStandardFileSystem {
Microsoft,
POSIX;

public static DirectorySystem getDirectorySystem() {
public static OSFileSystem getDirectorySystem() {
final PlatformCategory category = HPlatform.getPlatform().getCategory();
switch (category) {
case Microsoft:
return DirectorySystem.Microsoft;
return OSFileSystem.Microsoft;
case Posix:
return DirectorySystem.POSIX;
return OSFileSystem.POSIX;
default:
throw new EnumException(PlatformCategory.class, category);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.g2forge.alexandria.path;
package com.g2forge.alexandria.path.path;

import com.g2forge.alexandria.collection.ICollection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.g2forge.alexandria.path;
package com.g2forge.alexandria.path.path;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.g2forge.alexandria.path.path.format;

import com.g2forge.alexandria.path.path.IPath;

public interface IPathFormat<T> {
public T toComponent(String component);

public IPath<T> toPath(String path);

public String toString(IPath<T> path);

public String toString(T component);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.g2forge.alexandria.path.path.format;

import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.g2forge.alexandria.path.path.IPath;
import com.g2forge.alexandria.path.path.Path;

public interface IStandardPathFormat<T> extends IPathFormat<T> {
public String getSeparator();

@Override
public default IPath<T> toPath(String path) {
final String[] components = path.split(Pattern.quote(getSeparator()));
return new Path<>(Stream.of(components).map(this::toComponent).collect(Collectors.toList()));
}

@Override
public default String toString(IPath<T> path) {
return path.getComponents().stream().map(this::toString).collect(Collectors.joining(getSeparator()));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.g2forge.alexandria.path.format;
package com.g2forge.alexandria.path.path.format;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum PathFormat implements IStandardPathFormat<String> {
public enum OSPathFormat implements IStandardPathFormat<String> {
Microsoft("\\"),
POSIX("/");

protected final String separator;

@Override
public String toComponent(String component) {
return component;
}

@Override
public String toString(String component) {
return component;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.g2forge.alexandria.path.file;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;

import com.g2forge.alexandria.test.HAssert;

import lombok.Getter;

public class TestLocalFile {
@Getter(lazy = true)
private final Path directory = Paths.get(System.getProperty("user.home"));

@Test
public void get() {
final Path directory = getDirectory();
HAssert.assertEquals(new LocalFile(directory), new LocalFile(directory).get("."));
}

@Test
public void getParent() {
final Path directory = getDirectory();
HAssert.assertEquals(new LocalFile(directory.getParent()), new LocalFile(directory).getParent());
}

@Test
public void isDirectory() {
final Path directory = getDirectory();
HAssert.assertTrue(new LocalFile(directory).isDirectory());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.g2forge.alexandria.path.directory;
package com.g2forge.alexandria.path.file.system;

import java.util.Collection;
import java.util.stream.Collectors;
Expand All @@ -9,7 +9,7 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.g2forge.alexandria.path.Path;
import com.g2forge.alexandria.path.path.Path;
import com.g2forge.alexandria.test.HAssert;

import lombok.Getter;
Expand All @@ -18,13 +18,13 @@
@RunWith(Parameterized.class)
@RequiredArgsConstructor
@Getter
public class TestDirectorySystem {
public class TestOSFileSystem {
@Parameters
public static Collection<Object[]> data() {
return Stream.of(DirectorySystem.values()).map(s -> new Object[] { s }).collect(Collectors.toList());
return Stream.of(OSFileSystem.values()).map(s -> new Object[] { s }).collect(Collectors.toList());
}

protected final IStandardDirectorySystem system;
protected final IStandardFileSystem system;

@Test
public void empty() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.g2forge.alexandria.path;
package com.g2forge.alexandria.path.path;

import org.junit.Test;

import com.g2forge.alexandria.path.Path;
import com.g2forge.alexandria.test.HAssert;

public class TestPath {
@Test
public void resolveA0() {
public void resolve0A() {
final Path<String> a = new Path<>("a");
HAssert.assertSame(a, a.resolve(Path.createEmpty()));
HAssert.assertSame(a, Path.<String>createEmpty().resolve(a));
}

@Test
public void resolve0A() {
public void resolveA0() {
final Path<String> a = new Path<>("a");
HAssert.assertSame(a, Path.<String>createEmpty().resolve(a));
HAssert.assertSame(a, a.resolve(Path.createEmpty()));
}

@Test
Expand Down
Loading

0 comments on commit 3b4023d

Please sign in to comment.