001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.audit; 019 020import java.util.StringJoiner; 021import java.util.stream.IntStream; 022 023/** 024 * PID minter that creates hierarchical IDs from a given UUID. 025 * 026 * @author awoods 027 * @since 2016-07-03 028 */ 029public class UuidPathMinter { 030 031 private static final int DEFAULT_LENGTH = 2; 032 private static final int DEFAULT_COUNT = 4; 033 034 /** 035 * Mint a unique identifier given a UUID 036 * 037 * @param uuid from which identifier will be created 038 * @return hierarchical identifier 039 */ 040 public String get(final String uuid) { 041 final StringJoiner joiner = new StringJoiner("/", "", "/" + uuid); 042 043 IntStream.rangeClosed(0, DEFAULT_COUNT - 1) 044 .forEach(x -> joiner.add(uuid.substring(x * DEFAULT_LENGTH, (x + 1) * DEFAULT_LENGTH))); 045 046 return joiner.toString(); 047 } 048}