-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
669 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.huifer.concurrence.ch1; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* <p>Title : ThreadYield </p> | ||
* <p>Description : yield</p> | ||
* | ||
* @author huifer | ||
* @date 2019-03-27 | ||
*/ | ||
public class ThreadYield { | ||
|
||
public static void main(String[] args) { | ||
Task task1 = new Task(true); | ||
Task task2 = new Task(false); | ||
new Thread(task1).start(); | ||
new Thread(task2).start(); | ||
} | ||
|
||
|
||
private static class Task implements Runnable { | ||
|
||
private final boolean isYield; | ||
private List<String> stringList = new ArrayList<>(); | ||
|
||
public Task(boolean isYield) { | ||
this.isYield = isYield; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
String name = Thread.currentThread().getName(); | ||
System.out.println(name + " start:"); | ||
for (int i = 0; i < 1000000; i++) { | ||
if (isYield) { | ||
stringList.add("NO." + i); | ||
Thread.yield(); | ||
} | ||
} | ||
System.out.println(name + " end:"); | ||
|
||
} | ||
} | ||
|
||
|
||
} |
241 changes: 241 additions & 0 deletions
241
docs/spring/csbaaf1c16-55c3-11ee-9bca-acde48001122.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.apache.ibatis.parsing; | ||
|
||
import org.apache.ibatis.builder.BuilderException; | ||
import org.apache.ibatis.io.Resources; | ||
import org.junit.jupiter.api.Test; | ||
import org.w3c.dom.Document; | ||
import org.xml.sax.InputSource; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.Reader; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class XPathParserTest { | ||
private String resource = "resources/nodelet_test.xml"; | ||
|
||
// InputStream Source | ||
@Test | ||
void constructorWithInputStreamValidationVariablesEntityResolver() throws Exception { | ||
|
||
try (InputStream inputStream = Resources.getResourceAsStream(resource)) { | ||
XPathParser parser = new XPathParser(inputStream, false, null, null); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithInputStreamValidationVariables() throws IOException { | ||
try (InputStream inputStream = Resources.getResourceAsStream(resource)) { | ||
XPathParser parser = new XPathParser(inputStream, false, null); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithInputStreamValidation() throws IOException { | ||
try (InputStream inputStream = Resources.getResourceAsStream(resource)) { | ||
XPathParser parser = new XPathParser(inputStream, false); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithInputStream() throws IOException { | ||
try (InputStream inputStream = Resources.getResourceAsStream(resource)) { | ||
XPathParser parser = new XPathParser(inputStream); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
// Reader Source | ||
@Test | ||
void constructorWithReaderValidationVariablesEntityResolver() throws Exception { | ||
|
||
try (Reader reader = Resources.getResourceAsReader(resource)) { | ||
XPathParser parser = new XPathParser(reader, false, null, null); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithReaderValidationVariables() throws IOException { | ||
try (Reader reader = Resources.getResourceAsReader(resource)) { | ||
XPathParser parser = new XPathParser(reader, false, null); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithReaderValidation() throws IOException { | ||
try (Reader reader = Resources.getResourceAsReader(resource)) { | ||
XPathParser parser = new XPathParser(reader, false); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
@Test | ||
void constructorWithReader() throws IOException { | ||
try (Reader reader = Resources.getResourceAsReader(resource)) { | ||
XPathParser parser = new XPathParser(reader); | ||
testEvalMethod(parser); | ||
} | ||
} | ||
|
||
// Xml String Source | ||
@Test | ||
void constructorWithStringValidationVariablesEntityResolver() throws Exception { | ||
XPathParser parser = new XPathParser(getXmlString(resource), false, null, null); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithStringValidationVariables() throws IOException { | ||
XPathParser parser = new XPathParser(getXmlString(resource), false, null); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithStringValidation() throws IOException { | ||
XPathParser parser = new XPathParser(getXmlString(resource), false); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithString() throws IOException { | ||
XPathParser parser = new XPathParser(getXmlString(resource)); | ||
testEvalMethod(parser); | ||
} | ||
|
||
// Document Source | ||
@Test | ||
void constructorWithDocumentValidationVariablesEntityResolver() { | ||
XPathParser parser = new XPathParser(getDocument(resource), false, null, null); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithDocumentValidationVariables() { | ||
XPathParser parser = new XPathParser(getDocument(resource), false, null); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithDocumentValidation() { | ||
XPathParser parser = new XPathParser(getDocument(resource), false); | ||
testEvalMethod(parser); | ||
} | ||
|
||
@Test | ||
void constructorWithDocument() { | ||
XPathParser parser = new XPathParser(getDocument(resource)); | ||
testEvalMethod(parser); | ||
} | ||
|
||
private Document getDocument(String resource) { | ||
try { | ||
InputSource inputSource = new InputSource(Resources.getResourceAsReader(resource)); | ||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | ||
factory.setNamespaceAware(false); | ||
factory.setIgnoringComments(true); | ||
factory.setIgnoringElementContentWhitespace(false); | ||
factory.setCoalescing(false); | ||
factory.setExpandEntityReferences(true); | ||
DocumentBuilder builder = factory.newDocumentBuilder(); | ||
return builder.parse(inputSource);// already closed resource in builder.parse method | ||
} catch (Exception e) { | ||
throw new BuilderException("Error creating document instance. Cause: " + e, e); | ||
} | ||
} | ||
|
||
private String getXmlString(String resource) throws IOException { | ||
try (BufferedReader bufferedReader = new BufferedReader(Resources.getResourceAsReader(resource))) { | ||
StringBuilder sb = new StringBuilder(); | ||
String temp; | ||
while ((temp = bufferedReader.readLine()) != null) { | ||
sb.append(temp); | ||
} | ||
return sb.toString(); | ||
} | ||
} | ||
|
||
private void testEvalMethod(XPathParser parser) { | ||
assertEquals((Long) 1970L, parser.evalLong("/employee/birth_date/year")); | ||
assertEquals((short) 6, (short) parser.evalShort("/employee/birth_date/month")); | ||
assertEquals((Integer) 15, parser.evalInteger("/employee/birth_date/day")); | ||
assertEquals((Float) 5.8f, parser.evalFloat("/employee/height")); | ||
assertEquals((Double) 5.8d, parser.evalDouble("/employee/height")); | ||
assertEquals("${id_var}", parser.evalString("/employee/@id")); | ||
assertEquals(Boolean.TRUE, parser.evalBoolean("/employee/active")); | ||
assertEquals("<id>${id_var}</id>", parser.evalNode("/employee/@id").toString().trim()); | ||
assertEquals(7, parser.evalNodes("/employee/*").size()); | ||
XNode node = parser.evalNode("/employee/height"); | ||
assertEquals("employee/height", node.getPath()); | ||
assertEquals("employee[${id_var}]_height", node.getValueBasedIdentifier()); | ||
} | ||
|
||
@Test | ||
public void formatXNodeToString() { | ||
XPathParser parser = new XPathParser("<users><user><id>100</id><name>Tom</name><age>30</age><cars><car>BMW</car><car>Audi</car><car>Benz</car></cars></user></users>"); | ||
String usersNodeToString = parser.evalNode("/users").toString(); | ||
String userNodeToString = parser.evalNode("/users/user").toString(); | ||
String carsNodeToString = parser.evalNode("/users/user/cars").toString(); | ||
|
||
String usersNodeToStringExpect = | ||
"<users>\n" + | ||
" <user>\n" + | ||
" <id>100</id>\n" + | ||
" <name>Tom</name>\n" + | ||
" <age>30</age>\n" + | ||
" <cars>\n" + | ||
" <car>BMW</car>\n" + | ||
" <car>Audi</car>\n" + | ||
" <car>Benz</car>\n" + | ||
" </cars>\n" + | ||
" </user>\n" + | ||
"</users>\n"; | ||
|
||
String userNodeToStringExpect = | ||
"<user>\n" + | ||
" <id>100</id>\n" + | ||
" <name>Tom</name>\n" + | ||
" <age>30</age>\n" + | ||
" <cars>\n" + | ||
" <car>BMW</car>\n" + | ||
" <car>Audi</car>\n" + | ||
" <car>Benz</car>\n" + | ||
" </cars>\n" + | ||
"</user>\n"; | ||
|
||
String carsNodeToStringExpect = | ||
"<cars>\n" + | ||
" <car>BMW</car>\n" + | ||
" <car>Audi</car>\n" + | ||
" <car>Benz</car>\n" + | ||
"</cars>\n"; | ||
|
||
assertEquals(usersNodeToStringExpect, usersNodeToString); | ||
assertEquals(userNodeToStringExpect, userNodeToString); | ||
assertEquals(carsNodeToStringExpect, carsNodeToString); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.apache.ibatis.annotations; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** | ||
* The annotation that specify the parameter name. | ||
* | ||
* <p><br> | ||
* <b>How to use:</b> | ||
* <pre> | ||
* public interface UserMapper { | ||
* @Select("SELECT id, name FROM users WHERE name = #{name}") | ||
* User selectById(@Param("name") String value); | ||
* } | ||
* </pre> | ||
* 参数注解 | ||
* @author Clinton Begin | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.PARAMETER) | ||
public @interface Param { | ||
/** | ||
* Returns the parameter name. | ||
* | ||
* @return the parameter name | ||
*/ | ||
String value(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2009-2016 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.apache.ibatis.submitted.array_result_type; | ||
|
||
import org.apache.ibatis.annotations.Select; | ||
|
||
public interface Mapper { | ||
|
||
@Select("select * from users") | ||
User[] getUsers(); | ||
|
||
User[] getUsersXml(); | ||
|
||
@Select("select id from users") | ||
Integer[] getUserIds(); | ||
|
||
@Select("select id from users") | ||
int[] getUserIdsPrimitive(); | ||
} |
Oops, something went wrong.