{ // ルームの作成
val room = Room(
id = idWorker.createId,
title = "[PJ] Falcon",
description = Some("開発プロジェクト"),
roomType = RoomType.Group
)
val result: Try[Room] = RoomRepository.store(room)
}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait IdWorker { | |
val identifer: IdWorkerId | |
val idConfig: IdConfig | |
def createIdValue: IdValue | |
val idValueWriter: IdValueWriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class IdWorkerImpl(idConfig: IdConfig, dataCenterId: DataCenterId, identifier: IdWorkerId) | |
extends IdWorker { | |
require(dataCenterId.value < idConfig.maxDataCenterId) | |
require(identifier.value < idConfig.maxIdWorkerId) | |
@volatile | |
private[this] var sequence: Long = 0 | |
@volatile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait IdValue extends Ordered[IdValue] { | |
val timestamp: Long | |
val dataCenterId: DataCenterId | |
val idWorkerId: IdWorkerId | |
val sequence: Long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val dataCenterId = DataCenterId(1) | |
val idWorkerId = IdWorkerId(1) | |
val idWorker = IdWorker(idConfig, dataCenterId, idWorkerId) | |
// ID生成 | |
val idValue = idWorker.createIdValue | |
// Long型に変換 | |
println(idValue.toLong) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait IdConfig { | |
val timestampBits: Int | |
val dataCenterIdBits: Int | |
val workerIdBits: Int | |
val sequenceBits: Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Color { | |
private int red; | |
private int green; | |
private int blue; | |
public int getRed() { return red; } | |
public int getGreen() { return green; } | |
public int getBlue() { return blue; } | |
public Color(int red, int green, int blue) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isNameHasUpperCase(String name) { | |
boolean result = false; | |
for(int i = 0; i < name.length(); i++) { | |
if (Character.isUpperCase(name.charAt(i))) { | |
result = true; | |
break; | |
} | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example | |
import scala.io.Source | |
object Hello extends App { | |
def find_(keyword: String, root: java.io.File): Seq[java.io.File] = { | |
import sys.process._ | |
(s"grep -l -r -s -I '$keyword' $root" lines_!) map { | |
new java.io.File(_) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scala_sample | |
import org.apache.commons.lang3.StringUtils | |
object JavaApiSample extends App { | |
{ | |
println(StringUtils.capitalize("personName")) | |
// Scalaのみで可能。こっちのがシンプル |