Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 21 #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/org/noggit/IteratorWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright 2006- Yonik Seeley
*
* 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.noggit;

import java.io.IOException;

/**
* Interface to help do push writing to an array
*/
public interface IteratorWriter {
/**
* @param iw after this method returns , the ItemWriter Object is invalid
* Do not hold a reference to this object
*/
void writeIter(ItemWriter iw) throws IOException;

interface ItemWriter {
/**
* The item could be any supported type
*/
ItemWriter add(Object o) throws IOException;

default ItemWriter add(int v) throws IOException {
add((Integer) v);
return this;
}


default ItemWriter add(long v) throws IOException {
add((Long) v);
return this;
}


default ItemWriter add(float v) throws IOException {
add((Float) v);
return this;
}

default ItemWriter add(double v) throws IOException {
add((Double) v);
return this;
}

default ItemWriter add(boolean v) throws IOException {
add((Boolean) v);
return this;
}
}

}
78 changes: 78 additions & 0 deletions src/main/java/org/noggit/MapWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.noggit;

/**
* Copyright 2006- Yonik Seeley
*
* 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.
*/

import java.io.IOException;

/**
* Use this class to push all entries of a Map into an output.
* This avoids creating map instances and is supposed to be memory efficient.
* If the entries are primitives, unnecessary boxing is also avoided
*/
public interface MapWriter {



void writeMap(EntryWriter ew) throws IOException;

/**
* An interface to push one entry at a time to the output
*/
interface EntryWriter {

/**
* Writes a key value into the map
*
* @param k The key
* @param v The value can be any supported object
*/
EntryWriter put(String k, Object v) throws IOException;

default EntryWriter putIfNotNull(String k, Object v) throws IOException {
if(v != null) put(k,v);
return this;
}


default EntryWriter put(String k, int v) throws IOException {
put(k, (Integer) v);
return this;
}


default EntryWriter put(String k, long v) throws IOException {
put(k, (Long) v);
return this;
}


default EntryWriter put(String k, float v) throws IOException {
put(k, (Float) v);
return this;
}

default EntryWriter put(String k, double v) throws IOException {
put(k, (Double) v);
return this;
}

default EntryWriter put(String k, boolean v) throws IOException {
put(k, (Boolean) v);
return this;
}
}
}