You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by ka...@apache.org on 2013/07/19 11:33:12 UTC
[29/61] [partial] Hard rename of all 'org/eobjects' folders to
'org/apache'.
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/Update.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/Update.java b/core/src/main/java/org/eobjects/metamodel/update/Update.java
deleted file mode 100644
index 837a05e..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/Update.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.update;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eobjects.metamodel.DataContext;
-import org.eobjects.metamodel.UpdateCallback;
-import org.eobjects.metamodel.UpdateScript;
-import org.eobjects.metamodel.UpdateableDataContext;
-import org.eobjects.metamodel.data.AbstractRowBuilder;
-import org.eobjects.metamodel.data.Style;
-import org.eobjects.metamodel.data.WhereClauseBuilder;
-import org.eobjects.metamodel.query.FilterItem;
-import org.eobjects.metamodel.query.SelectItem;
-import org.eobjects.metamodel.query.builder.AbstractFilterBuilder;
-import org.eobjects.metamodel.query.builder.FilterBuilder;
-import org.eobjects.metamodel.schema.Column;
-import org.eobjects.metamodel.schema.Table;
-
-/**
- * Represents a single UPDATE operation to be applied to a
- * {@link UpdateableDataContext}. Instead of providing a custom implementation
- * of the {@link UpdateScript} interface, one can use this pre-built update
- * implementation. Some {@link DataContext}s may even optimize specifically
- * based on the knowledge that there will only be a single update statement
- * executed.
- */
-public final class Update extends AbstractRowBuilder<Update> implements UpdateScript, WhereClauseBuilder<Update> {
-
- private final Table _table;
- private final List<FilterItem> _whereItems;
-
- public Update(Table table) {
- super(table);
- _table = table;
- _whereItems = new ArrayList<FilterItem>();
- }
-
- @Override
- public Table getTable() {
- return _table;
- }
-
- @Override
- public void run(UpdateCallback callback) {
- RowUpdationBuilder updateBuilder = callback.update(_table).where(_whereItems);
-
- final Column[] columns = getColumns();
- final Object[] values = getValues();
- final Style[] styles = getStyles();
- final boolean[] explicitNulls = getExplicitNulls();
-
- for (int i = 0; i < columns.length; i++) {
- Object value = values[i];
- Column column = columns[i];
- Style style = styles[i];
- if (value == null) {
- if (explicitNulls[i]) {
- updateBuilder = updateBuilder.value(column, value, style);
- }
- } else {
- updateBuilder = updateBuilder.value(column, value, style);
- }
- }
-
- updateBuilder.execute();
- }
-
- @Override
- public FilterBuilder<Update> where(Column column) {
- SelectItem selectItem = new SelectItem(column);
- return new AbstractFilterBuilder<Update>(selectItem) {
- @Override
- protected Update applyFilter(FilterItem filter) {
- return where(filter);
- }
- };
- }
-
- @Override
- public FilterBuilder<Update> where(String columnName) {
- Column column = _table.getColumnByName(columnName);
- if (column == null) {
- throw new IllegalArgumentException("No such column: " + columnName);
- }
- return where(column);
- }
-
- @Override
- public Update where(FilterItem... filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-
- @Override
- public Update where(Iterable<FilterItem> filterItems) {
- for (FilterItem filterItem : filterItems) {
- _whereItems.add(filterItem);
- }
- return this;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/update/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/update/package-info.java b/core/src/main/java/org/eobjects/metamodel/update/package-info.java
deleted file mode 100644
index d29b7d0..0000000
--- a/core/src/main/java/org/eobjects/metamodel/update/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-/**
- * API for updating rows
- */
-package org.eobjects.metamodel.update;
-
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Action.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Action.java b/core/src/main/java/org/eobjects/metamodel/util/Action.java
deleted file mode 100644
index bf0bbc4..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Action.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * Represents an abstract action, which is an executable piece of functionality
- * that takes an argument. An {@link Action} has no return type, unlike a
- * {@link Func}.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the argument type of the action
- */
-public interface Action<E> {
-
- public void run(E arg) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java b/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
deleted file mode 100644
index 3663959..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/AggregateBuilder.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * Interface for aggregate builders which allows for an iterative approach to
- * evaluating aggregates.
- *
- * @author Kasper Sørensen
- *
- * @param <E>
- * the aggregate result type
- */
-public interface AggregateBuilder<E> {
-
- public void add(Object o);
-
- public E getAggregate();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java b/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
deleted file mode 100644
index d47b0af..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/AlphabeticSequence.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * A sequence based on alphabetic representations. Typically a sequence begin
- * with "A", "B", "C" etc. and go from "Z" to "AA", from "AZ" to "BA" etc.
- *
- * This sequence is practical for generating column names that correspond to
- * column identifiers in spreadsheets and the like.
- *
- * @author Kasper Sørensen
- */
-public class AlphabeticSequence {
-
- private StringBuilder _stringBuilder;
-
- /**
- * Creates an alphabetic sequence that will have "A" as it's first value, if
- * iterated using next().
- */
- public AlphabeticSequence() {
- this(Character.toString((char) ('A' - 1)));
- }
-
- /**
- * Creates an alphabetic sequence based on a value
- *
- * @param value
- */
- public AlphabeticSequence(String value) {
- _stringBuilder = new StringBuilder(value.toUpperCase());
- }
-
- /**
- * Gets the current value (ie. doesn't iterate).
- *
- * @return a string identifier, eg. "A", "B", "AA" etc.
- */
- public String current() {
- return _stringBuilder.toString();
- }
-
- /**
- * Iterates to the next value and returns it.
- *
- * @return a string identifier, eg. "A", "B", "AA" etc.
- */
- public String next() {
- boolean updated = false;
- int length = _stringBuilder.length();
- for (int i = length - 1; i >= 0; i--) {
- char c = _stringBuilder.charAt(i);
- if (c != 'Z') {
- c = (char) (c + 1);
- _stringBuilder.setCharAt(i, c);
- updated = true;
- break;
- } else {
- _stringBuilder.setCharAt(i, 'A');
- }
- }
-
- if (!updated) {
- // need to add another char
- _stringBuilder.append('A');
- }
- return current();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java b/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
deleted file mode 100644
index dde30da..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/BaseObject.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A base object type with conveniently implemented base methods like hashCode()
- * and equals(). Subclasses should implement the {@link #decorateIdentity(List)}
- * method to have {@link #equals(Object)} and {@link #hashCode()} automatically
- * implemented.
- *
- * @author Kasper Sørensen
- */
-public abstract class BaseObject {
-
- private static final Logger logger = LoggerFactory
- .getLogger(BaseObject.class);
-
- @Override
- public String toString() {
- // overridden version of toString() method that uses identity hash code
- // (to prevent hashCode() recursion due to logging!)
- return getClass().getName() + "@"
- + Integer.toHexString(System.identityHashCode(this));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final int hashCode() {
- logger.debug("{}.hashCode()", this);
- int hashCode = -1;
- List<Object> list = new ArrayList<Object>();
- decorateIdentity(list);
- if (list.isEmpty()) {
- list.add(toString());
- }
- hashCode -= list.size();
- for (Object obj : list) {
- hashCode += hashCode(obj);
- }
- return hashCode;
- }
-
- private static final int hashCode(Object obj) {
- if (obj == null) {
- logger.debug("obj is null, returning constant");
- return -17;
- }
- if (obj.getClass().isArray()) {
- logger.debug("obj is an array, returning a sum");
- int length = Array.getLength(obj);
- int hashCode = 4324;
- for (int i = 0; i < length; i++) {
- Object o = Array.get(obj, i);
- hashCode += hashCode(o);
- }
- return hashCode;
- }
- logger.debug("obj is a regular object, returning hashCode");
- return obj.hashCode();
- }
-
- /**
- * Override this method if the equals method should support different
- * subtypes. For example, if different subtypes of Number should be
- * supported, implement this method with:
- *
- * <code>
- * obj instanceof Number
- * </code>
- *
- * and make sure that the decorateIdentity(...) method will always return a
- * comparable list of identity-objects.
- *
- * @param obj
- * @return true if the provided object's class is accepted for equals
- * comparison
- */
- protected boolean classEquals(BaseObject obj) {
- return getClass() == obj.getClass();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj instanceof BaseObject) {
- BaseObject that = (BaseObject) obj;
- if (classEquals(that)) {
- List<Object> list1 = new ArrayList<Object>();
- List<Object> list2 = new ArrayList<Object>();
-
- decorateIdentity(list1);
- that.decorateIdentity(list2);
-
- if (list1.size() != list2.size()) {
- throw new IllegalStateException(
- "Two instances of the same class ("
- + getClass().getName()
- + ") returned different size decorated identity lists");
- }
-
- if (list1.isEmpty()) {
- assert list2.isEmpty();
- list1.add(toString());
- list2.add(that.toString());
- }
-
- EqualsBuilder eb = new EqualsBuilder();
-
- Iterator<Object> it1 = list1.iterator();
- Iterator<Object> it2 = list2.iterator();
- while (it1.hasNext()) {
- assert it2.hasNext();
- Object next1 = it1.next();
- Object next2 = it2.next();
- eb.append(next1, next2);
- }
- assert !it2.hasNext();
-
- return eb.isEquals();
- }
- }
- return false;
- }
-
- /**
- * Subclasses should implement this method and add all fields to the list
- * that are to be included in equals(...) and hashCode() evaluation
- *
- * @param identifiers
- */
- protected abstract void decorateIdentity(List<Object> identifiers);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java b/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
deleted file mode 100644
index 22bc9f1..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/BooleanComparator.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.util.Comparator;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Comparator of booleans
- *
- * @author Kasper Sørensen
- */
-public final class BooleanComparator implements Comparator<Object> {
-
- private static final Logger logger = LoggerFactory
- .getLogger(BooleanComparator.class);
-
- private static BooleanComparator _instance = new BooleanComparator();
-
- private BooleanComparator() {
- }
-
- public static Comparator<Object> getComparator() {
- return _instance;
- }
-
- public static Comparable<Object> getComparable(Object object) {
- final Boolean b = toBoolean(object);
- return new Comparable<Object>() {
-
- @Override
- public boolean equals(Object obj) {
- return _instance.equals(obj);
- }
-
- public int compareTo(Object o) {
- return _instance.compare(b, o);
- }
-
- @Override
- public String toString() {
- return "BooleanComparable[boolean=" + b + "]";
- }
- };
- }
-
- public int compare(Object o1, Object o2) {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1 == null) {
- return -1;
- }
- if (o2 == null) {
- return 1;
- }
- Boolean b1 = toBoolean(o1);
- Boolean b2 = toBoolean(o2);
- return b1.compareTo(b2);
- }
-
- public static Boolean toBoolean(Object o) {
- if (o == null) {
- return null;
- }
-
- if (o instanceof Boolean) {
- return (Boolean) o;
- }
- if (o instanceof String) {
- try {
- return parseBoolean((String) o);
- } catch (IllegalArgumentException e) {
- logger.warn(
- "Could not convert String '{}' to boolean, returning false", o);
- return false;
- }
- }
- if (o instanceof Number) {
- int i = ((Number) o).intValue();
- return i >= 1;
- }
-
- logger.warn(
- "Could not convert '{}' to boolean, returning false",
- o);
- return false;
- }
-
- /**
- * Parses a string and returns a boolean representation of it. To parse the
- * string the following values will be accepted, irrespective of case.
- * <ul>
- * <li>true</li>
- * <li>false</li>
- * <li>1</li>
- * <li>0</li>
- * <li>yes</li>
- * <li>no</li>
- * <li>y</li>
- * <li>n</li>
- * </ul>
- *
- * @param string
- * the string to parse
- * @return a boolean
- * @throws IllegalArgumentException
- * if the string provided is null or cannot be parsed as a
- * boolean
- */
- public static boolean parseBoolean(String string)
- throws IllegalArgumentException {
- if (string == null) {
- throw new IllegalArgumentException("string cannot be null");
- }
- string = string.trim();
- if ("true".equalsIgnoreCase(string) || "1".equals(string)
- || "y".equalsIgnoreCase(string)
- || "yes".equalsIgnoreCase(string)) {
- return true;
- } else if ("false".equalsIgnoreCase(string) || "0".equals(string)
- || "n".equalsIgnoreCase(string)
- || "no".equalsIgnoreCase(string)) {
- return false;
- } else {
- throw new IllegalArgumentException(
- "Could not get boolean value of string: " + string);
- }
- }
-
- public static boolean isBoolean(Object o) {
- if (o instanceof Boolean) {
- return true;
- }
- if (o instanceof String) {
- if ("true".equalsIgnoreCase((String) o)
- || "false".equalsIgnoreCase((String) o)) {
- return true;
- }
- }
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java b/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
deleted file mode 100644
index 05275a8..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ClasspathResource.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.net.URL;
-
-/**
- * A {@link Resource} based on a classpath entry
- */
-public class ClasspathResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final String _resourcePath;
-
- public ClasspathResource(String resourcePath) {
- if (resourcePath == null) {
- throw new IllegalArgumentException("Classpath resource path cannot be null");
- }
- _resourcePath = resourcePath;
- }
-
- @Override
- public String toString() {
- return "ClasspathResource[" + _resourcePath + "]";
- }
-
- /**
- * Gets the name of the classpath entry
- * @return
- */
- public String getResourcePath() {
- return _resourcePath;
- }
-
- @Override
- public String getName() {
- String name = _resourcePath;
- final int lastSlash = name.lastIndexOf('/');
- final int lastBackSlash = name.lastIndexOf('\\');
- final int lastIndex = Math.max(lastSlash, lastBackSlash);
- if (lastIndex != -1) {
- final String lastPart = name.substring(lastIndex + 1);
- if (!"".equals(lastPart)) {
- return lastPart;
- }
- }
- return name;
- }
-
- protected ClassLoader getClassLoader() {
- return ClassLoader.getSystemClassLoader();
- }
-
- private UrlResource getUrlResourceDelegate() {
- ClassLoader classLoader = getClassLoader();
-
- URL url = classLoader.getResource(_resourcePath);
- if (url == null && _resourcePath.startsWith("/")) {
- url = classLoader.getResource(_resourcePath.substring(1));
- }
-
- if (url == null) {
- return null;
- }
- return new UrlResource(url);
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public boolean isExists() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return false;
- }
- return delegate.isExists();
- }
-
- @Override
- public long getSize() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return -1;
- }
- return delegate.getSize();
- }
-
- @Override
- public long getLastModified() {
- UrlResource delegate = getUrlResourceDelegate();
- if (delegate == null) {
- return -1;
- }
- return delegate.getLastModified();
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- getUrlResourceDelegate().write(writeCallback);
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) throws ResourceException {
- getUrlResourceDelegate().append(appendCallback);
- }
-
- @Override
- public InputStream read() throws ResourceException {
- return getUrlResourceDelegate().read();
- }
-
- @Override
- public void read(Action<InputStream> readCallback) throws ResourceException {
- getUrlResourceDelegate().read(readCallback);
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) throws ResourceException {
- return getUrlResourceDelegate().read(readCallback);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java b/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
deleted file mode 100644
index 52cff9a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/CollectionUtils.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Various utility methods for handling of collections and arrays.
- *
- * @author Kasper Sørensen
- */
-public final class CollectionUtils {
-
- private CollectionUtils() {
- // prevent instantiation
- }
-
- /**
- * Concatenates two arrays
- *
- * @param existingArray an existing array
- * @param elements the elements to add to the end of it
- * @return
- */
- @SuppressWarnings("unchecked")
- public static <E> E[] array(final E[] existingArray, final E... elements) {
- if (existingArray == null) {
- return elements;
- }
- Object result = Array.newInstance(existingArray.getClass()
- .getComponentType(), existingArray.length + elements.length);
- System.arraycopy(existingArray, 0, result, 0, existingArray.length);
- System.arraycopy(elements, 0, result, existingArray.length,
- elements.length);
- return (E[]) result;
- }
-
- public static <E> List<E> concat(boolean removeDuplicates,
- Collection<? extends E> firstCollection,
- Collection<?>... collections) {
- final List<E> result;
- if (removeDuplicates) {
- result = new ArrayList<E>();
- addElements(removeDuplicates, result, firstCollection);
- } else {
- result = new ArrayList<E>(firstCollection);
- }
- for (Collection<?> collection : collections) {
- @SuppressWarnings("unchecked")
- Collection<? extends E> elems = (Collection<? extends E>) collection;
- addElements(removeDuplicates, result, elems);
- }
- return result;
- }
-
- private static <E> void addElements(boolean removeDuplicates,
- final List<E> result, Collection<? extends E> elements) {
- for (E item : elements) {
- if (removeDuplicates) {
- if (!result.contains(item)) {
- result.add(item);
- }
- } else {
- result.add(item);
- }
- }
- }
-
- public static <E> E[] arrayRemove(E[] array, E elementToRemove) {
- @SuppressWarnings("unchecked")
- E[] result = (E[]) arrayRemoveInternal(array, elementToRemove);
- return result;
- }
-
- public static Object arrayRemove(Object array, Object elementToRemove) {
- return arrayRemoveInternal(array, elementToRemove);
- }
-
- private static Object arrayRemoveInternal(Object array,
- Object elementToRemove) {
- boolean found = false;
- final int oldLength = Array.getLength(array);
- if (oldLength == 0) {
- return array;
- }
- final int newLength = oldLength - 1;
- final Object result = Array.newInstance(array.getClass()
- .getComponentType(), newLength);
- int nextIndex = 0;
- for (int i = 0; i < oldLength; i++) {
- final Object e = Array.get(array, i);
- if (e.equals(elementToRemove)) {
- found = true;
- } else {
- if (nextIndex == newLength) {
- break;
- }
- Array.set(result, nextIndex, e);
- nextIndex++;
- }
- }
- if (!found) {
- return array;
- }
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public static <E> E[] arrayOf(Class<E> elementClass, Object arrayOrElement) {
- if (arrayOrElement == null) {
- return null;
- }
- if (arrayOrElement.getClass().isArray()) {
- return (E[]) arrayOrElement;
- }
- Object result = Array.newInstance(elementClass, 1);
- Array.set(result, 0, arrayOrElement);
- return (E[]) result;
- }
-
- public static <E> List<E> filter(E[] items, Predicate<? super E> predicate) {
- return filter(Arrays.asList(items), predicate);
- }
-
- public static <E> List<E> filter(Iterable<E> items,
- Predicate<? super E> predicate) {
- List<E> result = new ArrayList<E>();
- for (E e : items) {
- if (predicate.eval(e).booleanValue()) {
- result.add(e);
- }
- }
- return result;
- }
-
- public static <I, O> List<O> map(I[] items, Func<? super I, O> func) {
- return map(Arrays.asList(items), func);
- }
-
- public static <I, O> List<O> map(Iterable<I> items, Func<? super I, O> func) {
- List<O> result = new ArrayList<O>();
- for (I item : items) {
- O output = func.eval(item);
- result.add(output);
- }
- return result;
- }
-
- public static <E> void forEach(E[] items, Action<? super E> action) {
- forEach(Arrays.asList(items), action);
- }
-
- public static <E> void forEach(Iterable<E> items, Action<? super E> action) {
- for (E item : items) {
- try {
- action.run(item);
- } catch (Exception e) {
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new IllegalStateException("Action threw exception", e);
- }
- }
- }
-
- public static <E> boolean isNullOrEmpty(E[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNullOrEmpty(Collection<?> col) {
- return col == null || col.isEmpty();
- }
-
- /**
- * General purpose list converter method. Will convert arrays, collections,
- * iterables etc. into lists.
- *
- * If the argument is a single object (such as a String or a POJO) it will
- * be wrapped in a single-element list.
- *
- * Null will be converted to the empty list.
- *
- * @param obj
- * any object
- * @return a list representation of the object
- */
- public static List<?> toList(Object obj) {
- final List<Object> result;
- if (obj == null) {
- result = Collections.emptyList();
- } else if (obj instanceof List) {
- @SuppressWarnings("unchecked")
- List<Object> list = (List<Object>) obj;
- result = list;
- } else if (obj.getClass().isArray()) {
- int length = Array.getLength(obj);
- result = new ArrayList<Object>(length);
- for (int i = 0; i < length; i++) {
- result.add(Array.get(obj, i));
- }
- } else if (obj instanceof Iterable) {
- result = new ArrayList<Object>();
- for (Object item : (Iterable<?>) obj) {
- result.add(item);
- }
- } else if (obj instanceof Iterator) {
- result = new ArrayList<Object>();
- Iterator<?> it = (Iterator<?>) obj;
- while (it.hasNext()) {
- result.add(it.next());
- }
- } else {
- result = new ArrayList<Object>(1);
- result.add(obj);
- }
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java b/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
deleted file mode 100644
index d2813ed..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ConstantFunc.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * A function that always returns the same constant response.
- *
- * @param <I>
- * @param <O>
- */
-public final class ConstantFunc<I, O> implements Func<I, O> {
-
- private final O _response;
-
- public ConstantFunc(O response) {
- _response = response;
- }
-
- @Override
- public O eval(I arg) {
- return _response;
- }
-
- @Override
- public int hashCode() {
- if (_response == null) {
- return -1;
- }
- return _response.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj instanceof ConstantFunc) {
- Object otherResponse = ((ConstantFunc<?, ?>) obj)._response;
- if (otherResponse == null && _response == null) {
- return true;
- } else if (_response == null) {
- return false;
- } else {
- return _response.equals(otherResponse);
- }
- }
- return false;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java b/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
deleted file mode 100644
index b146523..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/DateUtils.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-/**
- * Various utility methods pertaining to date handling
- *
- * @author Kasper Sørensen
- */
-public final class DateUtils {
-
- public static final long MILLISECONDS_PER_SECOND = 1000;
- public static final long MILLISECONDS_PER_MINUTE = MILLISECONDS_PER_SECOND * 60;
- public static final long MILLISECONDS_PER_HOUR = MILLISECONDS_PER_MINUTE * 60;
- public static final long MILLISECONDS_PER_DAY = MILLISECONDS_PER_HOUR * 24;
-
- private DateUtils() {
- // prevent instantiation
- }
-
- public static Date get(int year, Month month, int dayOfMonth) {
- Calendar c = createCalendar();
- c.set(Calendar.YEAR, year);
- c.set(Calendar.MONTH, month.getCalendarConstant());
- c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
- c.set(Calendar.HOUR, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- return c.getTime();
- }
-
- public static Date get(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- c.set(Calendar.HOUR, 0);
- c.set(Calendar.MINUTE, 0);
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
-
- return c.getTime();
- }
-
- public static Date get(Date originalDate, int daysDiff) {
- long millis = originalDate.getTime();
- long diff = daysDiff * MILLISECONDS_PER_DAY;
- millis = millis + diff;
- return new Date(millis);
- }
-
- public static int getYear(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- return cal.get(Calendar.YEAR);
- }
-
- public static Month getMonth(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- int monthConstant = cal.get(Calendar.MONTH);
- return Month.getByCalendarConstant(monthConstant);
- }
-
- public static Weekday getWeekday(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- int weekdayConstant = cal.get(Calendar.DAY_OF_WEEK);
- return Weekday.getByCalendarConstant(weekdayConstant);
- }
-
- public static int getDayOfMonth(Date date) {
- Calendar cal = createCalendar();
- cal.setTime(date);
- return cal.get(Calendar.DAY_OF_MONTH);
- }
-
- public static Calendar createCalendar() {
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis(0l);
- return c;
- }
-
- public static DateFormat createDateFormat() {
- return createDateFormat("yyyy-MM-dd HH:mm:ss");
- }
-
- public static DateFormat createDateFormat(String datePattern) {
- SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
- return dateFormat;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java b/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
deleted file mode 100644
index b02b6df..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/EqualsBuilder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.lang.reflect.Array;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A helper class for implementing equals(...) methods.
- *
- * @author Kasper Sørensen
- */
-public final class EqualsBuilder {
-
- private static final Logger logger = LoggerFactory
- .getLogger(EqualsBuilder.class);
- private boolean equals = true;
-
- public EqualsBuilder append(boolean b) {
- logger.debug("append({})", b);
- if (equals) {
- equals = b;
- }
- return this;
- }
-
- public EqualsBuilder append(Object o1, Object o2) {
- if (equals) {
- equals = equals(o1, o2);
- }
- return this;
- }
-
- public static boolean equals(final Object obj1, final Object obj2) {
- if (obj1 == obj2) {
- return true;
- }
-
- if (obj1 == null || obj2 == null) {
- return false;
- }
-
- Class<? extends Object> class1 = obj1.getClass();
- Class<? extends Object> class2 = obj2.getClass();
- if (class1.isArray()) {
- if (!class2.isArray()) {
- return false;
- } else {
- Class<?> componentType1 = class1.getComponentType();
- Class<?> componentType2 = class2.getComponentType();
- if (!componentType1.equals(componentType2)) {
- return false;
- }
-
- int length1 = Array.getLength(obj1);
- int length2 = Array.getLength(obj2);
- if (length1 != length2) {
- return false;
- }
- for (int i = 0; i < length1; i++) {
- Object elem1 = Array.get(obj1, i);
- Object elem2 = Array.get(obj2, i);
- if (!equals(elem1, elem2)) {
- return false;
- }
- }
- return true;
- }
- } else {
- if (class2.isArray()) {
- return false;
- }
- }
-
- return obj1.equals(obj2);
- }
-
- public boolean isEquals() {
- return equals;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java b/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
deleted file mode 100644
index 78744bc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ExclusionPredicate.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * A predicate that uses an exclusion list ("black list") of elements to
- * determine whether to evaluate true or false.
- *
- * @param <E>
- */
-public class ExclusionPredicate<E> implements Predicate<E> {
-
- private final Collection<E> _exclusionList;
-
- public ExclusionPredicate(Collection<E> exclusionList) {
- _exclusionList = exclusionList;
- }
-
- @Override
- public Boolean eval(E arg) {
- if (_exclusionList.contains(arg)) {
- return false;
- }
- return true;
- }
-
- public Collection<E> getExclusionList() {
- return Collections.unmodifiableCollection(_exclusionList);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java b/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
deleted file mode 100644
index 7ba8b2a..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FalsePredicate.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.io.Serializable;
-
-/**
- * A predicate that is always false
- *
- * @param <E>
- */
-public final class FalsePredicate<E> implements Predicate<E>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public Boolean eval(E arg) {
- return false;
- }
-
- @Override
- public int hashCode() {
- return Boolean.FALSE.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj.getClass() == FalsePredicate.class;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java b/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
deleted file mode 100644
index 229baeb..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FileHelper.java
+++ /dev/null
@@ -1,460 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.Flushable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PushbackInputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Various helper methods for handling files
- */
-public final class FileHelper {
-
- private final static Logger logger = LoggerFactory.getLogger(FileHelper.class);
-
- public static final String UTF_8_ENCODING = "UTF-8";
- public static final String UTF_16_ENCODING = "UTF-16";
- public static final String US_ASCII_ENCODING = "US-ASCII";
- public static final String ISO_8859_1_ENCODING = "ISO_8859_1";
- public static final String DEFAULT_ENCODING = UTF_8_ENCODING;
-
- private FileHelper() {
- // prevent instantiation
- }
-
- public static File createTempFile(String prefix, String suffix) {
- try {
- return File.createTempFile(prefix, suffix);
- } catch (IOException e) {
- logger.error("Could not create tempFile", e);
- File tempDir = getTempDir();
- return new File(tempDir, prefix + '.' + suffix);
- }
- }
-
- public static File getTempDir() {
- File result = null;
- String tmpDirPath = System.getProperty("java.io.tmpdir");
- if (tmpDirPath != null && !"".equals(tmpDirPath)) {
- result = new File(tmpDirPath);
- } else {
- logger.debug("Could not determine tmpdir by using environment variable.");
- try {
- File file = File.createTempFile("foo", "bar");
- result = file.getParentFile();
- if (!file.delete()) {
- logger.warn("Could not delete temp file '{}'", file.getAbsolutePath());
- }
- } catch (IOException e) {
- logger.error("Could not create tempFile in order to find temporary dir", e);
- result = new File("metamodel.tmp.dir");
- if (!result.mkdir()) {
- throw new IllegalStateException("Could not create directory for temporary files: " + result.getName());
- }
- result.deleteOnExit();
- }
- }
- if (logger.isInfoEnabled()) {
- logger.info("Using '{}' as tmpdir.", result.getAbsolutePath());
- }
- return result;
- }
-
- public static Writer getWriter(File file, String encoding, boolean append) throws IllegalStateException {
- boolean insertBom = !append;
- return getWriter(file, encoding, append, insertBom);
- }
-
- public static Writer getWriter(OutputStream outputStream, String encoding) throws IllegalStateException {
- return getWriter(outputStream, encoding, false);
- }
-
- public static Writer getWriter(OutputStream outputStream, String encoding, boolean insertBom) throws IllegalStateException {
- if (!(outputStream instanceof BufferedOutputStream)) {
- outputStream = new BufferedOutputStream(outputStream);
- }
-
- try {
- if (insertBom) {
- Writer writer = new UnicodeWriter(outputStream, encoding);
- return writer;
- } else {
- Writer writer = new OutputStreamWriter(outputStream, encoding);
- return writer;
- }
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static Writer getWriter(File file, String encoding, boolean append, boolean insertBom) throws IllegalStateException {
- if (append && insertBom) {
- throw new IllegalArgumentException("Can not insert BOM into appending writer");
- }
- final OutputStream outputStream = getOutputStream(file, append);
- return getWriter(outputStream, encoding, insertBom);
-
- }
-
- public static Writer getWriter(File file, String encoding) throws IllegalStateException {
- return getWriter(file, encoding, false);
- }
-
- public static Reader getReader(InputStream inputStream, String encoding) throws IllegalStateException {
- try {
- if (encoding == null || encoding.toLowerCase().indexOf("utf") != -1) {
- byte bom[] = new byte[4];
- int unread;
-
- // auto-detect byte-order-mark
- PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream, bom.length);
- int n = pushbackInputStream.read(bom, 0, bom.length);
-
- // Read ahead four bytes and check for BOM marks.
- if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
- encoding = "UTF-8";
- unread = n - 3;
- } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
- encoding = "UTF-16BE";
- unread = n - 2;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
- encoding = "UTF-16LE";
- unread = n - 2;
- } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE)
- && (bom[3] == (byte) 0xFF)) {
- encoding = "UTF-32BE";
- unread = n - 4;
- } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00)
- && (bom[3] == (byte) 0x00)) {
- encoding = "UTF-32LE";
- unread = n - 4;
- } else {
- unread = n;
- }
-
- if (unread > 0) {
- pushbackInputStream.unread(bom, (n - unread), unread);
- } else if (unread < -1) {
- pushbackInputStream.unread(bom, 0, 0);
- }
-
- inputStream = pushbackInputStream;
- }
-
- final InputStreamReader inputStreamReader;
- if (encoding == null) {
- inputStreamReader = new InputStreamReader(inputStream);
- } else {
- inputStreamReader = new InputStreamReader(inputStream, encoding);
- }
- return inputStreamReader;
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static Reader getReader(File file, String encoding) throws IllegalStateException {
- final InputStream inputStream;
- try {
- inputStream = new BufferedInputStream(new FileInputStream(file));
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- return getReader(inputStream, encoding);
- }
-
- public static String readInputStreamAsString(InputStream inputStream, String encoding) throws IllegalStateException {
- Reader reader = getReader(inputStream, encoding);
- return readAsString(reader);
- }
-
- public static String readFileAsString(File file, String encoding) throws IllegalStateException {
- Reader br = getReader(file, encoding);
- return readAsString(br);
- }
-
- public static String readAsString(Reader reader) throws IllegalStateException {
- final BufferedReader br = getBufferedReader(reader);
- try {
- StringBuilder sb = new StringBuilder();
- boolean firstLine = true;
- for (String line = br.readLine(); line != null; line = br.readLine()) {
- if (firstLine) {
- firstLine = false;
- } else {
- sb.append('\n');
- }
- sb.append(line);
- }
- return sb.toString();
- } catch (Exception e) {
- throw new IllegalStateException(e);
- } finally {
- safeClose(br, reader);
- }
- }
-
- public static void safeClose(Object... objects) {
- boolean debugEnabled = logger.isDebugEnabled();
-
- if (objects == null || objects.length == 0) {
- logger.info("safeClose(...) was invoked with null or empty array: {}", objects);
- return;
- }
-
- for (Object obj : objects) {
- if (obj != null) {
- if (debugEnabled) {
- logger.debug("Trying to safely close {}", obj);
- }
-
- if (obj instanceof Flushable) {
- try {
- ((Flushable) obj).flush();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Flushing Flushable failed", e);
- }
- }
- }
-
- if (obj instanceof Closeable) {
- try {
- ((Closeable) obj).close();
- } catch (IOException e) {
- if (debugEnabled) {
- logger.debug("Closing Closeable failed", e);
- }
- }
- } else if (obj instanceof Connection) {
- try {
- ((Connection) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing Connection failed", e);
- }
- }
- } else if (obj instanceof Statement) {
- try {
- ((Statement) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing Statement failed", e);
- }
- }
- } else if (obj instanceof ResultSet) {
- try {
- ((ResultSet) obj).close();
- } catch (Exception e) {
- if (debugEnabled) {
- logger.debug("Closing ResultSet failed", e);
- }
- }
- } else {
- logger.info("obj was neither Closeable, Connection, Statement or ResultSet.");
-
- try {
- Method method = obj.getClass().getMethod("close", new Class[0]);
- if (method == null) {
- logger.info("obj did not have a close() method, ignoring");
- } else {
- method.setAccessible(true);
- method.invoke(obj);
- }
- } catch (InvocationTargetException e) {
- logger.warn("Invoking close() by reflection threw exception", e);
- } catch (Exception e) {
- logger.warn("Could not invoke close() by reflection", e);
- }
- }
- }
-
- }
- }
-
- public static BufferedWriter getBufferedWriter(File file, String encoding) throws IllegalStateException {
- Writer writer = getWriter(file, encoding);
- return new BufferedWriter(writer);
- }
-
- public static BufferedReader getBufferedReader(File file, String encoding) throws IllegalStateException {
- Reader reader = getReader(file, encoding);
- return new BufferedReader(reader);
- }
-
- public static BufferedReader getBufferedReader(InputStream inputStream, String encoding) throws IllegalStateException {
- Reader reader = getReader(inputStream, encoding);
- return new BufferedReader(reader);
- }
-
- public static Reader getReader(File file) throws IllegalStateException {
- return getReader(file, DEFAULT_ENCODING);
- }
-
- public static String readFileAsString(File file) throws IllegalStateException {
- return readFileAsString(file, DEFAULT_ENCODING);
- }
-
- public static BufferedWriter getBufferedWriter(File file) throws IllegalStateException {
- return getBufferedWriter(file, DEFAULT_ENCODING);
- }
-
- public static Writer getWriter(File file) throws IllegalStateException {
- return getWriter(file, DEFAULT_ENCODING);
- }
-
- public static void writeString(OutputStream outputStream, String string) throws IllegalStateException {
- writeString(outputStream, string, DEFAULT_ENCODING);
- }
-
- public static void writeString(OutputStream outputStream, String string, String encoding) throws IllegalStateException {
- final Writer writer = getWriter(outputStream, encoding);
- writeString(writer, string, encoding);
- }
-
- public static void writeString(Writer writer, String string) throws IllegalStateException {
- writeString(writer, string, DEFAULT_ENCODING);
- }
-
- public static void writeString(Writer writer, String string, String encoding) throws IllegalStateException {
- try {
- writer.write(string);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- } finally {
- safeClose(writer);
- }
- }
-
- public static void writeStringAsFile(File file, String string) throws IllegalStateException {
- writeStringAsFile(file, string, DEFAULT_ENCODING);
- }
-
- public static void writeStringAsFile(File file, String string, String encoding) throws IllegalStateException {
- final BufferedWriter bw = getBufferedWriter(file, encoding);
- writeString(bw, string, encoding);
- }
-
- public static BufferedReader getBufferedReader(File file) throws IllegalStateException {
- return getBufferedReader(file, DEFAULT_ENCODING);
- }
-
- public static void copy(Reader reader, Writer writer) throws IllegalStateException {
- final BufferedReader bufferedReader = getBufferedReader(reader);
- try {
- boolean firstLine = true;
- for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) {
- if (firstLine) {
- firstLine = false;
- } else {
- writer.write('\n');
- }
- writer.write(line);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static BufferedReader getBufferedReader(Reader reader) {
- if (reader instanceof BufferedReader) {
- return (BufferedReader) reader;
- }
- return new BufferedReader(reader);
- }
-
- public static void copy(InputStream fromStream, OutputStream toStream) throws IllegalStateException {
- try {
- byte[] buffer = new byte[1024 * 32];
- for (int read = fromStream.read(buffer); read != -1; read = fromStream.read(buffer)) {
- toStream.write(buffer, 0, read);
- }
- } catch (IOException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static void copy(File from, File to) throws IllegalStateException {
- assert from.exists();
-
- final InputStream fromStream = getInputStream(from);
- final OutputStream toStream = getOutputStream(to);
-
- try {
- copy(fromStream, toStream);
- } finally {
- safeClose(fromStream, toStream);
- }
- }
-
- public static OutputStream getOutputStream(File file) throws IllegalStateException {
- return getOutputStream(file, false);
- }
-
- public static OutputStream getOutputStream(File file, boolean append) {
- try {
- return new BufferedOutputStream(new FileOutputStream(file, append));
- } catch (FileNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static InputStream getInputStream(File file) throws IllegalStateException {
- try {
- return new BufferedInputStream(new FileInputStream(file));
- } catch (FileNotFoundException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public static byte[] readAsBytes(InputStream inputStream) {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- copy(inputStream, baos);
- } finally {
- safeClose(inputStream);
- }
- return baos.toByteArray();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java b/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
deleted file mode 100644
index f713e0c..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FileResource.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-/**
- * {@link File} based {@link Resource} implementation.
- */
-public class FileResource implements Resource, Serializable {
-
- private static final long serialVersionUID = 1L;
- private final File _file;
-
- public FileResource(String filename) {
- _file = new File(filename);
- }
-
- public FileResource(File file) {
- _file = file;
- }
-
- @Override
- public String toString() {
- return "FileResource[" + _file.getPath() + "]";
- }
-
- @Override
- public String getName() {
- return _file.getName();
- }
-
- @Override
- public boolean isReadOnly() {
- if (!isExists()) {
- return false;
- }
- boolean canWrite = _file.canWrite();
- return !canWrite;
- }
-
- @Override
- public void write(Action<OutputStream> writeCallback) throws ResourceException {
- final OutputStream out = FileHelper.getOutputStream(_file);
- try {
- writeCallback.run(out);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in write callback", e);
- } finally {
- FileHelper.safeClose(out);
- }
- }
-
- @Override
- public void append(Action<OutputStream> appendCallback) {
- final OutputStream out = FileHelper.getOutputStream(_file, true);
- try {
- appendCallback.run(out);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in append callback", e);
- } finally {
- FileHelper.safeClose(out);
- }
- }
-
- @Override
- public void read(Action<InputStream> readCallback) {
- final InputStream in = read();
- try {
- readCallback.run(in);
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- @Override
- public <E> E read(Func<InputStream, E> readCallback) {
- final InputStream in = read();
- try {
- final E result = readCallback.eval(in);
- return result;
- } catch (Exception e) {
- throw new ResourceException(this, "Error occurred in read callback", e);
- } finally {
- FileHelper.safeClose(in);
- }
- }
-
- public File getFile() {
- return _file;
- }
-
- @Override
- public boolean isExists() {
- return _file.exists();
- }
-
- @Override
- public long getSize() {
- return _file.length();
- }
-
- @Override
- public long getLastModified() {
- final long lastModified = _file.lastModified();
- if (lastModified == 0) {
- return -1;
- }
- return lastModified;
- }
-
- @Override
- public InputStream read() throws ResourceException {
- final InputStream in = FileHelper.getInputStream(_file);
- return in;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java b/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
deleted file mode 100644
index 3b954dc..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/FormatHelper.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Date;
-
-import org.eobjects.metamodel.query.QueryParameter;
-import org.eobjects.metamodel.schema.ColumnType;
-
-/**
- * Helper class for formatting
- */
-public final class FormatHelper {
-
- /**
- * Creates a uniform number format which is similar to that of eg. Java
- * doubles. The format will not include thousand separators and it will use
- * a dot as a decimal separator.
- *
- * @return
- */
- public static NumberFormat getUiNumberFormat() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols();
- symbols.setDecimalSeparator('.');
- DecimalFormat format = new DecimalFormat("###.##", symbols);
- format.setGroupingUsed(false);
- return format;
- }
-
- public static NumberFormat getSqlNumberFormat() {
- DecimalFormatSymbols symbols = new DecimalFormatSymbols();
- symbols.setDecimalSeparator('.');
- DecimalFormat format = new DecimalFormat("###.##", symbols);
- format.setGroupingUsed(false);
- format.setMaximumFractionDigits(100);
- return format;
- }
-
- public static String formatSqlBoolean(ColumnType columnType, boolean b) {
- if (columnType == ColumnType.BIT) {
- if (b) {
- return "1";
- } else {
- return "0";
- }
- } else {
- if (b) {
- return "TRUE";
- } else {
- return "FALSE";
- }
- }
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or
- * TIMESTAMP)
- *
- * @param columnType
- * the column type
- * @param date
- * the date value
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date) {
- return formatSqlTime(columnType, date, true);
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or
- * TIMESTAMP)
- *
- * @param columnType
- * the column type
- * @param date
- * the date value
- * @param typeCastDeclaration
- * whether or not to include a type cast declaration
- * @param beforeDateLiteral
- * before date literal
- * @param afterDateLiteral
- * after date literal
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date,
- boolean typeCastDeclaration, String beforeDateLiteral,
- String afterDateLiteral) {
- if (columnType == null) {
- throw new IllegalArgumentException("Column type cannot be null");
- }
- final DateFormat format;
- final String typePrefix;
- switch (columnType) {
- case DATE:
- format = DateUtils.createDateFormat("yyyy-MM-dd");
- typePrefix = "DATE";
- break;
- case TIME:
- format = DateUtils.createDateFormat("HH:mm:ss");
- typePrefix = "TIME";
- break;
- case TIMESTAMP:
- format = DateUtils.createDateFormat("yyyy-MM-dd HH:mm:ss");
- typePrefix = "TIMESTAMP";
- break;
- default:
- throw new IllegalArgumentException(
- "Cannot format time value of type: " + columnType);
- }
-
- if (typeCastDeclaration) {
- return typePrefix + " " + beforeDateLiteral + format.format(date) + afterDateLiteral;
- } else {
- return format.format(date);
- }
- }
-
- /**
- * Formats a date according to a specific column type (DATE, TIME or TIMESTAMP). For backward compatibility.
- * @param columnType
- * @param date
- * @param typeCastDeclaration
- * @return
- */
- public static String formatSqlTime(ColumnType columnType, Date date, boolean typeCastDeclaration) {
- return formatSqlTime(columnType, date, typeCastDeclaration, "\'", "\'");
- }
-
- /**
- * Parses a SQL string representation of a time based value
- *
- * @param type
- * @param value
- * @return
- */
- public static Date parseSqlTime(ColumnType columnType, String value) {
- final String[] formats;
- switch (columnType) {
- case DATE:
- formats = new String[] { "yyyy-MM-dd", };
- break;
- case TIME:
- formats = new String[] { "HH:mm:ss", "HH:mm" };
- break;
- case TIMESTAMP:
- formats = new String[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
- "yyyy-MM-dd" };
- break;
- default:
- throw new IllegalArgumentException(
- "Cannot parse time value of type: " + columnType);
- }
-
- for (String format : formats) {
- try {
- DateFormat dateFormat = DateUtils.createDateFormat(format);
- return dateFormat.parse(value);
- } catch (ParseException e) {
- // proceed to next format
- }
- }
-
- throw new IllegalArgumentException("String value '" + value
- + "' not parseable as a " + columnType);
- }
-
- public static String formatSqlValue(ColumnType columnType, Object value) {
- if (value == null) {
- return "NULL";
- }
- if (value instanceof QueryParameter) {
- return value.toString();
- }
- if (value.getClass().isArray()) {
- value = CollectionUtils.toList(value);
- }
- if (value instanceof Iterable) {
- StringBuilder sb = new StringBuilder();
- sb.append('(');
- for (Object item : (Iterable<?>) value) {
- if (sb.length() > 1) {
- sb.append(" , ");
- }
- sb.append(formatSqlValue(columnType, item));
- }
- sb.append(')');
- return sb.toString();
- } else if (isNumber(columnType, value)) {
- NumberFormat numberFormat = getSqlNumberFormat();
- Number n = NumberComparator.toNumber(value);
- if (n == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to number");
- }
- String numberString = numberFormat.format(n);
- return numberString;
- } else if (isBoolean(columnType, value)) {
- Boolean b = BooleanComparator.toBoolean(value);
- if (b == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to boolean");
- }
- String booleanString = formatSqlBoolean(columnType, b);
- return booleanString;
- } else if (isTimeBased(columnType, value)) {
- Date date = TimeComparator.toDate(value);
- if (date == null) {
- throw new IllegalStateException("Could not convert " + value
- + " to date");
- }
- String timeString = formatSqlTime(columnType, date);
- return timeString;
- } else if (isLiteral(columnType, value)) {
- return '\'' + value.toString() + '\'';
- } else {
- if (columnType == null) {
- throw new IllegalStateException("Value type not supported: "
- + value);
- }
- throw new IllegalStateException("Column type not supported: "
- + columnType);
- }
- }
-
- private static boolean isTimeBased(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return TimeComparator.isTimeBased(operand);
- }
- return columnType.isTimeBased();
- }
-
- private static boolean isBoolean(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof Boolean;
- }
- return columnType.isBoolean();
- }
-
- private static boolean isNumber(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof Number;
- }
- return columnType.isNumber();
- }
-
- private static boolean isLiteral(ColumnType columnType, Object operand) {
- if (columnType == null) {
- return operand instanceof String;
- }
- return columnType.isLiteral();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/Func.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/Func.java b/core/src/main/java/org/eobjects/metamodel/util/Func.java
deleted file mode 100644
index e17f3cf..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/Func.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * Represents an abstract function, which is an executable piece of
- * functionality that has an input and an output. A {@link Func} has a return
- * type, unlike an {@link Action}.
- *
- * @author Kasper Sørensen
- *
- * @param <I>
- * the input type
- * @param <O>
- * the output type
- */
-public interface Func<I, O> {
-
- /**
- * Evaluates an element and transforms it using this function.
- *
- * @param arg
- * the input given to the function
- * @return the output result of the function
- */
- public O eval(I arg);
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/HasName.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/HasName.java b/core/src/main/java/org/eobjects/metamodel/util/HasName.java
deleted file mode 100644
index 647848f..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/HasName.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-/**
- * Represents anything with a (String based) name.
- *
- * @author Kasper Sørensen
- */
-public interface HasName {
-
- public String getName();
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java b/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
deleted file mode 100644
index 3b22a32..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/HasNameMapper.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.io.Serializable;
-
-/**
- * {@link Func} useful for mapping {@link HasName} instances to names, using
- * {@link CollectionUtils#map(Object[], Func)} and
- * {@link CollectionUtils#map(Iterable, Func)}.
- *
- * @author Kasper Sørensen
- */
-public final class HasNameMapper implements Func<HasName, String>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public String eval(HasName arg) {
- return arg.getName();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-metamodel/blob/e2e2b37a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java b/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
deleted file mode 100644
index 4ed34a6..0000000
--- a/core/src/main/java/org/eobjects/metamodel/util/ImmutableDate.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.eobjects.metamodel.util;
-
-import java.text.DateFormat;
-import java.util.Date;
-
-/**
- * A Date implementation that is immutable and has a predictable
- * (locale-indifferent) toString() method.
- *
- * @author Kasper Sørensen
- *
- * @deprecated MetaModel is not a Date API, use Joda time or live with
- * java.util.Date.
- */
-@Deprecated
-public final class ImmutableDate extends Date {
-
- private static final long serialVersionUID = 1L;
-
- public ImmutableDate(long time) {
- super(time);
- }
-
- public ImmutableDate(Date date) {
- super(date.getTime());
- }
-
- /**
- * This mutator will throw an {@link UnsupportedOperationException}, since
- * the date is ummutable.
- *
- * @param time
- * new time to set
- */
- @Override
- public void setTime(long time) {
- throw new UnsupportedOperationException("setTime(...) is not allowed");
- }
-
- @Override
- public String toString() {
- DateFormat format = DateUtils.createDateFormat();
- return format.format(this);
- }
-}