svnno****@sourc*****
svnno****@sourc*****
2009年 9月 15日 (火) 02:14:37 JST
Revision: 3568 http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3568 Author: daisuke_m Date: 2009-09-15 02:14:37 +0900 (Tue, 15 Sep 2009) Log Message: ----------- v0.0.2リリース。 Added Paths: ----------- leto/jiemamy-commons/tags/release/0.0.2/ leto/jiemamy-commons/tags/release/0.0.2/pom.xml leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java Removed Paths: ------------- leto/jiemamy-commons/tags/release/0.0.2/pom.xml leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java Property changes on: leto/jiemamy-commons/tags/release/0.0.2 ___________________________________________________________________ Added: svn:ignore + target lib repo .externalToolBuilders Added: svn:externals + .settings -r3550 http://svn.sourceforge.jp/svnroot/jiemamy/athena/master/trunk/.settings Deleted: leto/jiemamy-commons/tags/release/0.0.2/pom.xml =================================================================== --- leto/jiemamy-commons/trunk/pom.xml 2009-09-14 09:39:05 UTC (rev 3550) +++ leto/jiemamy-commons/tags/release/0.0.2/pom.xml 2009-09-14 17:14:37 UTC (rev 3568) @@ -1,117 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.jiemamy</groupId> - <artifactId>master</artifactId> - <version>1.1</version> - </parent> - <groupId>org.jiemamy</groupId> - <artifactId>jiemamy-commons</artifactId> - <name>Jiemamy Commons</name> - <version>0.0.2-SNAPSHOT</version> - <url>http://report.jiemamy.org/jiemamy-commons</url> - <issueManagement> - <system>JIRA</system> - <url>http://jira.jiemamy.org/jira/browse/COM</url> - </issueManagement> - <ciManagement> - <system>hudson</system> - <url>http://hudson.jiemamy.org/hudson/job/jiemamy-commons/</url> - <notifiers> - <notifier> - <sendOnSuccess>false</sendOnSuccess> - <configuration> - <recipients>jiema****@googl*****</recipients> - </configuration> - </notifier> - </notifiers> - </ciManagement> - <inceptionYear>2009</inceptionYear> - <developers> - <developer> - <id>daisuke</id> - <name>MIYAMOTO Daisuke</name> - <email>daisuke_m****@users*****</email> - <url>http://d.hatena.ne.jp/daisuke-m/</url> - <timezone>+9</timezone> - </developer> - <developer> - <id>j5ik2o</id> - <name>Junichi Kato</name> - <email>j5ik2****@users*****</email> - <url>http://d.hatena.ne.jp/j5ik2o/</url> - <timezone>+9</timezone> - </developer> - </developers> - <scm> - <connection>scm:svn:http://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</connection> - <developerConnection>scm:svn:svn+ssh://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</developerConnection> - <url>http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi/leto/jiemamy-commons/trunk/?root=jiemamy</url> - </scm> - <repositories> - <repository> - <id>jiemamy.org</id> - <name>Jiemamy Repository</name> - <url>http://maven.jiemamy.org/release</url> - </repository> - </repositories> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.5</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-library</artifactId> - <version>1.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.h2database</groupId> - <artifactId>h2</artifactId> - <version>1.1.113</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>jcl-over-slf4j</artifactId> - <version>1.5.6</version> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-core</artifactId> - <version>0.9.15</version> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>0.9.15</version> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>1.3.2</version> - </dependency> - <dependency> - <groupId>javassist</groupId> - <artifactId>javassist</artifactId> - <version>3.8.0.GA</version> - <optional>false</optional> - </dependency> - </dependencies> -</project> \ No newline at end of file Copied: leto/jiemamy-commons/tags/release/0.0.2/pom.xml (from rev 3567, leto/jiemamy-commons/trunk/pom.xml) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.2/pom.xml (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.2/pom.xml 2009-09-14 17:14:37 UTC (rev 3568) @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.jiemamy</groupId> + <artifactId>master</artifactId> + <version>1.1</version> + </parent> + <groupId>org.jiemamy</groupId> + <artifactId>jiemamy-commons</artifactId> + <name>Jiemamy Commons</name> + <version>0.0.2</version> + <url>http://report.jiemamy.org/jiemamy-commons</url> + <issueManagement> + <system>JIRA</system> + <url>http://jira.jiemamy.org/jira/browse/COM</url> + </issueManagement> + <ciManagement> + <system>hudson</system> + <url>http://hudson.jiemamy.org/hudson/job/jiemamy-commons/</url> + <notifiers> + <notifier> + <sendOnSuccess>false</sendOnSuccess> + <configuration> + <recipients>jiema****@googl*****</recipients> + </configuration> + </notifier> + </notifiers> + </ciManagement> + <inceptionYear>2009</inceptionYear> + <developers> + <developer> + <id>daisuke</id> + <name>MIYAMOTO Daisuke</name> + <email>daisuke_m****@users*****</email> + <url>http://d.hatena.ne.jp/daisuke-m/</url> + <timezone>+9</timezone> + </developer> + <developer> + <id>j5ik2o</id> + <name>Junichi Kato</name> + <email>j5ik2****@users*****</email> + <url>http://d.hatena.ne.jp/j5ik2o/</url> + <timezone>+9</timezone> + </developer> + </developers> + <scm> + <connection>scm:svn:http://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</connection> + <developerConnection>scm:svn:svn+ssh://svn.sourceforge.jp/svnroot/jiemamy/leto/jiemamy-commons/trunk</developerConnection> + <url>http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi/leto/jiemamy-commons/trunk/?root=jiemamy</url> + </scm> + <repositories> + <repository> + <id>jiemamy.org</id> + <name>Jiemamy Repository</name> + <url>http://maven.jiemamy.org/release</url> + </repository> + </repositories> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>1.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.1.113</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <version>1.5.6</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> + <version>0.9.15</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>0.9.15</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>javassist</groupId> + <artifactId>javassist</artifactId> + <version>3.8.0.GA</version> + <optional>false</optional> + </dependency> + </dependencies> +</project> \ No newline at end of file Deleted: leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java =================================================================== --- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java 2009-09-14 09:39:05 UTC (rev 3550) +++ leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java 2009-09-14 17:14:37 UTC (rev 3568) @@ -1,205 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/02/23 - * - * This file is part of Jiemamy. - * - * 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 org.jiemamy.utils; - -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.slf4j.Marker; -import org.slf4j.helpers.BasicMarker; - -/** - * SLF4Jのログマーカーを提供する定数クラス。 - * - * <p>cf. <a - * href="http://d.hatena.ne.jp/taichitaichi/20090220/1235124140">http://d.hatena.ne.jp/taichitaichi/20090220/1235124140</a></p> - * - * @see BasicMarker - * @author daisuke - */ -public enum LogMarker implements Marker { - - /** Jiemamy用 SLF4Jのルートログマーカー */ - MARKER_ROOT("org.jiemamy"), - - /** 設計判断を伴う処理に関連する項目。アドインやプラグインに関連する部分など */ - DESIGN("org.jiemamy.design"), - - /** ファイルやネットワーク、他の依存ライブラリに対するインターフェースに関連する項目 */ - BOUNDARY("org.jiemamy.boundary"), - - /** ライブラリ内に定義されているオブジェクトのライフサイクルに関連する項目 */ - LIFECYCLE("org.jiemamy.lifecycle"), - - /** - * 処理の中で、詳細な情報を出力する為の項目 - * - * <p>このマーカは、主にライブリやフレームワークの実装者が、バグの調査を目的として使う</p> - */ - DETAIL("org.jiemamy" + ".detail"); - - private static final String OPEN = "[ "; - - private static final String CLOSE = " ]"; - - private static final String SEP = ", "; - - static { - for (Marker m : values()) { - if (m == MARKER_ROOT) { - continue; - } - MARKER_ROOT.add(m); - } - } - - private final String name; - - private List<Marker> refereceList; - - - LogMarker(String name) { - this.name = name; - } - - public void add(Marker reference) { - if (reference == null) { - throw new IllegalArgumentException("A null value cannot be added to a Marker as reference."); - } - - // no point in adding the reference multiple times - if (this.contains(reference)) { - return; - - } else if (reference.contains(this)) { // avoid recursion - // a potential reference should not its future "parent" as a reference - return; - } else { - // let's add the reference - if (refereceList == null) { - refereceList = new Vector<Marker>(); - } - refereceList.add(reference); - } - } - - public boolean contains(Marker other) { - if (other == null) { - throw new IllegalArgumentException("Other cannot be null"); - } - - if (equals(other)) { - return true; - } - - if (hasReferences()) { - for (int i = 0; i < refereceList.size(); i++) { - Marker ref = refereceList.get(i); - if (ref.contains(other)) { - return true; - } - } - } - return false; - } - - public boolean contains(String name) { - if (name == null) { - throw new IllegalArgumentException("Other cannot be null"); - } - - if (this.name.equals(name)) { - return true; - } - - if (hasReferences()) { - for (int i = 0; i < refereceList.size(); i++) { - Marker ref = refereceList.get(i); - if (ref.contains(name)) { - return true; - } - } - } - return false; - } - - public String getName() { - return name; - } - - @Deprecated - @SuppressWarnings("deprecation") - public boolean hasChildren() { - return hasReferences(); - } - - public boolean hasReferences() { - return refereceList != null && refereceList.size() > 0; - } - - public Iterator<Marker> iterator() { - if (refereceList != null) { - return refereceList.iterator(); - } else { - @SuppressWarnings("unchecked") - Iterator<Marker> result = Collections.EMPTY_LIST.iterator(); - return result; - } - } - - public boolean remove(Marker referenceToRemove) { - if (refereceList == null) { - return false; - } - - int size = refereceList.size(); - for (int i = 0; i < size; i++) { - Marker m = refereceList.get(i); - if (referenceToRemove.equals(m)) { - refereceList.remove(i); - return true; - } - } - return false; - } - - @Override - public String toString() { - if (!hasReferences()) { - return getName(); - } - Iterator<Marker> it = iterator(); - Marker reference; - StringBuffer sb = new StringBuffer(getName()); - sb.append(' ').append(OPEN); - while (it.hasNext()) { - reference = it.next(); - sb.append(reference.getName()); - if (it.hasNext()) { - sb.append(SEP); - } - } - sb.append(CLOSE); - - return sb.toString(); - } - -} Copied: leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java (from rev 3564, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/LogMarker.java 2009-09-14 17:14:37 UTC (rev 3568) @@ -0,0 +1,204 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/23 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.utils; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Vector; + +import org.slf4j.Marker; +import org.slf4j.helpers.BasicMarker; + +/** + * SLF4Jのログマーカーを提供する定数クラス。 + * + * <p>cf. <a + * href="http://d.hatena.ne.jp/taichitaichi/20090220/1235124140">http://d.hatena.ne.jp/taichitaichi/20090220/1235124140</a></p> + * + * @see BasicMarker + * @author daisuke + */ +public enum LogMarker implements Marker { + + /** Jiemamy用 SLF4Jのルートログマーカー */ + MARKER_ROOT("org.jiemamy"), + + /** 設計判断を伴う処理に関連する項目。アドインやプラグインに関連する部分など */ + DESIGN("org.jiemamy.design"), + + /** ファイルやネットワーク、他の依存ライブラリに対するインターフェースに関連する項目 */ + BOUNDARY("org.jiemamy.boundary"), + + /** ライブラリ内に定義されているオブジェクトのライフサイクルに関連する項目 */ + LIFECYCLE("org.jiemamy.lifecycle"), + + /** + * 処理の中で、詳細な情報を出力する為の項目 + * + * <p>このマーカは、主にライブリやフレームワークの実装者が、バグの調査を目的として使う</p> + */ + DETAIL("org.jiemamy" + ".detail"); + + private static final String OPEN = "[ "; + + private static final String CLOSE = " ]"; + + private static final String SEP = ", "; + + static { + for (Marker m : values()) { + if (m == MARKER_ROOT) { + continue; + } + MARKER_ROOT.add(m); + } + } + + private final String name; + + private List<Marker> refereceList; + + + LogMarker(String name) { + this.name = name; + } + + public void add(Marker reference) { + if (reference == null) { + throw new IllegalArgumentException("A null value cannot be added to a Marker as reference."); + } + + // no point in adding the reference multiple times + if (this.contains(reference)) { + return; + + } else if (reference.contains(this)) { // avoid recursion + // a potential reference should not its future "parent" as a reference + return; + } else { + // let's add the reference + if (refereceList == null) { + refereceList = new Vector<Marker>(); + } + refereceList.add(reference); + } + } + + public boolean contains(Marker other) { + if (other == null) { + throw new IllegalArgumentException("Other cannot be null"); + } + + if (equals(other)) { + return true; + } + + if (hasReferences()) { + for (int i = 0; i < refereceList.size(); i++) { + Marker ref = refereceList.get(i); + if (ref.contains(other)) { + return true; + } + } + } + return false; + } + + public boolean contains(String name) { + if (name == null) { + throw new IllegalArgumentException("Other cannot be null"); + } + + if (this.name.equals(name)) { + return true; + } + + if (hasReferences()) { + for (int i = 0; i < refereceList.size(); i++) { + Marker ref = refereceList.get(i); + if (ref.contains(name)) { + return true; + } + } + } + return false; + } + + public String getName() { + return name; + } + + @Deprecated + public boolean hasChildren() { + return hasReferences(); + } + + public boolean hasReferences() { + return refereceList != null && refereceList.size() > 0; + } + + public Iterator<Marker> iterator() { + if (refereceList != null) { + return refereceList.iterator(); + } else { + @SuppressWarnings("unchecked") + Iterator<Marker> result = Collections.EMPTY_LIST.iterator(); + return result; + } + } + + public boolean remove(Marker referenceToRemove) { + if (refereceList == null) { + return false; + } + + int size = refereceList.size(); + for (int i = 0; i < size; i++) { + Marker m = refereceList.get(i); + if (referenceToRemove.equals(m)) { + refereceList.remove(i); + return true; + } + } + return false; + } + + @Override + public String toString() { + if (!hasReferences()) { + return getName(); + } + Iterator<Marker> it = iterator(); + Marker reference; + StringBuffer sb = new StringBuffer(getName()); + sb.append(' ').append(OPEN); + while (it.hasNext()) { + reference = it.next(); + sb.append(reference.getName()); + if (it.hasNext()) { + sb.append(SEP); + } + } + sb.append(CLOSE); + + return sb.toString(); + } + +} Deleted: leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java =================================================================== --- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/StringUtil.java 2009-09-14 09:39:05 UTC (rev 3550) +++ leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java 2009-09-14 17:14:37 UTC (rev 3568) @@ -1,547 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/06/09 - * - * This file is part of Jiemamy. - * - * 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 org.jiemamy.utils; - -import org.apache.commons.lang.StringUtils; - -import org.jiemamy.exception.JiemamyError; - -/** - * Stringユーティリティ。 - * - * @author j5ik2o - */ -public final class StringUtil { - - private static final int C_8 = 8; - - private static final int C_16 = 16; - - private static final int C_24 = 24; - - private static final int C_0XFF = 0xff; - - private static final int C_0X0F = 0x0f; - - private static final int C_0XF0 = 0xf0; - - private static final int CAMELIZE_BUFF_SIZE = 40; - - private static final int REPLACE_BUFF_SIZE = 100; - - /** 空の文字列の配列。*/ - public static final String[] EMPTY_STRINGS = new String[0]; - - - /** - * 文字列に、数値を16進数に変換した文字列を追加します。 - * - * @param buf 追加先の文字列 - * @param i 数値 - */ - public static void appendHex(final StringBuffer buf, final byte i) { - buf.append(Character.forDigit((i & C_0X0F) >> 4, 16)); - buf.append(Character.forDigit(i & C_0XF0, 16)); - } - - /** - * 文字列に、数値を16進数に変換した文字列を追加します。 - * - * @param buf 追加先の文字列 - * @param i 数値 - */ - public static void appendHex(final StringBuffer buf, final int i) { - buf.append(Integer.toHexString((i >> C_24) & C_0XFF)); - buf.append(Integer.toHexString((i >> C_16) & C_0XFF)); - buf.append(Integer.toHexString((i >> C_8) & C_0XFF)); - buf.append(Integer.toHexString(i & C_0XFF)); - } - - /** - * _記法をキャメル記法に変換します。 - * - * @param s テキスト - * @return 結果の文字列 - */ - public static String camelize(String s) { - String current = s; - if (current == null) { - return null; - } - current = current.toLowerCase(); - String[] array = StringUtils.split(current, "_"); - if (array.length == 1) { - return capitalize(current); - } - StringBuffer buf = new StringBuffer(CAMELIZE_BUFF_SIZE); - for (int i = 0; i < array.length; ++i) { - buf.append(capitalize(array[i])); - } - return buf.toString(); - } - - /** - * JavaBeansの仕様にしたがってキャピタライズを行ないます。 - * 大文字が2つ以上続く場合は、大文字にならないので注意してください。 - * - * @param name 名前 - * @return 結果の文字列 - */ - public static String capitalize(final String name) { - if (isEmpty(name)) { - return name; - } - char[] chars = name.toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - return new String(chars); - } - - /** - * charを含んでいるかどうか返します。 - * - * @param str 文字列 - * @param ch char - * @return charを含んでいるかどうか - */ - public static boolean contains(final String str, final char ch) { - if (isEmpty(str)) { - return false; - } - return str.indexOf(ch) >= 0; - } - - /** - * 文字列を含んでいるかどうか返します。 - * - * @param s1 文字列 - * @param s2 比較する対象となる文字列 - * @return 文字列を含んでいるかどうか - */ - public static boolean contains(final String s1, final String s2) { - if (isEmpty(s1)) { - return false; - } - return s1.indexOf(s2) >= 0; - } - - /** - * キャメル記法を_記法に変換します。 - * - * @param s テキスト - * @return 結果の文字列 - */ - public static String decamelize(final String s) { - if (s == null) { - return null; - } - if (s.length() == 1) { - return s.toUpperCase(); - } - StringBuffer buf = new StringBuffer(CAMELIZE_BUFF_SIZE); - int pos = 0; - for (int i = 1; i < s.length(); ++i) { - if (Character.isUpperCase(s.charAt(i))) { - if (buf.length() != 0) { - buf.append('_'); - } - buf.append(s.substring(pos, i).toUpperCase()); - pos = i; - } - } - if (buf.length() != 0) { - buf.append('_'); - } - buf.append(s.substring(pos, s.length()).toUpperCase()); - return buf.toString(); - } - - /** - * JavaBeansの仕様にしたがってデキャピタライズを行ないます。大文字が2つ以上続く場合は、小文字にならないので注意してください。 - * - * @param name 名前 - * @return 結果の文字列 - */ - public static String decapitalize(final String name) { - if (isEmpty(name)) { - return name; - } - char[] chars = name.toCharArray(); - if (chars.length >= 2 && Character.isUpperCase(chars[0]) && Character.isUpperCase(chars[1])) { - return name; - } - chars[0] = Character.toLowerCase(chars[0]); - return new String(chars); - } - - /** - * ケースインセンシティブで特定の文字で終わっているのかどうかを返します。 - * - * @param target1 テキスト - * @param target2 比較する文字列 - * @return ケースインセンシティブで特定の文字で終わっているのかどうか - */ - public static boolean endsWithIgnoreCase(final String target1, final String target2) { - if (target1 == null || target2 == null) { - return false; - } - int length1 = target1.length(); - int length2 = target2.length(); - if (length1 < length2) { - return false; - } - String s1 = target1.substring(length1 - length2); - return s1.equalsIgnoreCase(target2); - } - - /** - * 文字列同士が等しいかどうか返します。どちらもnullの場合は、<code>true</code>を返します。 - * - * @param target1 文字列1 - * @param target2 文字列2 - * @return 文字列同士が等しいかどうか - */ - public static boolean equals(final String target1, final String target2) { - return (target1 == null) ? (target2 == null) : target1.equals(target2); - } - - /** - * ケースインセンシティブで文字列同士が等しいかどうか返します。どちらもnullの場合は、<code>true</code>を返します。 - * - * @param target1 文字列1 - * @param target2 文字列2 - * @return ケースインセンシティブで文字列同士が等しいか - */ - public static boolean equalsIgnoreCase(final String target1, final String target2) { - return (target1 == null) ? (target2 == null) : target1.equalsIgnoreCase(target2); - } - - /** - * ブランクかどうか返します。 - * - * @param str 文字列 - * @return ブランクかどうか - */ - public static boolean isBlank(final String str) { - if (str == null || str.length() == 0) { - return true; - } - for (int i = 0; i < str.length(); i++) { - if (!Character.isWhitespace(str.charAt(i))) { - return false; - } - } - return true; - } - - /** - * 文字列が<code>null</code>または空文字列なら<code>true</code>を返します。 - * - * @param text 文字列 - * @return 文字列が<code>null</code>または空文字列なら<code>true</code> - */ - public static boolean isEmpty(final String text) { - return text == null || text.length() == 0; - } - - /** - * ブランクではないかどうか返します。 - * - * @param str 文字列 - * @return ブランクではないかどうか - * @see #isBlank(String) - */ - public static boolean isNotBlank(final String str) { - return !isBlank(str); - } - - /** - * 文字列が<code>null</code>でも空文字列でもなければ<code>true</code>を返します。 - * - * @param text 文字列 - * @return 文字列が<code>null</code>でも空文字列でもなければ<code>true</code> - * @since 2.4.33 - */ - public static boolean isNotEmpty(final String text) { - return !isEmpty(text); - } - - /** - * 文字列が数値のみで構成されているかどうかを返します。 - * - * @param s 文字列 - * @return 数値のみで構成されている場合、<code>true</code> - */ - public static boolean isNumber(final String s) { - if (s == null || s.length() == 0) { - return false; - } - - int size = s.length(); - for (int i = 0; i < size; i++) { - char chr = s.charAt(i); - if (chr < '0' || '9' < chr) { - return false; - } - } - - return true; - } - - /** - * 左側の空白を削ります。 - * - * @param text テキスト - * @return 結果の文字列 - */ - public static String ltrim(final String text) { - return ltrim(text, null); - } - - /** - * 左側の指定した文字列を削ります。 - * - * @param text テキスト - * @param trimText 削るテキスト - * @return 結果の文字列 - */ - public static String ltrim(final String text, String trimText) { - if (text == null) { - return null; - } - if (trimText == null) { - trimText = " "; - } - int pos = 0; - for (; pos < text.length(); pos++) { - if (trimText.indexOf(text.charAt(pos)) < 0) { - break; - } - } - return text.substring(pos); - } - - /** - * 文字列を置き換えます。 - * - * @param text テキスト - * @param fromText 置き換え対象のテキスト - * @param toText 置き換えるテキスト - * @return 結果 - */ - public static String replace(final String text, final String fromText, final String toText) { - if (text == null || fromText == null || toText == null) { - return null; - } - StringBuffer buf = new StringBuffer(REPLACE_BUFF_SIZE); - int pos = 0; - int pos2 = 0; - while (true) { - pos = text.indexOf(fromText, pos2); - if (pos == 0) { - buf.append(toText); - pos2 = fromText.length(); - } else if (pos > 0) { - buf.append(text.substring(pos2, pos)); - buf.append(toText); - pos2 = pos + fromText.length(); - } else { - buf.append(text.substring(pos2)); - break; - } - } - return buf.toString(); - } - - /** - * 右側の空白を削ります。 - * - * @param text テキスト - * @return 結果の文字列 - */ - public static String rtrim(final String text) { - return rtrim(text, null); - } - - /** - * 右側の指定した文字列を削ります。 - * - * @param text テキスト - * @param trimText 削る文字列 - * @return 結果の文字列 - */ - public static String rtrim(final String text, String trimText) { - if (text == null) { - return null; - } - if (trimText == null) { - trimText = " "; - } - int pos = text.length() - 1; - for (; pos >= 0; pos--) { - if (trimText.indexOf(text.charAt(pos)) < 0) { - break; - } - } - return text.substring(0, pos + 1); - } - - /** - * 文字列を分割します。 - * - * @param str 文字列 - * @param delim 分割するためのデリミタ - * @return 分割された文字列の配列 - */ - public static String[] split(final String str, final String delim) { - if (isEmpty(str)) { - return EMPTY_STRINGS; - } - return str.split(delim); - } - - /** - * ケースインセンシティブで特定の文字ではじまっているのかどうかを返します。 - * - * @param target1 テキスト - * @param target2 比較する文字列 - * @return ケースインセンシティブで特定の文字ではじまっているのかどうか - */ - public static boolean startsWithIgnoreCase(final String target1, final String target2) { - if (target1 == null || target2 == null) { - return false; - } - int length1 = target1.length(); - int length2 = target2.length(); - if (length1 < length2) { - return false; - } - String s1 = target1.substring(0, target2.length()); - return s1.equalsIgnoreCase(target2); - } - - /** - * 文字列の最後から指定した文字列で始まっている部分より手前を返します。 - * - * @param str 文字列 - * @param separator セパレータ - * @return 結果の文字列 - */ - public static String substringFromLast(final String str, final String separator) { - if (isEmpty(str) || isEmpty(separator)) { - return str; - } - int pos = str.lastIndexOf(separator); - if (pos == -1) { - return str; - } - return str.substring(0, pos); - } - - /** - * 文字列の最後から指定した文字列で始まっている部分より後ろを返します。 - * - * @param str 文字列 - * @param separator セパレータ - * @return 結果の文字列 - */ - public static String substringToLast(final String str, final String separator) { - if (isEmpty(str) || isEmpty(separator)) { - return str; - } - int pos = str.lastIndexOf(separator); - if (pos == -1) { - return str; - } - return str.substring(pos + 1, str.length()); - } - - /** - * 16進数の文字列に変換します。 - * - * @param bytes バイトの配列 - * @return 16進数の文字列 - */ - public static String toHex(final byte[] bytes) { - if (bytes == null) { - return ""; - } - StringBuffer sb = new StringBuffer(bytes.length * 2); - for (int i = 0; i < bytes.length; ++i) { - appendHex(sb, bytes[i]); - } - return sb.toString(); - } - - /** - * 16進数の文字列に変換します。 - * - * @param i int - * @return 16進数の文字列 - */ - public static String toHex(final int i) { - StringBuffer buf = new StringBuffer(); - appendHex(buf, i); - return buf.toString(); - } - - /** - * プレフィックスを削除する。 - * - * @param text テキスト - * @param prefix プレフィックス - * @return 結果の文字列 - */ - public static String trimPrefix(final String text, final String prefix) { - if (text == null) { - return null; - } - if (prefix == null) { - return text; - } - if (text.startsWith(prefix)) { - return text.substring(prefix.length()); - } - return text; - } - - /** - * サフィックスを削ります。 - * - * @param text テキスト - * @param suffix サフィックス - * @return 結果の文字列 - */ - public static String trimSuffix(final String text, final String suffix) { - if (text == null) { - return null; - } - if (suffix == null) { - return text; - } - if (text.endsWith(suffix)) { - return text.substring(0, text.length() - suffix.length()); - } - return text; - } - - private StringUtil() { - throw new JiemamyError("不到達ポイント"); - } - -} Copied: leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java (from rev 3564, leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/StringUtil.java) =================================================================== --- leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java (rev 0) +++ leto/jiemamy-commons/tags/release/0.0.2/src/main/java/org/jiemamy/utils/StringUtil.java 2009-09-14 17:14:37 UTC (rev 3568) @@ -0,0 +1,549 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/06/09 + * + * This file is part of Jiemamy. + * + * 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 org.jiemamy.utils; + +import java.util.Locale; + +import org.apache.commons.lang.StringUtils; + +import org.jiemamy.exception.JiemamyError; + +/** + * Stringユーティリティ。 + * + * @author j5ik2o + */ +public final class StringUtil { + + private static final int C_8 = 8; + + private static final int C_16 = 16; + + private static final int C_24 = 24; + + private static final int C_0XFF = 0xff; + + private static final int C_0X0F = 0x0f; + + private static final int C_0XF0 = 0xf0; + + private static final int CAMELIZE_BUFF_SIZE = 40; + + private static final int REPLACE_BUFF_SIZE = 100; + + /** 空の文字列の配列。*/ + public static final String[] EMPTY_STRINGS = new String[0]; + + + /** + * 文字列に、数値を16進数に変換した文字列を追加します。 + * + * @param buf 追加先の文字列 + * @param i 数値 + */ + public static void appendHex(final StringBuffer buf, final byte i) { + buf.append(Character.forDigit((i & C_0X0F) >> 4, 16)); + buf.append(Character.forDigit(i & C_0XF0, 16)); + } + + /** + * 文字列に、数値を16進数に変換した文字列を追加します。 + * + * @param buf 追加先の文字列 + * @param i 数値 + */ + public static void appendHex(final StringBuffer buf, final int i) { + buf.append(Integer.toHexString((i >> C_24) & C_0XFF)); + buf.append(Integer.toHexString((i >> C_16) & C_0XFF)); + buf.append(Integer.toHexString((i >> C_8) & C_0XFF)); + buf.append(Integer.toHexString(i & C_0XFF)); + } + + /** + * _記法をキャメル記法に変換します。 + * + * @param s テキスト + * @return 結果の文字列 + */ + public static String camelize(String s) { + String current = s; + if (current == null) { + return null; + } + current = current.toLowerCase(Locale.getDefault()); + String[] array = StringUtils.split(current, "_"); + if (array.length == 1) { + return capitalize(current); + } + StringBuffer buf = new StringBuffer(CAMELIZE_BUFF_SIZE); + for (int i = 0; i < array.length; ++i) { + buf.append(capitalize(array[i])); + } + return buf.toString(); + } + + /** + * JavaBeansの仕様にしたがってキャピタライズを行ないます。 + * 大文字が2つ以上続く場合は、大文字にならないので注意してください。 + * + * @param name 名前 + * @return 結果の文字列 + */ + public static String capitalize(final String name) { + if (isEmpty(name)) { + return name; + } + char[] chars = name.toCharArray(); + chars[0] = Character.toUpperCase(chars[0]); + return new String(chars); + } + + /** + * charを含んでいるかどうか返します。 + * + * @param str 文字列 + * @param ch char + * @return charを含んでいるかどうか + */ + public static boolean contains(final String str, final char ch) { + if (isEmpty(str)) { + return false; + } + return str.indexOf(ch) >= 0; + } + + /** + * 文字列を含んでいるかどうか返します。 + * + * @param s1 文字列 + * @param s2 比較する対象となる文字列 + * @return 文字列を含んでいるかどうか + */ + public static boolean contains(final String s1, final String s2) { + if (isEmpty(s1)) { + return false; + } + return s1.indexOf(s2) >= 0; + } + + /** + * キャメル記法を_記法に変換します。 + * + * @param s テキスト + * @return 結果の文字列 + */ + public static String decamelize(final String s) { + if (s == null) { + return null; + } + if (s.length() == 1) { + return s.toUpperCase(Locale.getDefault()); + } + StringBuffer buf = new StringBuffer(CAMELIZE_BUFF_SIZE); + int pos = 0; + for (int i = 1; i < s.length(); ++i) { + if (Character.isUpperCase(s.charAt(i))) { + if (buf.length() != 0) { + buf.append('_'); + } + buf.append(s.substring(pos, i).toUpperCase(Locale.getDefault())); + pos = i; + } + } + if (buf.length() != 0) { + buf.append('_'); + } + buf.append(s.substring(pos, s.length()).toUpperCase(Locale.getDefault())); + return buf.toString(); + } + + /** + * JavaBeansの仕様にしたがってデキャピタライズを行ないます。大文字が2つ以上続く場合は、小文字にならないので注意してください。 + * + * @param name 名前 + * @return 結果の文字列 + */ + public static String decapitalize(final String name) { + if (isEmpty(name)) { + return name; + } + char[] chars = name.toCharArray(); + if (chars.length >= 2 && Character.isUpperCase(chars[0]) && Character.isUpperCase(chars[1])) { + return name; + } + chars[0] = Character.toLowerCase(chars[0]); + return new String(chars); + } + + /** + * ケースインセンシティブで特定の文字で終わっているのかどうかを返します。 + * + * @param target1 テキスト + * @param target2 比較する文字列 + * @return ケースインセンシティブで特定の文字で終わっているのかどうか + */ + public static boolean endsWithIgnoreCase(final String target1, final String target2) { + if (target1 == null || target2 == null) { + return false; + } + int length1 = target1.length(); + int length2 = target2.length(); + if (length1 < length2) { + return false; + } + String s1 = target1.substring(length1 - length2); + return s1.equalsIgnoreCase(target2); + } + + /** + * 文字列同士が等しいかどうか返します。どちらもnullの場合は、<code>true</code>を返します。 + * + * @param target1 文字列1 + * @param target2 文字列2 + * @return 文字列同士が等しいかどうか + */ + public static boolean equals(final String target1, final String target2) { + return (target1 == null) ? (target2 == null) : target1.equals(target2); + } + + /** + * ケースインセンシティブで文字列同士が等しいかどうか返します。どちらもnullの場合は、<code>true</code>を返します。 + * + * @param target1 文字列1 + * @param target2 文字列2 + * @return ケースインセンシティブで文字列同士が等しいか + */ + public static boolean equalsIgnoreCase(final String target1, final String target2) { + return (target1 == null) ? (target2 == null) : target1.equalsIgnoreCase(target2); + } + + /** + * ブランクかどうか返します。 + * + * @param str 文字列 + * @return ブランクかどうか + */ + public static boolean isBlank(final String str) { + if (str == null || str.length() == 0) { + return true; + } + for (int i = 0; i < str.length(); i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return false; + } + } + return true; + } + + /** + * 文字列が<code>null</code>または空文字列なら<code>true</code>を返します。 + * + * @param text 文字列 + * @return 文字列が<code>null</code>または空文字列なら<code>true</code> + */ + public static boolean isEmpty(final String text) { + return text == null || text.length() == 0; + } + + /** + * ブランクではないかどうか返します。 + * + * @param str 文字列 + * @return ブランクではないかどうか + * @see #isBlank(String) + */ + public static boolean isNotBlank(final String str) { + return !isBlank(str); + } + + /** + * 文字列が<code>null</code>でも空文字列でもなければ<code>true</code>を返します。 + * + * @param text 文字列 + * @return 文字列が<code>null</code>でも空文字列でもなければ<code>true</code> + * @since 2.4.33 + */ + public static boolean isNotEmpty(final String text) { + return !isEmpty(text); + } + + /** + * 文字列が数値のみで構成されているかどうかを返します。 + * + * @param s 文字列 + * @return 数値のみで構成されている場合、<code>true</code> + */ + public static boolean isNumber(final String s) { + if (s == null || s.length() == 0) { + return false; + } + + int size = s.length(); + for (int i = 0; i < size; i++) { + char chr = s.charAt(i); + if (chr < '0' || '9' < chr) { + return false; + } + } + + return true; + } + + /** + * 左側の空白を削ります。 + * + * @param text テキスト + * @return 結果の文字列 + */ + public static String ltrim(final String text) { + return ltrim(text, null); + } + + /** + * 左側の指定した文字列を削ります。 + * + * @param text テキスト + * @param trimText 削るテキスト + * @return 結果の文字列 + */ + public static String ltrim(final String text, String trimText) { + if (text == null) { + return null; + } + if (trimText == null) { + trimText = " "; + } + int pos = 0; + for (; pos < text.length(); pos++) { + if (trimText.indexOf(text.charAt(pos)) < 0) { + break; + } + } + return text.substring(pos); + } + + /** + * 文字列を置き換えます。 + * + * @param text テキスト + * @param fromText 置き換え対象のテキスト + * @param toText 置き換えるテキスト + * @return 結果 + */ + public static String replace(final String text, final String fromText, final String toText) { + if (text == null || fromText == null || toText == null) { + return null; + } + StringBuffer buf = new StringBuffer(REPLACE_BUFF_SIZE); + int pos = 0; + int pos2 = 0; + while (true) { + pos = text.indexOf(fromText, pos2); + if (pos == 0) { + buf.append(toText); + pos2 = fromText.length(); + } else if (pos > 0) { + buf.append(text.substring(pos2, pos)); + buf.append(toText); + pos2 = pos + fromText.length(); + } else { + buf.append(text.substring(pos2)); + break; + } + } + return buf.toString(); + } + + /** + * 右側の空白を削ります。 + * + * @param text テキスト + * @return 結果の文字列 + */ + public static String rtrim(final String text) { + return rtrim(text, null); + } + + /** + * 右側の指定した文字列を削ります。 + * + * @param text テキスト + * @param trimText 削る文字列 + * @return 結果の文字列 + */ + public static String rtrim(final String text, String trimText) { + if (text == null) { + return null; + } + if (trimText == null) { + trimText = " "; + } + int pos = text.length() - 1; + for (; pos >= 0; pos--) { + if (trimText.indexOf(text.charAt(pos)) < 0) { + break; + } + } + return text.substring(0, pos + 1); + } + + /** + * 文字列を分割します。 + * + * @param str 文字列 + * @param delim 分割するためのデリミタ + * @return 分割された文字列の配列 + */ + public static String[] split(final String str, final String delim) { + if (isEmpty(str)) { + return EMPTY_STRINGS; + } + return str.split(delim); + } + + /** + * ケースインセンシティブで特定の文字ではじまっているのかどうかを返します。 + * + * @param target1 テキスト + * @param target2 比較する文字列 + * @return ケースインセンシティブで特定の文字ではじまっているのかどうか + */ + public static boolean startsWithIgnoreCase(final String target1, final String target2) { + if (target1 == null || target2 == null) { + return false; + } + int length1 = target1.length(); + int length2 = target2.length(); + if (length1 < length2) { + return false; + } + String s1 = target1.substring(0, target2.length()); + return s1.equalsIgnoreCase(target2); + } + + /** + * 文字列の最後から指定した文字列で始まっている部分より手前を返します。 + * + * @param str 文字列 + * @param separator セパレータ + * @return 結果の文字列 + */ + public static String substringFromLast(final String str, final String separator) { + if (isEmpty(str) || isEmpty(separator)) { + return str; + } + int pos = str.lastIndexOf(separator); + if (pos == -1) { + return str; + } + return str.substring(0, pos); + } + + /** + * 文字列の最後から指定した文字列で始まっている部分より後ろを返します。 + * + * @param str 文字列 + * @param separator セパレータ + * @return 結果の文字列 + */ + public static String substringToLast(final String str, final String separator) { + if (isEmpty(str) || isEmpty(separator)) { + return str; + } + int pos = str.lastIndexOf(separator); + if (pos == -1) { + return str; + } + return str.substring(pos + 1, str.length()); + } + + /** + * 16進数の文字列に変換します。 + * + * @param bytes バイトの配列 + * @return 16進数の文字列 + */ + public static String toHex(final byte[] bytes) { + if (bytes == null) { + return ""; + } + StringBuffer sb = new StringBuffer(bytes.length * 2); + for (int i = 0; i < bytes.length; ++i) { + appendHex(sb, bytes[i]); + } + return sb.toString(); + } + + /** + * 16進数の文字列に変換します。 + * + * @param i int + * @return 16進数の文字列 + */ + public static String toHex(final int i) { + StringBuffer buf = new StringBuffer(); + appendHex(buf, i); + return buf.toString(); + } + + /** + * プレフィックスを削除する。 + * + * @param text テキスト + * @param prefix プレフィックス + * @return 結果の文字列 + */ + public static String trimPrefix(final String text, final String prefix) { + if (text == null) { + return null; + } + if (prefix == null) { + return text; + } + if (text.startsWith(prefix)) { + return text.substring(prefix.length()); + } + return text; + } + + /** + * サフィックスを削ります。 + * + * @param text テキスト + * @param suffix サフィックス + * @return 結果の文字列 + */ + public static String trimSuffix(final String text, final String suffix) { + if (text == null) { + return null; + } + if (suffix == null) { + return text; + } + if (text.endsWith(suffix)) { + return text.substring(0, text.length() - suffix.length()); + } + return text; + } + + private StringUtil() { + throw new JiemamyError("不到達ポイント"); + } + +}